Skip to content

Disable tests with unpermitted operations in Threads #895

Open
@alisevych

Description

@alisevych

Description

Tests with unpermitted operation is Threads should be disabled, but they are up.

To Reproduce

  1. IntelliJ IDEA 2022.1.4 with latest UTBot plugin installed
  2. Create/open a project with JDK 8/11
  3. Add the following class and generate tests for it with default settings:
public class SecurityCheck {
    public int read() throws Throwable {
        Thread t = new Thread("fileRead") {
            public void run()  {
                try {
                    new File("a.txt").createNewFile();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        };
        t.start();
        Thread.sleep(500);
        return 10;
    }
}
  1. Open the generated test

Expected behavior

Generated test should be disabled due to sandbox.

Actual behavior

The following method is not executed - AccessControlException is thrown (was seen in Concrete executor logs when they were informative) - that's Ok.
But the generated tests are not disabled due to Sandbox. If we run the test - file will be created.

Visual proofs (screenshots, logs, images)

public class SecurityCheckTest {
    @Test
    @DisplayName("read: arg_0 = SecurityCheck() -> return 10")
    public void testReadReturns10() throws Throwable {
        SecurityCheck securityCheck = new SecurityCheck();

        int actual = securityCheck.read();

        assertEquals(10, actual);
    }
}

Environment

Windows 10 Pro
IntelliJ IDEA 2022.1.4
JDK 8

Originally posted by @alisevych in #790 (comment)

Metadata

Metadata

Assignees

Labels

comp-sandboxingIssue is related to sandboxing unpermitted operations by Java Security Managerctg-bugIssue is a bug

Type

No type

Projects

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions