Closed
Description
Description
Sandboxed test is not compiling because commented stack trace contains "illegal unicode escape".
To Reproduce
- Run a project in IntelliJ Idea 2022.1.3 - 2022.2.2
- Install RC plugin build
- Set Fuzzing to 100% (in File -> Settings -> Tools -> UnitTestBot)
- Add the following class (originally posted in Add SecurityManager support to block suspicious code #622 #625 ):
public class SecurityCheck {
public int normalTest(int value) {
if (value < 0) {
return -value;
}
return value;
}
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;
}
public String property(String key) {
return System.getProperty(key);
}
public String systemExit() {
System.exit(0);
return "bad";
}
}
- Generate tests with UnitTestBot
- Open generated tests
Expected behavior
Project can be successfully build after test generation.
Actual behavior
SecurityCheckTest is not compiled.
The following error is displayed:
C:\Users\<user_name>\UTBotJava\utbot-sample\src\test\java\org\utbot\examples\securitycheck\SecurityCheckTest.java:2823: error: illegal unicode escape
/* This test fails because method [org.utbot.examples.securitycheck.SecurityCheck.read] produces [java.security.AccessControlException: access denied ("java.io.FilePermission" "jkmqh\uhauh" "read")]
Visual proofs (screenshots, logs, images)
There is the following test generated by Fuzzer
///region FUZZER: EXPLICITLY_THROWN_UNCHECKED_EXCEPTIONS for method read(java.io.File)
@Test
@DisplayName("read: path = File(String, String)")
@Disabled(value = "Disabled due to sandbox")
public void testRead() {
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) */
}
///endregion
Environment
Windows 10 Pro
IntelliJ IDEA 2022.2.2
Additional context
Originally posted by @alisevych in #1125 (comment)
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Done