Description
Unpermitted operations can be called implicitly. Need to sandbox them too.
- in constructors of used classes
- in static blocks
- in private methods of other classes
- in separate threads
- ? probably, there are other cases to be added ?
To Reproduce
Steps to reproduce the behavior:
- Open IntelliJ IDEA with installed UTBot plugin (with Security Manager turned on)
- Open/create a project with JDK 8/11
- Add the following class:
importjava.io.File;
importjava.io.IOException;
classA {
A () throwsIOException {
Filea = newFile("a.txt");
a.createNewFile();
}
}
publicclassSecurityCheck {
publicintread(Aa) {
return10;
}
}- Generate tests for the SecurityCheck.read method - with Mocking on
Expected behavior
Generated test is supposed to be disabled with sandbox-related comment.
No file must be created by user's code during test generation.
Actual behavior
Successful test is generated.
File "a.txt" is created during test generation.
Visual proofs (screenshots, logs, images)
@Test@DisplayName("read: a = A() -> return 10")
publicvoidtestReadReturns10() throwsIOException {
SecurityChecksecurityCheck = newSecurityCheck();
Aa = newA();
intactual = securityCheck.read(a);
assertEquals(10, actual);
}
Environment
IntelliJ IDEA 2022.1 - 2022.1.4
JDK 8/11
Additional context
Static blocks are being executed without sandbox either:
importjava.io.File;
classA {
static {
newFile("a.txt").renameTo(newFile("b.txt"));
}
}
publicclassAnotherCheck {
publicintread(Aa) {
return10;
}
}
Description
Unpermitted operations can be called implicitly. Need to sandbox them too.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Generated test is supposed to be disabled with sandbox-related comment.
No file must be created by user's code during test generation.
Actual behavior
Successful test is generated.
File "a.txt" is created during test generation.
Visual proofs (screenshots, logs, images)
Environment
IntelliJ IDEA 2022.1 - 2022.1.4
JDK 8/11
Additional context
Static blocks are being executed without sandbox either: