changeset 57970:6e49fb6ad4ee

8237804: sun/security/mscapi tests fail with "Key pair not generated, alias <nnnnnn> already exists" Reviewed-by: mullan
author weijun
date Wed, 05 Feb 2020 11:09:02 +0800
parents 84e55cb3894e
children 3e021f5c81f5
files test/jdk/sun/security/mscapi/KeyAlgorithms.java test/jdk/sun/security/mscapi/PublicKeyInterop.java
diffstat 2 files changed, 24 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/test/jdk/sun/security/mscapi/KeyAlgorithms.java	Tue Feb 04 22:05:31 2020 +0000
+++ b/test/jdk/sun/security/mscapi/KeyAlgorithms.java	Wed Feb 05 11:09:02 2020 +0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2020, 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
@@ -23,7 +23,7 @@
 
 /**
  * @test
- * @bug 8213009
+ * @bug 8213009 8237804
  * @summary Make sure SunMSCAPI keys have correct algorithm names
  * @requires os.family == "windows"
  * @library /test/lib
@@ -42,6 +42,7 @@
 
     public static void main(String[] arg) throws Exception {
 
+        cleanup();
         SecurityTools.keytool("-genkeypair",
                 "-storetype", "Windows-My",
                 "-keyalg", ALG,
@@ -52,13 +53,21 @@
         try {
             test(loadKeysFromKeyStore());
         } finally {
+            cleanup();
+        }
+
+        test(generateKeys());
+    }
+
+    private static void cleanup() {
+        try {
             KeyStore ks = KeyStore.getInstance("Windows-MY");
             ks.load(null, null);
             ks.deleteEntry(ALIAS);
             ks.store(null, null);
+        } catch (Exception e) {
+            System.out.println("No such entry.");
         }
-
-        test(generateKeys());
     }
 
     static KeyPair loadKeysFromKeyStore() throws Exception {
--- a/test/jdk/sun/security/mscapi/PublicKeyInterop.java	Tue Feb 04 22:05:31 2020 +0000
+++ b/test/jdk/sun/security/mscapi/PublicKeyInterop.java	Wed Feb 05 11:09:02 2020 +0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2020, 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
@@ -23,7 +23,7 @@
 
 /**
  * @test
- * @bug 6888925 8180570
+ * @bug 6888925 8180570 8237804
  * @summary SunMSCAPI's Cipher can't use RSA public keys obtained from other sources.
  * @requires os.family == "windows"
  * @library /test/lib
@@ -45,6 +45,7 @@
 
     public static void main(String[] arg) throws Exception {
 
+        cleanup();
         SecurityTools.keytool("-genkeypair",
                 "-storetype", "Windows-My",
                 "-keyalg", "RSA",
@@ -55,10 +56,18 @@
         try {
             run();
         } finally {
+            cleanup();
+        }
+    }
+
+    private static void cleanup() {
+        try {
             KeyStore ks = KeyStore.getInstance("Windows-MY");
             ks.load(null, null);
             ks.deleteEntry("6888925");
             ks.store(null, null);
+        } catch (Exception e) {
+            System.out.println("No such entry.");
         }
     }