8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
Summary: Enhanced test to detect if the corresponding module is present and update provider list.
Reviewed-by: mchung, valeriep
--- a/jdk/test/java/lang/SecurityManager/CheckSecurityProvider.java Thu Jul 07 17:05:23 2016 -0700
+++ b/jdk/test/java/lang/SecurityManager/CheckSecurityProvider.java Fri Jul 08 00:50:28 2016 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2016, 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
@@ -28,11 +28,14 @@
* @run main/othervm CheckSecurityProvider
*/
+import java.lang.reflect.Layer;
import java.security.Provider;
import java.security.Security;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
/*
* The main benefit of this test is to catch merge errors or other types
@@ -42,6 +45,8 @@
*/
public class CheckSecurityProvider {
public static void main(String[] args) throws Exception {
+ Layer layer = Layer.boot();
+
System.setSecurityManager(new SecurityManager());
String os = System.getProperty("os.name");
@@ -55,43 +60,60 @@
// NOTE: the ordering must match what's defined inside java.security
if (os.equals("SunOS")) {
- expected.add("com.oracle.security.ucrypto.UcryptoProvider");
- expected.add("sun.security.pkcs11.SunPKCS11");
+ layer.findModule("jdk.crypto.ucrypto")
+ .ifPresent(m -> expected.add("com.oracle.security.ucrypto.UcryptoProvider"));
+ layer.findModule("jdk.crypto.pkcs11")
+ .ifPresent(m -> expected.add("sun.security.pkcs11.SunPKCS11"));
}
expected.add("sun.security.provider.Sun");
expected.add("sun.security.rsa.SunRsaSign");
- expected.add("sun.security.ec.SunEC");
+ layer.findModule("jdk.crypto.ec")
+ .ifPresent(m -> expected.add("sun.security.ec.SunEC"));
expected.add("com.sun.net.ssl.internal.ssl.Provider");
expected.add("com.sun.crypto.provider.SunJCE");
- expected.add("sun.security.jgss.SunProvider");
- expected.add("com.sun.security.sasl.Provider");
- expected.add("org.jcp.xml.dsig.internal.dom.XMLDSigRI");
- expected.add("sun.security.smartcardio.SunPCSC");
- expected.add("sun.security.provider.certpath.ldap.JdkLDAP");
- expected.add("com.sun.security.sasl.gsskerb.JdkSASL");
+ layer.findModule("jdk.security.jgss")
+ .ifPresent(m -> expected.add("sun.security.jgss.SunProvider"));
+ layer.findModule("java.security.sasl")
+ .ifPresent(m -> expected.add("com.sun.security.sasl.Provider"));
+ layer.findModule("java.xml.crypto")
+ .ifPresent(m -> expected.add("org.jcp.xml.dsig.internal.dom.XMLDSigRI"));
+ layer.findModule("java.smartcardio")
+ .ifPresent(m -> expected.add("sun.security.smartcardio.SunPCSC"));
+ layer.findModule("java.naming")
+ .ifPresent(m -> expected.add("sun.security.provider.certpath.ldap.JdkLDAP"));
+ layer.findModule("jdk.security.jgss")
+ .ifPresent(m -> expected.add("com.sun.security.sasl.gsskerb.JdkSASL"));
if (os.startsWith("Windows")) {
- expected.add("sun.security.mscapi.SunMSCAPI");
+ layer.findModule("jdk.crypto.mscapi")
+ .ifPresent(m -> expected.add("sun.security.mscapi.SunMSCAPI"));
}
if (os.contains("OS X")) {
expected.add("apple.security.AppleProvider");
}
if (!os.equals("SunOS")) {
- expected.add("sun.security.pkcs11.SunPKCS11");
+ layer.findModule("jdk.crypto.pkcs11")
+ .ifPresent(m -> expected.add("sun.security.pkcs11.SunPKCS11"));
}
+ List<String> actual = Stream.of(Security.getProviders())
+ .map(p -> p.getClass().getName())
+ .collect(Collectors.toList());
+
+ System.out.println("Expected providers:");
+ expected.stream().forEach(System.out::println);
+ System.out.println("Actual providers:");
+ actual.stream().forEach(System.out::println);
+
+ if (expected.size() != actual.size()) {
+ throw new Exception("Unexpected provider count. "
+ + "Expected: " + expected.size() + ". Actual: " + actual.size());
+ }
Iterator<String> iter = expected.iterator();
- for (Provider p: Security.getProviders()) {
- if (!iter.hasNext()) {
- throw new Exception("Less expected");
+ for (String p: actual) {
+ String nextExpected = iter.next();
+ if (!nextExpected.equals(p)) {
+ throw new Exception("Expected " + nextExpected + ", actual " + p);
}
- String n1 = iter.next();
- String n2 = p.getClass().getName();
- if (!n1.equals(n2)) {
- throw new Exception("Expected " + n1 + ", actual " + n2);
- }
- }
- if (iter.hasNext()) {
- throw new Exception("More expected");
}
}
}