Skip to content

Commit b340457

Browse files
author
duke
committed
Backport a3693ccc617d06137a61050b34646e8a90ed3d7e
1 parent 4dc682a commit b340457

File tree

13 files changed

+141
-102
lines changed

13 files changed

+141
-102
lines changed

test/jdk/ProblemList.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,6 @@ com/sun/security/sasl/gsskerb/NoSecurityLayer.java 8039280 generic-
665665
javax/security/auth/kerberos/KerberosHashEqualsTest.java 8039280 generic-all
666666
javax/security/auth/kerberos/KerberosTixDateTest.java 8039280 generic-all
667667
sun/security/provider/PolicyFile/GrantAllPermToExtWhenNoPolicy.java 8039280 generic-all
668-
sun/security/provider/PolicyParser/ExtDirsChange.java 8039280 generic-all
669668
sun/security/provider/PolicyParser/PrincipalExpansionError.java 8039280 generic-all
670669

671670
sun/security/pkcs11/sslecc/ClientJSSEServerJSSE.java 8316183 linux-ppc64le

test/jdk/TEST.groups

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -574,9 +574,6 @@ jdk_security_manual_no_input = \
574574
com/sun/security/sasl/gsskerb/ConfSecurityLayer.java \
575575
com/sun/security/sasl/gsskerb/NoSecurityLayer.java \
576576
sun/security/provider/PolicyFile/GrantAllPermToExtWhenNoPolicy.java \
577-
sun/security/provider/PolicyParser/ExtDirs.java \
578-
sun/security/provider/PolicyParser/ExtDirsChange.java \
579-
sun/security/provider/PolicyParser/ExtDirsDefaultPolicy.java \
580577
sun/security/provider/PolicyParser/PrincipalExpansionError.java \
581578
sun/security/smartcardio/TestChannel.java \
582579
sun/security/smartcardio/TestConnect.java \

test/jdk/java/security/Policy/Root/Root.java

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -22,27 +22,46 @@
2222
*/
2323

2424
/*
25-
*
25+
* @test
2626
* @bug 4619757
2727
* @summary User Policy Setting is not recognized on Netscape 6
2828
* when invoked as root.
29-
* @run main/manual Root
29+
* @library /test/lib
30+
* @run testng/othervm Root
3031
*/
3132

32-
/*
33-
* Place Root.policy in the root home directory (/),
34-
* as /.java.policy and run as test as root user.
35-
*/
33+
import org.testng.Assert;
34+
import org.testng.annotations.AfterTest;
35+
import org.testng.annotations.BeforeTest;
36+
import org.testng.annotations.Test;
3637

38+
import java.io.IOException;
39+
import java.nio.file.Files;
40+
import java.nio.file.Path;
41+
import java.nio.file.Paths;
42+
import java.nio.file.StandardCopyOption;
3743
import java.security.*;
3844

3945
public class Root {
40-
public static void main(String[] args) {
46+
private static final String SRC = System.getProperty("test.src");
47+
private static final String ROOT = System.getProperty("user.home");
48+
private static final Path SOURCE = Paths.get(SRC, "Root.policy");
49+
private static final Path TARGET = Paths.get(ROOT, ".java.policy");
50+
51+
@BeforeTest
52+
public void setup() throws IOException {
53+
Files.copy(SOURCE, TARGET, StandardCopyOption.REPLACE_EXISTING);
54+
}
55+
56+
@AfterTest
57+
public void cleanUp() throws IOException {
58+
Files.delete(TARGET);
59+
}
60+
61+
@Test
62+
private void test() {
4163
Policy p = Policy.getPolicy();
42-
if (p.implies(Root.class.getProtectionDomain(), new AllPermission())) {
43-
System.out.println("Test succeeded");
44-
} else {
45-
throw new SecurityException("Test failed");
46-
}
64+
Assert.assertTrue(p.implies(Root.class.getProtectionDomain(),
65+
new AllPermission()));
4766
}
4867
}

test/jdk/javax/crypto/CryptoPermissions/InconsistentEntries.java

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,57 +23,74 @@
2323
* questions.
2424
*/
2525

26-
/**
26+
/*
2727
* @test
2828
* @bug 8286779
2929
* @summary Test limited/default_local.policy containing inconsistent entries
30-
* @run main/manual InconsistentEntries
30+
* @library /test/lib
31+
* @run testng/othervm InconsistentEntries
3132
*/
33+
34+
import org.testng.Assert;
35+
import org.testng.annotations.AfterTest;
36+
import org.testng.annotations.BeforeTest;
37+
import org.testng.annotations.Test;
38+
3239
import javax.crypto.*;
3340
import java.io.File;
41+
import java.io.IOException;
3442
import java.nio.file.Files;
3543
import java.nio.file.Path;
44+
import java.nio.file.Paths;
45+
import java.nio.file.StandardCopyOption;
3646
import java.security.Security;
3747

3848
public class InconsistentEntries {
3949

40-
public static void main(String[] args) throws Exception {
41-
System.out.println("***********************************************************");
42-
System.out.println("// This is a manual test to test a custom \"default_local.policy\" containing inconsistent entries");
43-
System.out.println("// under a new subfolder \"$JAVA_HOME/conf/security/policy\" directory.");
44-
System.out.println("// This test fails when the policy directory \"testlimited\" or the policy \"default_local.policy");
45-
System.out.println("// does not exist or is empty.");
46-
System.out.println("// - Create a new subfolder \"testlimited\" under \"$JAVA_HOME/conf/security/policy\"");
47-
System.out.println("// - Place the custom \"default_local.policy\" under \"testlimited\" directory");
48-
System.out.println("// - default_local.policy contains:");
49-
System.out.println("// grant {");
50-
System.out.println("// permission javax.crypto.CryptoAllPermission;");
51-
System.out.println("// permission javax.crypto.CryptoPermission \"DES\", 64;");
52-
System.out.println("// };");
53-
System.out.println("***********************************************************");
50+
private static final String JDK_HOME = System.getProperty("test.jdk");
51+
private static final String TEST_SRC = System.getProperty("test.src");
52+
private static final Path POLICY_DIR = Paths.get(JDK_HOME, "conf", "security",
53+
"policy", "testlimited");
54+
private static final Path POLICY_FILE = Paths.get(TEST_SRC, "default_local.policy");
55+
56+
Path targetFile = null;
57+
58+
@BeforeTest
59+
public void setUp() throws IOException {
60+
if (!POLICY_DIR.toFile().exists()) {
61+
Files.createDirectory(POLICY_DIR);
62+
}
5463

64+
targetFile = POLICY_DIR.resolve(POLICY_FILE.getFileName());
65+
Files.copy(POLICY_FILE, targetFile, StandardCopyOption.REPLACE_EXISTING);
66+
}
67+
68+
@AfterTest
69+
public void cleanUp() throws IOException {
70+
Files.delete(targetFile);
71+
}
72+
73+
@Test
74+
public void test() throws Exception {
5575
String JAVA_HOME = System.getProperty("java.home");
5676
String FS = System.getProperty("file.separator");
5777
Path testlimited = Path.of(JAVA_HOME + FS + "conf" + FS + "security" +
5878
FS + "policy" + FS + "testlimited");
5979
if (!Files.exists(testlimited)) {
60-
throw new RuntimeException("custom policy subdirectory: testlimited does not exist");
80+
throw new RuntimeException(
81+
"custom policy subdirectory: testlimited does not exist");
6182
}
6283

6384
File testpolicy = new File(JAVA_HOME + FS + "conf" + FS + "security" +
6485
FS + "policy" + FS + "testlimited" + FS + "default_local.policy");
6586
if (testpolicy.length() == 0) {
66-
throw new RuntimeException("policy: default_local.policy does not exist or is empty");
87+
throw new RuntimeException(
88+
"policy: default_local.policy does not exist or is empty");
6789
}
6890

6991
Security.setProperty("crypto.policy", "testlimited");
7092

71-
try {
72-
int maxKeyLen = Cipher.getMaxAllowedKeyLength("AES");
73-
throw new RuntimeException("Should fail due to inconsistent entries in policy file");
74-
} catch (ExceptionInInitializerError e) {
75-
e.printStackTrace();
76-
System.out.println("Test completed successfully");
77-
}
93+
Assert.assertThrows(ExceptionInInitializerError.class,
94+
() -> Cipher.getMaxAllowedKeyLength("AES"));
7895
}
7996
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
grant {
2+
permission javax.crypto.CryptoAllPermission;
3+
permission javax.crypto.CryptoPermission "DES", 64;
4+
}

test/jdk/sun/security/provider/PolicyParser/ExtDirs.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -26,16 +26,15 @@
2626
* @bug 4215035
2727
* @summary standard extensions path is hard-coded in default
2828
* system policy file
29-
* @run main/manual ExtDirs
29+
* @run main ExtDirs
3030
*/
3131

3232
/*
33-
* Run this test manually with:
34-
* java -Djava.security.manager \
35-
* -Djava.ext.dirs=./ExtDirsA:./ExtDirsB \
36-
* -Djava.security.policy==./ExtDirs.policy \
37-
* -Djava.security.debug=parser \
38-
* ExtDirs
33+
* @test
34+
* @bug 4215035
35+
* @summary standard extensions path is hard-coded in default
36+
* system policy file
37+
* @run main/othervm/policy=ExtDirs.policy ExtDirs
3938
*/
4039

4140
public class ExtDirs {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
grant codebase "${java.ext.dirs}" {
1+
grant codebase "file:${test.classes}" {
22
permission java.util.PropertyPermission "user.name", "read";
33
permission java.util.PropertyPermission "user.home", "read";
44
};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
grant codebase "file:${{java.ext.dirs}}/*" {
1+
grant codebase "file:${test.classes}" {
22
permission java.util.PropertyPermission "user.name", "read";
33
permission java.util.PropertyPermission "user.home", "read";
44
};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
grant codebase "file:${{java.ext.dirs}}" {
1+
grant codebase "file:${test.classes}/*" {
22
permission java.util.PropertyPermission "user.name", "read";
33
permission java.util.PropertyPermission "user.home", "read";
44
};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
grant codebase "${{java.ext.dirs}}" {
1+
grant codebase "file:${test.classes}/-" {
22
permission java.util.PropertyPermission "user.name", "read";
33
permission java.util.PropertyPermission "user.home", "read";
44
};

0 commit comments

Comments
 (0)