Skip to content

Socket.connect and Files.readAllBytes produce errors in Concrete execution #1314

Description

@alisevych

Description

Socket.connect and Files.readAllBytes produce errors in Concrete execution

To Reproduce

  1. Install Build from the unit-test-bot/rc112022 branch into IDEA 2022.2.3
  2. Open UTBotJava project
  3. Check File -> Settings are default: 95% Symbolic execution
  4. Generate tests for the following class:
public class SecurityCheck {

    public int read(File path) throws IOException {
        byte[] bytes = Files.readAllBytes(path.toPath());
        return bytes.length;
    }

    public int connect(Socket socket) throws IOException {
        socket.connect(new InetSocketAddress("0.0.0.0", 22));
        return 0;
    }
}

Expected behavior

Tests are supposed to be generated without error reports.

Actual behavior

An error test is generated with information about errors in the concrete executor.

Visual proofs (screenshots, logs, images)

public final class SecurityCheckTest {
    ///region Test suites for executable org.utbot.examples.securitycheck.SecurityCheck.connect

    ///region

    @Test
    @Disabled(value = "Disabled due to sandbox")
    public void testConnect1() throws IOException {
        SecurityCheck securityCheck = new SecurityCheck();
        Socket socket = new Socket("jkmqh", 568849899, true);

        /* This test fails because method [org.utbot.examples.securitycheck.SecurityCheck.connect] produces [java.security.AccessControlException: access denied ("java.net.SocketPermission" "jkmqh" "resolve")] */
    }

    @Test
    @Disabled(value = "Disabled due to sandbox")
    public void testConnect2() throws IOException {
        SecurityCheck securityCheck = new SecurityCheck();
        Socket socket = new Socket("hlcoj", 1525745488);

        /* This test fails because method [org.utbot.examples.securitycheck.SecurityCheck.connect] produces [java.security.AccessControlException: access denied ("java.net.SocketPermission" "hlcoj" "resolve")] */
    }

    @Test
    @Disabled(value = "Disabled due to sandbox")
    public void testConnect3() throws IOException {
        SecurityCheck securityCheck = new SecurityCheck();
        Socket socket = new Socket("", 22, true);

        /* This test fails because method [org.utbot.examples.securitycheck.SecurityCheck.connect] produces [java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:22" "connect,resolve")] */
    }

    @Test
    @Disabled(value = "Disabled due to sandbox")
    public void testConnect4() throws IOException {
        SecurityCheck securityCheck = new SecurityCheck();
        Socket socket = new Socket("jkmqh", 22, false);

        /* This test fails because method [org.utbot.examples.securitycheck.SecurityCheck.connect] produces [java.security.AccessControlException: access denied ("java.net.SocketPermission" "jkmqh" "resolve")] */
    }

    @Test
    @Disabled(value = "Disabled due to sandbox")
    public void testConnect5() throws IOException {
        SecurityCheck securityCheck = new SecurityCheck();
        Socket socket = new Socket("", 0, true);

        /* This test fails because method [org.utbot.examples.securitycheck.SecurityCheck.connect] produces [java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:0" "connect,resolve")] */
    }

    @Test
    @Disabled(value = "Disabled due to sandbox")
    public void testConnect6() throws IOException {
        SecurityCheck securityCheck = new SecurityCheck();
        Socket socket = new Socket("0.0.0.0", 22);

        /* This test fails because method [org.utbot.examples.securitycheck.SecurityCheck.connect] produces [java.security.AccessControlException: access denied ("java.net.SocketPermission" "0.0.0.0:22" "connect,resolve")] */
    }

    @Test
    @Disabled(value = "Disabled due to sandbox")
    public void testConnect7() throws IOException {
        SecurityCheck securityCheck = new SecurityCheck();
        Socket socket = new Socket("noimn", 427785292);

        /* This test fails because method [org.utbot.examples.securitycheck.SecurityCheck.connect] produces [java.security.AccessControlException: access denied ("java.net.SocketPermission" "noimn" "resolve")] */
    }

    @Test
    @Disabled(value = "Disabled due to sandbox")
    public void testConnect8() throws IOException {
        SecurityCheck securityCheck = new SecurityCheck();
        Socket socket = new Socket("", 0);

        /* This test fails because method [org.utbot.examples.securitycheck.SecurityCheck.connect] produces [java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:0" "connect,resolve")] */
    }
    ///endregion

    ///region Errors report for connect

    public void testConnect_errors() {
        // Couldn't generate some tests. List of errors:
        // 
        // 70 occurrences of:
        // Default concrete execution failed

    }
    ///endregion

    ///endregion

    ///region Test suites for executable org.utbot.examples.securitycheck.SecurityCheck.read

    ///region

    @Test
    @Disabled(value = "Disabled due to sandbox")
    public void testRead1() {
        SecurityCheck securityCheck = new SecurityCheck();
        File path = new File("jkmqh", "uhauh");
        
        /* This test fails because method [org.utbot.examples.securitycheck.SecurityCheck.read] produces [java.security.AccessControlException: access denied ("java.io.FilePermission" "jkmqh\\uhauh" "read")]
            java.base/java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
            java.base/java.security.AccessController.checkPermission(AccessController.java:897)
            java.base/java.lang.SecurityManager.checkPermission(SecurityManager.java:322)
            java.base/java.lang.SecurityManager.checkRead(SecurityManager.java:661)
            java.base/sun.nio.fs.WindowsChannelFactory.open(WindowsChannelFactory.java:299)
            java.base/sun.nio.fs.WindowsChannelFactory.newFileChannel(WindowsChannelFactory.java:168)
            java.base/sun.nio.fs.WindowsFileSystemProvider.newByteChannel(WindowsFileSystemProvider.java:230)
            java.base/java.nio.file.Files.newByteChannel(Files.java:371)
            java.base/java.nio.file.Files.newByteChannel(Files.java:422)
            java.base/java.nio.file.Files.readAllBytes(Files.java:3206)
            org.utbot.examples.securitycheck.SecurityCheck.read(SecurityCheck.java:19) */
    }

    @Test
    public void testRead2() throws IOException {
        SecurityCheck securityCheck = new SecurityCheck();
        
        /* This test fails because method [org.utbot.examples.securitycheck.SecurityCheck.read] produces [java.lang.NullPointerException]
            org.utbot.examples.securitycheck.SecurityCheck.read(SecurityCheck.java:19) */
        securityCheck.read(null);
    }
    ///endregion

    ///region Errors report for read

    public void testRead_errors() {
        // Couldn't generate some tests. List of errors:
        // 
        // 6 occurrences of:
        // Default concrete execution failed

    }
    ///endregion

    ///endregion
}

Environment

Windows 10 Pro
IntelliJ IDEA 2022.2.3 (JBR 17)
Gradle
JDK 11

Activity

  1. moved this to Todo in UTBot Javaon Nov 7, 2022
  2. added this to the 2022.12 Release milestone on Nov 8, 2022
  3. alisevych commented on Nov 16, 2022

    @alisevych
    MemberAuthor

    @SBOne-Kenobi
    Also there is an unused import in the generated test:
    import java.net.UnknownHostException;
    Could you please check if it requires a separate issue?

  4. removed this from the 2022.12 Release milestone on Dec 21, 2022
  5. alisevych commented on Mar 21, 2023

    @alisevych
    MemberAuthor

    Reproducing on latest unit-test-bot/rc3102023 branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions