Skip to content

Commit

Permalink
8295087: Manual Test to Automated Test Conversion
Browse files Browse the repository at this point in the history
Reviewed-by: ssahoo, rhalade
  • Loading branch information
Bill Huang committed Dec 22, 2022
1 parent 5012039 commit a3693cc
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 102 deletions.
1 change: 0 additions & 1 deletion test/jdk/ProblemList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions test/jdk/TEST.groups
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
45 changes: 32 additions & 13 deletions test/jdk/java/security/Policy/Root/Root.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()));
}
}
67 changes: 42 additions & 25 deletions test/jdk/javax/crypto/CryptoPermissions/InconsistentEntries.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}
4 changes: 4 additions & 0 deletions test/jdk/javax/crypto/CryptoPermissions/default_local.policy
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
grant {
permission javax.crypto.CryptoAllPermission;
permission javax.crypto.CryptoPermission "DES", 64;
}
15 changes: 7 additions & 8 deletions test/jdk/sun/security/provider/PolicyParser/ExtDirs.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion test/jdk/sun/security/provider/PolicyParser/ExtDirs.policy
Original file line number Diff line number Diff line change
@@ -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";
};
Original file line number Diff line number Diff line change
@@ -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";
};
Original file line number Diff line number Diff line change
@@ -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";
};
Original file line number Diff line number Diff line change
@@ -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";
};
47 changes: 17 additions & 30 deletions test/jdk/sun/security/provider/PolicyParser/ExtDirsChange.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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();
Expand All @@ -58,14 +45,14 @@ public static void main(String args[]) throws Exception {
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;
}
});
Expand All @@ -79,7 +66,7 @@ public Object run() {
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();
Expand All @@ -99,13 +86,13 @@ public Object run() {
}

// 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;
}
Expand Down
14 changes: 11 additions & 3 deletions test/jdk/sun/security/provider/PolicyParser/ExtDirsChange.policy
Original file line number Diff line number Diff line change
@@ -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";
};
Expand Down
Loading

0 comments on commit a3693cc

Please sign in to comment.