8012971: PKCS11Test hiding exception failures
authorascarpino
Fri, 19 Jul 2013 11:34:33 -0700
changeset 19066 daf668acb10e
parent 19065 f7c941aa63ee
child 19067 5271291b7121
8012971: PKCS11Test hiding exception failures Reviewed-by: vinnie, valeriep
jdk/test/ProblemList.txt
jdk/test/sun/security/pkcs11/PKCS11Test.java
jdk/test/sun/security/pkcs11/SecmodTest.java
--- a/jdk/test/ProblemList.txt	Mon Jul 29 19:41:02 2013 +0100
+++ b/jdk/test/ProblemList.txt	Fri Jul 19 11:34:33 2013 -0700
@@ -255,6 +255,23 @@
 
 # jdk_security
 
+# 8012971 PKCS11Test hiding exception failures
+sun/security/pkcs11/KeyStore/SecretKeysBasic.java		solaris-all
+sun/security/pkcs11/KeyStore/SecretKeysBasic.java		linux-all
+sun/security/pkcs11/ec/TestCurves.java				solaris-all
+sun/security/pkcs11/ec/TestCurves.java				linux-all
+sun/security/pkcs11/ec/TestECDH.java				solaris-all
+sun/security/pkcs11/ec/TestECDH2.java				solaris-all
+sun/security/pkcs11/ec/TestECDH2.java				linux-all
+sun/security/pkcs11/ec/TestECDSA.java				solaris-all
+sun/security/pkcs11/ec/TestECDSA.java				linux-all
+sun/security/pkcs11/ec/TestECDSA2.java				solaris-all
+sun/security/pkcs11/ec/TestECDSA2.java				linux-all
+sun/security/pkcs11/ec/TestECGenSpec.java			solaris-all
+sun/security/pkcs11/ec/TestECGenSpec.java			linux-all
+sun/security/pkcs11/ec/TestKeyFactory.java			solaris-all
+sun/security/pkcs11/ec/TestKeyFactory.java			linux-all
+
 # 7164518: no PortUnreachableException on Mac
 sun/security/krb5/auto/Unreachable.java                         macosx-all
 
--- a/jdk/test/sun/security/pkcs11/PKCS11Test.java	Mon Jul 29 19:41:02 2013 +0100
+++ b/jdk/test/sun/security/pkcs11/PKCS11Test.java	Fri Jul 19 11:34:33 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2013, 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
@@ -54,6 +54,11 @@
 
     static String NSPR_PREFIX = "";
 
+    // The NSS library we need to search for in getNSSLibDir()
+    // Default is "libsoftokn3.so", listed as "softokn3"
+    // The other is "libnss3.so", listed as "nss3".
+    static String nss_library = "softokn3";
+
     static Provider getSunPKCS11(String config) throws Exception {
         Class clazz = Class.forName("sun.security.pkcs11.SunPKCS11");
         Constructor cons = clazz.getConstructor(new Class[] {String.class});
@@ -79,24 +84,28 @@
             testNSS(test);
             testDeimos(test);
         } finally {
+            // NOTE: Do not place a 'return' in any finally block
+            // as it will suppress exceptions and hide test failures.
             Provider[] newProviders = Security.getProviders();
+            boolean found = true;
             // Do not restore providers if nothing changed. This is especailly
             // useful for ./Provider/Login.sh, where a SecurityManager exists.
             if (oldProviders.length == newProviders.length) {
-                boolean found = false;
+                found = false;
                 for (int i = 0; i<oldProviders.length; i++) {
                     if (oldProviders[i] != newProviders[i]) {
                         found = true;
                         break;
                     }
                 }
-                if (!found) return;
             }
-            for (Provider p: newProviders) {
-                Security.removeProvider(p.getName());
-            }
-            for (Provider p: oldProviders) {
-                Security.addProvider(p);
+            if (found) {
+                for (Provider p: newProviders) {
+                    Security.removeProvider(p.getName());
+                }
+                for (Provider p: oldProviders) {
+                    Security.addProvider(p);
+                }
             }
         }
     }
@@ -178,7 +187,8 @@
         }
         String nssLibDir = null;
         for (String dir : nssLibDirs) {
-            if (new File(dir).exists()) {
+            if (new File(dir).exists() &&
+                new File(dir + System.mapLibraryName(nss_library)).exists()) {
                 nssLibDir = dir;
                 System.setProperty("pkcs11test.nss.libdir", nssLibDir);
                 break;
@@ -207,6 +217,11 @@
         return true;
     }
 
+    // Used to set the nss_library file to search for libsoftokn3.so
+    public static void useNSS() {
+        nss_library = "nss3";
+    }
+
     public static void testNSS(PKCS11Test test) throws Exception {
         String libdir = getNSSLibDir();
         if (libdir == null) {
@@ -218,7 +233,7 @@
             return;
         }
 
-        String libfile = libdir + System.mapLibraryName("softokn3");
+        String libfile = libdir + System.mapLibraryName(nss_library);
 
         String customDBdir = System.getProperty("CUSTOM_DB_DIR");
         String dbdir = (customDBdir != null) ?
@@ -252,7 +267,8 @@
         osMap.put("Linux-i386-32", new String[]{
             "/usr/lib/i386-linux-gnu/", "/usr/lib/"});
         osMap.put("Linux-amd64-64", new String[]{
-            "/usr/lib/x86_64-linux-gnu/", "/usr/lib64/"});
+            "/usr/lib/x86_64-linux-gnu/", "/usr/lib/x86_64-linux-gnu/nss/",
+            "/usr/lib64/"});
         osMap.put("Windows-x86-32", new String[]{
             PKCS11_BASE + "/nss/lib/windows-i586/".replace('/', SEP)});
         osMap.put("Windows-amd64-64", new String[]{
--- a/jdk/test/sun/security/pkcs11/SecmodTest.java	Mon Jul 29 19:41:02 2013 +0100
+++ b/jdk/test/sun/security/pkcs11/SecmodTest.java	Fri Jul 19 11:34:33 2013 -0700
@@ -36,6 +36,7 @@
     static String keyAlias = "mykey";
 
     static boolean initSecmod() throws Exception {
+        useNSS();
         LIBPATH = getNSSLibDir();
         if (LIBPATH == null) {
             return false;