I want to pass a security manager to be used in Junit tests by gradle. I tried jvmargs(not working) and now I'm using this:
apply plugin: 'java'
test {
systemProperties << ['java.security.policy': file("$projectDir/security.policy").absolutePath]
}
...
Java class
package hello;
import java.io.*;
import java.lang.*;
public class MyClass {
public void method() {
try {
File file = new File("/etc/passwd");
FileReader fr = new FileReader(file);
char [] a = new char[50];
fr.read(a);
for(char c : a)
System.out.print(c);
fr.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
My policy is:
grant {
permission java.io.FilePermission "/home/-", "read";
};
So I expect to get security exception when trying to read /etc/passwd
but I don't.