Skip to content

Commit b368809

Browse files
committed
8209546: Make sun/security/tools/keytool/autotest.sh to support macosx
Refactor autotest.sh to java test and remove standard.sh Reviewed-by: rrich Backport-of: afe0580
1 parent 6dc0712 commit b368809

File tree

6 files changed

+101
-228
lines changed

6 files changed

+101
-228
lines changed

test/jdk/ProblemList.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ sun/security/provider/PolicyFile/GrantAllPermToExtWhenNoPolicy.java 8039280 gene
648648
sun/security/provider/PolicyParser/ExtDirsChange.java 8039280 generic-all
649649
sun/security/provider/PolicyParser/PrincipalExpansionError.java 8039280 generic-all
650650

651-
sun/security/tools/keytool/NssTest.java 8295343 linux-all
651+
sun/security/tools/keytool/NssTest.java 8295343,8204203 linux-all,windows-all
652652
sun/security/pkcs11/Signature/TestRSAKeyLength.java 8295343 linux-all
653653
sun/security/pkcs11/rsa/TestSignatures.java 8295343 linux-all
654654
sun/security/pkcs11/rsa/TestKeyPairGenerator.java 8295343 linux-all

test/jdk/sun/security/pkcs11/PKCS11Test.java

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.io.File;
2929
import java.io.FileInputStream;
3030
import java.io.IOException;
31+
import java.io.InputStream;
3132
import java.io.InputStreamReader;
3233
import java.io.StringReader;
3334
import java.nio.charset.StandardCharsets;
@@ -347,6 +348,22 @@ public static String getNSSLibDir() throws Exception {
347348
}
348349

349350
static String getNSSLibDir(String library) throws Exception {
351+
Path libPath = getNSSLibPath(library);
352+
if (libPath == null) {
353+
return null;
354+
}
355+
356+
String libDir = String.valueOf(libPath.getParent()) + File.separatorChar;
357+
System.out.println("nssLibDir: " + libDir);
358+
System.setProperty("pkcs11test.nss.libdir", libDir);
359+
return libDir;
360+
}
361+
362+
private static Path getNSSLibPath() throws Exception {
363+
return getNSSLibPath(nss_library);
364+
}
365+
366+
static Path getNSSLibPath(String library) throws Exception {
350367
String osid = getOsId();
351368
String[] nssLibDirs = getNssLibPaths(osid);
352369
if (nssLibDirs == null) {
@@ -358,21 +375,20 @@ static String getNSSLibDir(String library) throws Exception {
358375
System.out.println("Warning: NSS not supported on this platform, skipping test");
359376
return null;
360377
}
361-
String nssLibDir = null;
378+
379+
Path nssLibPath = null;
362380
for (String dir : nssLibDirs) {
363-
if (new File(dir).exists() &&
364-
new File(dir + System.mapLibraryName(library)).exists()) {
365-
nssLibDir = dir;
366-
System.out.println("nssLibDir: " + nssLibDir);
367-
System.setProperty("pkcs11test.nss.libdir", nssLibDir);
381+
Path libPath = Paths.get(dir).resolve(System.mapLibraryName(library));
382+
if (Files.exists(libPath)) {
383+
nssLibPath = libPath;
368384
break;
369385
}
370386
}
371-
if (nssLibDir == null) {
387+
if (nssLibPath == null) {
372388
System.out.println("Warning: can't find NSS librarys on this machine, skipping test");
373389
return null;
374390
}
375-
return nssLibDir;
391+
return nssLibPath;
376392
}
377393

378394
private static String getOsId() {
@@ -466,20 +482,19 @@ static double getNSSInfo(String library) {
466482
boolean found = false;
467483
String s = null;
468484
int i = 0;
469-
String libfile = "";
485+
Path libfile = null;
470486

471487
if (library.compareTo("softokn3") == 0 && softoken3_version > -1)
472488
return softoken3_version;
473489
if (library.compareTo("nss3") == 0 && nss3_version > -1)
474490
return nss3_version;
475491

476492
try {
477-
String libdir = getNSSLibDir();
478-
if (libdir == null) {
493+
libfile = getNSSLibPath();
494+
if (libfile == null) {
479495
return 0.0;
480496
}
481-
libfile = libdir + System.mapLibraryName(library);
482-
try (FileInputStream is = new FileInputStream(libfile)) {
497+
try (InputStream is = Files.newInputStream(libfile)) {
483498
byte[] data = new byte[1000];
484499
int read = 0;
485500

test/jdk/sun/security/tools/keytool/KeyToolTest.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@
2222
*/
2323

2424
/*
25-
*
26-
*
27-
* @summary Testing keytool
25+
* @test
2826
* @author weijun.wang
27+
* @summary Testing keytool
2928
*
3029
* Run through autotest.sh and manualtest.sh
3130
*
@@ -54,6 +53,12 @@
5453
*
5554
* ATTENTION:
5655
* NSS PKCS11 config file are changed, DSA not supported now.
56+
*
57+
* @library /test/lib
58+
* @modules java.base/sun.security.tools.keytool
59+
* java.base/sun.security.util
60+
* java.base/sun.security.x509
61+
* @run main/othervm/timeout=600 -Dfile KeyToolTest
5762
*/
5863

5964
import java.nio.file.Files;
@@ -68,6 +73,7 @@
6873
import jdk.test.lib.util.FileUtils;
6974
import sun.security.util.ObjectIdentifier;
7075

76+
7177
public class KeyToolTest {
7278

7379
// The stdout and stderr outputs after a keytool run
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
import java.io.IOException;
25+
import java.nio.file.Files;
26+
import java.nio.file.Path;
27+
import java.nio.file.Paths;
28+
29+
/*
30+
* @test
31+
* @summary It tests (almost) all keytool behaviors with NSS.
32+
* @library /test/lib /test/jdk/sun/security/pkcs11
33+
* @modules java.base/sun.security.tools.keytool
34+
* java.base/sun.security.util
35+
* java.base/sun.security.x509
36+
* @run main/othervm/timeout=600 NssTest
37+
*/
38+
public class NssTest {
39+
40+
public static void main(String[] args) throws Exception {
41+
Path libPath = PKCS11Test.getNSSLibPath("softokn3");
42+
if (libPath == null) {
43+
return;
44+
}
45+
System.out.println("Using NSS lib at " + libPath);
46+
47+
copyFiles();
48+
System.setProperty("nss", "");
49+
System.setProperty("nss.lib", String.valueOf(libPath));
50+
KeyToolTest.main(args);
51+
}
52+
53+
private static void copyFiles() throws IOException {
54+
Path srcPath = Paths.get(System.getProperty("test.src"));
55+
Files.copy(srcPath.resolve("p11-nss.txt"), Paths.get("p11-nss.txt"));
56+
57+
Path dbPath = srcPath.getParent().getParent()
58+
.resolve("pkcs11").resolve("nss").resolve("db");
59+
Files.copy(dbPath.resolve("cert8.db"), Paths.get("cert8.db"));
60+
Files.copy(dbPath.resolve("key3.db"), Paths.get("key3.db"));
61+
Files.copy(dbPath.resolve("secmod.db"), Paths.get("secmod.db"));
62+
}
63+
}

test/jdk/sun/security/tools/keytool/autotest.sh

Lines changed: 0 additions & 130 deletions
This file was deleted.

0 commit comments

Comments
 (0)