How to allow package access, without breaking the classes #114
-
Describe the bug I used: @BlacklistPackage("**")
@WhitelistPackage("java.lang**")
@WhitelistPackage("java.io**") This may be caused by Expected behavior Additional context |
Beta Was this translation helpful? Give feedback.
Replies: 15 comments 5 replies
-
Trying @Public
@StrictTimeout(1)
@BlacklistPackage("**")
@WhitelistPackage({ "java.lang", "java.nio**", "java.io**" })
class BasicExampleTest {
@Test
void testExample(IOTester io) {
io.in().addLinesToInput("Christian");
BasicExample.main(new String[0]);
String actualOutput = io.out().getOutputAsString();
if (!"""
Enter your name:
Hello Christian!""".equals(actualOutput))
fail("'Wrong output!");
}
} and import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class BasicExample {
public static void main(String[] args) {
try (var bufferedReader = new BufferedReader(new InputStreamReader(System.in))) {
System.out.println("Enter your name:");
var name = bufferedReader.readLine();
System.out.println("Hello " + name + "!");
} catch (IOException e) {
e.printStackTrace();
}
}
} worked for me. But you are right that |
Beta Was this translation helpful? Give feedback.
-
Thanks! I'll try that. Although, I would prefer a solution where only the "first" accessed class is restricted and if the call goes over a whitelisted class the call is permitted. |
Beta Was this translation helpful? Give feedback.
-
I can have a look at that, but I doubt I can fix that easily (the solution that comes to my mind would not protect against reflective access, as Also keep in mind that |
Beta Was this translation helpful? Give feedback.
-
I am still running into timeout issues when I add the annotations. The debug output does not really help:
Maybe it's because the student submission runs in its own thread and is called by reflection? |
Beta Was this translation helpful? Give feedback.
-
Yes, very likely, especially when the thread is started outside the test and you are providing input in the test. |
Beta Was this translation helpful? Give feedback.
-
Is this a limit of AJTS or did I something wrong? I used Unrelated: Could you briefly explain what |
Beta Was this translation helpful? Give feedback.
-
If you want the students to wait for input and then react and always provide input after the student code requests the input, this will not work with Ares as it is now. The input/output testing in Ares was created such that all read operations on the input stream either directly succeed or fail (because we wanted to avoid any timeouts). |
Beta Was this translation helpful? Give feedback.
-
I do not use AJTS Input/Output Testing. I use my own thing. Without the Blacklist/Whilelist that does work like a charm. But with, the timeouts occur. |
Beta Was this translation helpful? Give feedback.
-
If the package of
|
Beta Was this translation helpful? Give feedback.
-
I assume "Without the Blacklist/Whilelist" means with Ares but just without those annotations. Then it depends on how this custom solution works. My guess is that the custom solution somehow catches the package access security exception and then uses a different strategy after that or just works differently. Or hangs in some other way. |
Beta Was this translation helpful? Give feedback.
-
Thanks for your explanation!
Yes! Using Ares but without any additional annotations. Just for my understanding: When a student accesses a blacklisted package then a SecurityException is thrown? |
Beta Was this translation helpful? Give feedback.
-
Yes, for example inserting Class.forName("java.util.List").isInterface(); in my given example will yield:
|
Beta Was this translation helpful? Give feedback.
-
Is the |
Beta Was this translation helpful? Give feedback.
-
All annotations are only relevant in a test context. So only the test class and its members can use the annotations. |
Beta Was this translation helpful? Give feedback.
-
I will make a discussion out of this because this is/became one. Tell me if there are still problems related to this (I guess there is already a related issue #105 for that). Please select which of my answers helped (if they did, but there were not further messages here, so I guess one did) to resolve this discussion. |
Beta Was this translation helpful? Give feedback.
I will make a discussion out of this because this is/became one. Tell me if there are still problems related to this (I guess there is already a related issue #105 for that). Please select which of my answers helped (if they did, but there were not further messages here, so I guess one did) to resolve this discussion.