Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
alisevych opened this issue Nov 7, 2022 · 2 comments
Assignees
Labels
ctg-bug Issue is a bug priority-top-focus Top priority chosen by dev team

Comments

@alisevych
Copy link
Member

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

@alisevych alisevych added the ctg-bug Issue is a bug label Nov 7, 2022
@korifey korifey moved this to Todo in UTBot Java Nov 7, 2022
@alisevych alisevych assigned SBOne-Kenobi and unassigned Markoutte Nov 7, 2022
@alisevych alisevych added this to the 2022.12 Release milestone Nov 8, 2022
@alisevych
Copy link
Member Author

@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?

@alisevych alisevych added the priority-top-focus Top priority chosen by dev team label Nov 30, 2022
@denis-fokin denis-fokin removed this from the 2022.12 Release milestone Dec 21, 2022
@alisevych alisevych modified the milestone: 2023.03 Release Feb 27, 2023
@alisevych
Copy link
Member Author

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
Labels
ctg-bug Issue is a bug priority-top-focus Top priority chosen by dev team
Projects
Status: Todo
Development

No branches or pull requests

5 participants