8185620: MSCAPI test leaves too many entries in keystore
authormli
Mon, 14 Aug 2017 21:24:45 -0700
changeset 46155 a6288a07bb53
parent 46154 fcef65412084
child 46156 79e8a865c5b8
8185620: MSCAPI test leaves too many entries in keystore Summary: Deletes the added entries before exiting Reviewed-by: vinnie Contributed-by: John Jiang <sha.jiang@oracle.com>
jdk/test/sun/security/mscapi/SmallPrimeExponentP.java
--- a/jdk/test/sun/security/mscapi/SmallPrimeExponentP.java	Mon Aug 14 17:19:31 2017 -0700
+++ b/jdk/test/sun/security/mscapi/SmallPrimeExponentP.java	Mon Aug 14 21:24:45 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, 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
@@ -55,6 +55,9 @@
         CertAndKeyGen ckg = new CertAndKeyGen("RSA", "SHA1withRSA");
         ckg.setRandom(new MySecureRandom(seed));
 
+        String alias = "anything";
+        int count = 0;
+
         boolean see63 = false;
         boolean see65 = false;
         while (!see63 || !see65) {
@@ -78,12 +81,19 @@
                         see65 = true;
                     }
                 }
-                ks.setKeyEntry("anything", k, null, new X509Certificate[]{
+                ks.setKeyEntry(alias, k, null, new X509Certificate[]{
                     ckg.getSelfCertificate(new X500Name("CN=Me"), 1000)
                 });
+                count++;
             }
         }
-        ks.store(null, null);
+
+        // Because of JDK-8185844, it has to reload the key store after
+        // deleting an entry.
+        for (int i = 0; i < count; i++) {
+            ks.deleteEntry(alias);
+            ks.load(null, null);
+        }
     }
 
     static class MySecureRandom extends SecureRandom {