JDK-8180895 : java/security/AccessController/DoPrivAccompliceTest.java has to be improved
  • Type: Bug
  • Component: security-libs
  • Sub-Component: java.security
  • Affected Version: 9,10
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2017-05-24
  • Updated: 2017-06-02
  • Resolved: 2017-05-27
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 10
10 b10Fixed
Related Reports
Blocks :  
Description
there is a couple issue w/ DoPrivAccompliceTest.java test:
 - it's semi-automatic test, although it checks whether a spawn jvm exits gracefully, the test won't fail if it does not
 - "negative" case is not covered. the test does not check that DoPrivTest.jar does not have rights to read 'user.home' property
- the test uses its own testlibrary to create a jar, start a jvm, while there is a common testlibrary for the same use cases.
- the test does not follow code style, it's hard to read it, especially createPolicyFile method.
- the test creates files in class files directory which can affect other tests results   
Comments
RFR: http://mail.openjdk.java.net/pipermail/core-libs-dev/2017-May/047844.html
24-05-2017

webrev: http://cr.openjdk.java.net/~iignatyev//8180895/webrev.00/index.html
24-05-2017

suggested fix: diff -r d6721471ddb8 test/java/security/AccessController/DoPrivAccompliceTest.java --- a/test/java/security/AccessController/DoPrivAccompliceTest.java Tue May 23 18:24:48 2017 -0700 +++ b/test/java/security/AccessController/DoPrivAccompliceTest.java Tue May 23 19:06:14 2017 -0700 @@ -29,6 +29,7 @@ import java.net.URI; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; /* @@ -55,15 +56,16 @@ String codebase = codebaseURL.toString(); String quotes = "\""; StringBuilder policyFile = new StringBuilder(); - policyFile.append("grant codeBase ").append(quotes). - append(codebase).append(quotes).append("{\n"). - append("permission java.util.PropertyPermission "). - append(quotes).append("user.name").append(quotes). - append(",").append(quotes).append("read").append(quotes). - append(";\n};"); + policyFile.append("grant codeBase ") + .append(quotes).append(codebase).append(quotes) + .append("{\n") + .append("permission java.util.PropertyPermission ") + .append(quotes).append("user.name").append(quotes) + .append(",") + .append(quotes).append("read").append(quotes) + .append(";\n};"); try (FileWriter writer = new FileWriter(new File(PWD, "java.policy"))) { writer.write(policyFile.toString()); - writer.close(); } catch (IOException e) { System.err.println("Error while creating policy file"); throw e; @@ -71,16 +73,16 @@ } public static void main(String[] args) throws Exception { - final File class1 = new File(PWD, ACTION_SOURCE + ".class"); - final File class2 = new File(PWD, TEST_SOURCE + ".class"); - final File jarFile1 = new File(PWD, ACTION_SOURCE + ".jar"); - final File jarFile2 = new File(PWD, TEST_SOURCE + ".jar"); + File class1 = new File(PWD, ACTION_SOURCE + ".class"); + File class2 = new File(PWD, TEST_SOURCE + ".class"); + File jarFile1 = new File(PWD, ACTION_SOURCE + ".jar"); + File jarFile2 = new File(PWD, TEST_SOURCE + ".jar"); System.out.println("Compilation successfull"); - JavaToolUtils.createJar(jarFile1, Arrays.asList(new File[]{class1})); + JavaToolUtils.createJar(jarFile1, Collections.singletonList(class1)); System.out.println("Created jar file " + jarFile1); - JavaToolUtils.createJar(jarFile2, Arrays.asList(new File[]{class2})); + JavaToolUtils.createJar(jarFile2, Collections.singletonList(class2)); System.out.println("Created jar file " + jarFile2); - createPolicyFile(jarFile1.toURI()); + List<String> commands = new ArrayList<>(); final String pathSepartor = System.getProperty("path.separator"); @@ -90,9 +92,21 @@ commands.add(PWD + "/" + TEST_SOURCE + ".jar" + pathSepartor + PWD + "/" + ACTION_SOURCE + ".jar"); commands.add(TEST_SOURCE); + + createPolicyFile(jarFile1.toURI()); + System.out.println("Created policy for " + jarFile1); + int exitCode = JavaToolUtils.runJava(commands); + if (exitCode != 0) { + throw new AssertionError(commands + " exit with " + exitCode); + } + + createPolicyFile(jarFile2.toURI()); + System.out.println("Created policy for " + jarFile2); if (JavaToolUtils.runJava(commands) == 0) { - System.out.println("Test PASSES"); + throw new AssertionError(commands + " exit with 0"); } + System.out.println("Test PASSES"); + } }
24-05-2017