8295087: Manual Test to Automated Test Conversion
Reviewed-by: ssahoo, rhalade
This commit is contained in:
parent
50120396b6
commit
a3693ccc61
@ -612,7 +612,6 @@ com/sun/security/sasl/gsskerb/AuthOnly.java 8039280 generic-
|
||||
com/sun/security/sasl/gsskerb/ConfSecurityLayer.java 8039280 generic-all
|
||||
com/sun/security/sasl/gsskerb/NoSecurityLayer.java 8039280 generic-all
|
||||
sun/security/provider/PolicyFile/GrantAllPermToExtWhenNoPolicy.java 8039280 generic-all
|
||||
sun/security/provider/PolicyParser/ExtDirsChange.java 8039280 generic-all
|
||||
sun/security/provider/PolicyParser/PrincipalExpansionError.java 8039280 generic-all
|
||||
|
||||
sun/security/tools/keytool/NssTest.java 8295343 linux-all
|
||||
|
@ -623,9 +623,6 @@ jdk_core_manual_no_input_security = \
|
||||
com/sun/security/sasl/gsskerb/ConfSecurityLayer.java \
|
||||
com/sun/security/sasl/gsskerb/NoSecurityLayer.java \
|
||||
sun/security/provider/PolicyFile/GrantAllPermToExtWhenNoPolicy.java \
|
||||
sun/security/provider/PolicyParser/ExtDirs.java \
|
||||
sun/security/provider/PolicyParser/ExtDirsChange.java \
|
||||
sun/security/provider/PolicyParser/ExtDirsDefaultPolicy.java \
|
||||
sun/security/provider/PolicyParser/PrincipalExpansionError.java \
|
||||
sun/security/smartcardio/TestChannel.java \
|
||||
sun/security/smartcardio/TestConnect.java \
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -22,27 +22,46 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* @test
|
||||
* @bug 4619757
|
||||
* @summary User Policy Setting is not recognized on Netscape 6
|
||||
* when invoked as root.
|
||||
* @run main/manual Root
|
||||
* @library /test/lib
|
||||
* @run testng/othervm Root
|
||||
*/
|
||||
|
||||
/*
|
||||
* Place Root.policy in the root home directory (/),
|
||||
* as /.java.policy and run as test as root user.
|
||||
*/
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.AfterTest;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.security.*;
|
||||
|
||||
public class Root {
|
||||
public static void main(String[] args) {
|
||||
private static final String SRC = System.getProperty("test.src");
|
||||
private static final String ROOT = System.getProperty("user.home");
|
||||
private static final Path SOURCE = Paths.get(SRC, "Root.policy");
|
||||
private static final Path TARGET = Paths.get(ROOT, ".java.policy");
|
||||
|
||||
@BeforeTest
|
||||
public void setup() throws IOException {
|
||||
Files.copy(SOURCE, TARGET, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
|
||||
@AfterTest
|
||||
public void cleanUp() throws IOException {
|
||||
Files.delete(TARGET);
|
||||
}
|
||||
|
||||
@Test
|
||||
private void test() {
|
||||
Policy p = Policy.getPolicy();
|
||||
if (p.implies(Root.class.getProtectionDomain(), new AllPermission())) {
|
||||
System.out.println("Test succeeded");
|
||||
} else {
|
||||
throw new SecurityException("Test failed");
|
||||
}
|
||||
Assert.assertTrue(p.implies(Root.class.getProtectionDomain(),
|
||||
new AllPermission()));
|
||||
}
|
||||
}
|
||||
|
@ -23,57 +23,74 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
/*
|
||||
* @test
|
||||
* @bug 8286779
|
||||
* @summary Test limited/default_local.policy containing inconsistent entries
|
||||
* @run main/manual InconsistentEntries
|
||||
* @library /test/lib
|
||||
* @run testng/othervm InconsistentEntries
|
||||
*/
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.AfterTest;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.crypto.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.security.Security;
|
||||
|
||||
public class InconsistentEntries {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
System.out.println("***********************************************************");
|
||||
System.out.println("// This is a manual test to test a custom \"default_local.policy\" containing inconsistent entries");
|
||||
System.out.println("// under a new subfolder \"$JAVA_HOME/conf/security/policy\" directory.");
|
||||
System.out.println("// This test fails when the policy directory \"testlimited\" or the policy \"default_local.policy");
|
||||
System.out.println("// does not exist or is empty.");
|
||||
System.out.println("// - Create a new subfolder \"testlimited\" under \"$JAVA_HOME/conf/security/policy\"");
|
||||
System.out.println("// - Place the custom \"default_local.policy\" under \"testlimited\" directory");
|
||||
System.out.println("// - default_local.policy contains:");
|
||||
System.out.println("// grant {");
|
||||
System.out.println("// permission javax.crypto.CryptoAllPermission;");
|
||||
System.out.println("// permission javax.crypto.CryptoPermission \"DES\", 64;");
|
||||
System.out.println("// };");
|
||||
System.out.println("***********************************************************");
|
||||
private static final String JDK_HOME = System.getProperty("test.jdk");
|
||||
private static final String TEST_SRC = System.getProperty("test.src");
|
||||
private static final Path POLICY_DIR = Paths.get(JDK_HOME, "conf", "security",
|
||||
"policy", "testlimited");
|
||||
private static final Path POLICY_FILE = Paths.get(TEST_SRC, "default_local.policy");
|
||||
|
||||
Path targetFile = null;
|
||||
|
||||
@BeforeTest
|
||||
public void setUp() throws IOException {
|
||||
if (!POLICY_DIR.toFile().exists()) {
|
||||
Files.createDirectory(POLICY_DIR);
|
||||
}
|
||||
|
||||
targetFile = POLICY_DIR.resolve(POLICY_FILE.getFileName());
|
||||
Files.copy(POLICY_FILE, targetFile, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
|
||||
@AfterTest
|
||||
public void cleanUp() throws IOException {
|
||||
Files.delete(targetFile);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
String JAVA_HOME = System.getProperty("java.home");
|
||||
String FS = System.getProperty("file.separator");
|
||||
Path testlimited = Path.of(JAVA_HOME + FS + "conf" + FS + "security" +
|
||||
FS + "policy" + FS + "testlimited");
|
||||
if (!Files.exists(testlimited)) {
|
||||
throw new RuntimeException("custom policy subdirectory: testlimited does not exist");
|
||||
throw new RuntimeException(
|
||||
"custom policy subdirectory: testlimited does not exist");
|
||||
}
|
||||
|
||||
File testpolicy = new File(JAVA_HOME + FS + "conf" + FS + "security" +
|
||||
FS + "policy" + FS + "testlimited" + FS + "default_local.policy");
|
||||
if (testpolicy.length() == 0) {
|
||||
throw new RuntimeException("policy: default_local.policy does not exist or is empty");
|
||||
throw new RuntimeException(
|
||||
"policy: default_local.policy does not exist or is empty");
|
||||
}
|
||||
|
||||
Security.setProperty("crypto.policy", "testlimited");
|
||||
|
||||
try {
|
||||
int maxKeyLen = Cipher.getMaxAllowedKeyLength("AES");
|
||||
throw new RuntimeException("Should fail due to inconsistent entries in policy file");
|
||||
} catch (ExceptionInInitializerError e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("Test completed successfully");
|
||||
}
|
||||
Assert.assertThrows(ExceptionInInitializerError.class,
|
||||
() -> Cipher.getMaxAllowedKeyLength("AES"));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,4 @@
|
||||
grant {
|
||||
permission javax.crypto.CryptoAllPermission;
|
||||
permission javax.crypto.CryptoPermission "DES", 64;
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -26,16 +26,15 @@
|
||||
* @bug 4215035
|
||||
* @summary standard extensions path is hard-coded in default
|
||||
* system policy file
|
||||
* @run main/manual ExtDirs
|
||||
* @run main ExtDirs
|
||||
*/
|
||||
|
||||
/*
|
||||
* Run this test manually with:
|
||||
* java -Djava.security.manager \
|
||||
* -Djava.ext.dirs=./ExtDirsA:./ExtDirsB \
|
||||
* -Djava.security.policy==./ExtDirs.policy \
|
||||
* -Djava.security.debug=parser \
|
||||
* ExtDirs
|
||||
* @test
|
||||
* @bug 4215035
|
||||
* @summary standard extensions path is hard-coded in default
|
||||
* system policy file
|
||||
* @run main/othervm/policy=ExtDirs.policy ExtDirs
|
||||
*/
|
||||
|
||||
public class ExtDirs {
|
||||
|
@ -1,4 +1,4 @@
|
||||
grant codebase "${java.ext.dirs}" {
|
||||
grant codebase "file:${test.classes}" {
|
||||
permission java.util.PropertyPermission "user.name", "read";
|
||||
permission java.util.PropertyPermission "user.home", "read";
|
||||
};
|
||||
|
@ -1,4 +1,4 @@
|
||||
grant codebase "file:${{java.ext.dirs}}/*" {
|
||||
grant codebase "file:${test.classes}" {
|
||||
permission java.util.PropertyPermission "user.name", "read";
|
||||
permission java.util.PropertyPermission "user.home", "read";
|
||||
};
|
||||
|
@ -1,4 +1,4 @@
|
||||
grant codebase "file:${{java.ext.dirs}}" {
|
||||
grant codebase "file:${test.classes}/*" {
|
||||
permission java.util.PropertyPermission "user.name", "read";
|
||||
permission java.util.PropertyPermission "user.home", "read";
|
||||
};
|
||||
|
@ -1,4 +1,4 @@
|
||||
grant codebase "${{java.ext.dirs}}" {
|
||||
grant codebase "file:${test.classes}/-" {
|
||||
permission java.util.PropertyPermission "user.name", "read";
|
||||
permission java.util.PropertyPermission "user.home", "read";
|
||||
};
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2004, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -26,30 +26,17 @@
|
||||
* @bug 4993819
|
||||
* @summary standard extensions path is hard-coded in default
|
||||
* system policy file
|
||||
* @run main/manual ExtDirsChange
|
||||
* @run main/othervm/policy=ExtDirsChange.policy ExtDirsChange
|
||||
*/
|
||||
|
||||
/*
|
||||
* Run this test manually with:
|
||||
* javac ExtDirChange
|
||||
* rm ExtDirsA*.class ExtDirsB*.class
|
||||
* java -Djava.security.manager \
|
||||
* -Dtest.src=. \
|
||||
* -Djava.security.policy=ExtDirsChange.policy \
|
||||
* -Djava.security.debug=parser \
|
||||
* -cp ExtDirsA/a.jar:ExtDirsB/b.jar:. \
|
||||
* ExtDirsChange
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.security.*;
|
||||
|
||||
public class ExtDirsChange {
|
||||
public static void main(String args[]) throws Exception {
|
||||
System.out.println("java.ext.dirs: " +
|
||||
System.getProperty("java.ext.dirs"));
|
||||
System.out.println("java.policy.dirs: " +
|
||||
System.getProperty("java.policy.dirs"));
|
||||
|
||||
// Uses default security policy and java.ext.dirs
|
||||
// Uses default security policy and java.policy.dirs
|
||||
try {
|
||||
ExtDirsA a = new ExtDirsA();
|
||||
a.go();
|
||||
@ -58,14 +45,14 @@ public class ExtDirsChange {
|
||||
System.out.println("Setup OK");
|
||||
}
|
||||
|
||||
// Change java.ext.dirs and refresh policy
|
||||
// Change java.policy.dirs and refresh policy
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
// Change java.ext.dirs
|
||||
System.setProperty("java.ext.dirs",
|
||||
"ExtDirsA" + File.pathSeparator + "ExtDirsB");
|
||||
System.out.println("java.ext.dirs: " +
|
||||
System.getProperty("java.ext.dirs"));
|
||||
// Change java.policy.dirs
|
||||
System.setProperty("java.policy.dirs",
|
||||
System.getProperty("test.classes"));
|
||||
System.out.println("java.policy.dirs: " +
|
||||
System.getProperty("java.policy.dirs"));
|
||||
return null;
|
||||
}
|
||||
});
|
||||
@ -79,7 +66,7 @@ public class ExtDirsChange {
|
||||
System.out.println("Setup before refresh OK");
|
||||
}
|
||||
|
||||
// Refresh policy using updated java.ext.dirs
|
||||
// Refresh policy using updated java.policy.dirs
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
Policy.getPolicy().refresh();
|
||||
@ -99,13 +86,13 @@ public class ExtDirsChange {
|
||||
}
|
||||
|
||||
// Test with blank java.ext.dir
|
||||
// Change java.ext.dirs and refresh policy
|
||||
// Change java.policy.dirs and refresh policy
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
// Change java.ext.dirs
|
||||
System.setProperty("java.ext.dirs", " ");
|
||||
System.out.println("java.ext.dirs: " +
|
||||
System.getProperty("java.ext.dirs"));
|
||||
// Change java.policy.dirs
|
||||
System.setProperty("java.policy.dirs", " ");
|
||||
System.out.println("java.policy.dirs: " +
|
||||
System.getProperty("java.policy.dirs"));
|
||||
Policy.getPolicy().refresh();
|
||||
return null;
|
||||
}
|
||||
|
@ -1,8 +1,16 @@
|
||||
grant codebase "file:${test.src}/*" {
|
||||
permission java.security.AllPermission;
|
||||
grant {
|
||||
permission java.util.PropertyPermission "test.classes", "read";
|
||||
permission java.security.SecurityPermission "getPolicy";
|
||||
permission java.security.SecurityPermission "setPolicy";
|
||||
};
|
||||
|
||||
grant codebase "${java.ext.dirs}" {
|
||||
grant codebase "file:${test.classes}/*" {
|
||||
permission java.util.PropertyPermission "java.policy.dirs", "read, write";
|
||||
permission java.util.PropertyPermission "user.name", "write";
|
||||
permission java.util.PropertyPermission "user.home", "write";
|
||||
};
|
||||
|
||||
grant codebase "file:${java.policy.dirs}" {
|
||||
permission java.util.PropertyPermission "user.name", "read";
|
||||
permission java.util.PropertyPermission "user.home", "read";
|
||||
};
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2004, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -26,25 +26,34 @@
|
||||
* @bug 4993819
|
||||
* @summary standard extensions path is hard-coded in default
|
||||
* system policy file
|
||||
* @run main/manual ExtDirsDefaultPolicy
|
||||
* @run main ExtDirsDefaultPolicy
|
||||
*/
|
||||
|
||||
/*
|
||||
* Run this test manually with:
|
||||
* java -Djava.security.manager \
|
||||
* -Djava.ext.dirs=./ExtDirsA:./ExtDirsB \
|
||||
* -Djava.security.debug=parser \
|
||||
* ExtDirsDefaultPolicy
|
||||
* @test
|
||||
* @bug 4993819
|
||||
* @summary standard extensions path is hard-coded in default
|
||||
* system policy file
|
||||
*
|
||||
* To test other varients of the ${{java.ext.dirs}} protocol, remove
|
||||
* the grant statement for java.ext.dirs in $JAVA_HOME/lib/security/java.policy
|
||||
* and then run against the 3 different policy files.
|
||||
* @run main/othervm/policy=ExtDirs1.policy ExtDirsDefaultPolicy
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4993819
|
||||
* @summary standard extensions path is hard-coded in default
|
||||
* system policy file
|
||||
*
|
||||
* java -Djava.security.manager \
|
||||
* -Djava.ext.dirs=./ExtDirsA:./ExtDirsB \
|
||||
* -Djava.security.debug=parser \
|
||||
* -Djava.security.policy=ExtDirs{1,2,3}.policy \
|
||||
* ExtDirsDefaultPolicy
|
||||
* @run main/othervm/policy=ExtDirs2.policy ExtDirsDefaultPolicy
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4993819
|
||||
* @summary standard extensions path is hard-coded in default
|
||||
* system policy file
|
||||
*
|
||||
* @run main/othervm/policy=ExtDirs3.policy ExtDirsDefaultPolicy
|
||||
*/
|
||||
|
||||
public class ExtDirsDefaultPolicy {
|
||||
|
Loading…
Reference in New Issue
Block a user