-
Notifications
You must be signed in to change notification settings - Fork 7
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
How to allow package access, without breaking the classes #96
Comments
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 |
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. |
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 |
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? |
Yes, very likely, especially when the thread is started outside the test and you are providing input in the test. |
Is this a limit of AJTS or did I something wrong? I used Unrelated: Could you briefly explain what |
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). |
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. |
If the package of
|
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. |
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? |
Yes, for example inserting Class.forName("java.util.List").isInterface(); in my given example will yield:
|
Is the |
All annotations are only relevant in a test context. So only the test class and its members can use the annotations. |
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). |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Describe the bug
I would like to allow only
java.lang
andjava.io
. But when students try to read console input (like thy should) the test freezes and runs into the timeout.I used:
This may be caused by
java.io
accessing a restricted package.Expected behavior
The access of a blacklisted package through a whitelisted package should be allowed.
Additional context
Tested locally.
The text was updated successfully, but these errors were encountered: