Skip to content

Commit 2924515

Browse files
committed
8342270: Test sun/security/pkcs11/Provider/RequiredMechCheck.java needs write access to src tree
Backport-of: 342fe42555a0e892d21d187287ab996be199abb1
1 parent 1cfc1e7 commit 2924515

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

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

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,14 @@
5454
import java.util.ServiceConfigurationError;
5555
import java.util.ServiceLoader;
5656
import java.util.Set;
57+
import java.util.stream.Collectors;
5758
import java.util.stream.Stream;
5859

5960
import javax.crypto.SecretKey;
6061
import javax.crypto.spec.SecretKeySpec;
6162

6263
import jdk.test.lib.Platform;
64+
import jdk.test.lib.Utils;
6365
import jdk.test.lib.artifacts.Artifact;
6466
import jdk.test.lib.artifacts.ArtifactResolver;
6567
import jdk.test.lib.artifacts.ArtifactResolverException;
@@ -486,14 +488,13 @@ public static String getNssConfig() throws Exception {
486488
return null;
487489
}
488490

489-
String base = getBase();
490-
491+
String nssConfigDir = copyNssFiles();
491492
String libfile = libdir + System.mapLibraryName(nss_library);
492493

493494
String customDBdir = System.getProperty("CUSTOM_DB_DIR");
494495
String dbdir = (customDBdir != null) ?
495496
customDBdir :
496-
base + SEP + "nss" + SEP + "db";
497+
nssConfigDir + SEP + "db";
497498
// NSS always wants forward slashes for the config path
498499
dbdir = dbdir.replace('\\', '/');
499500

@@ -503,7 +504,7 @@ public static String getNssConfig() throws Exception {
503504
System.setProperty("pkcs11test.nss.db", dbdir);
504505
return (customConfig != null) ?
505506
customConfig :
506-
base + SEP + "nss" + SEP + customConfigName;
507+
nssConfigDir + SEP + customConfigName;
507508
}
508509

509510
// Generate a vector of supported elliptic curves of a given provider
@@ -786,6 +787,31 @@ private static Path findNSSLibrary(Path path, Path libraryName) throws IOExcepti
786787
}
787788
}
788789

790+
//Copy the nss config files to the current directory for tests. Returns the destination path
791+
private static String copyNssFiles() throws Exception {
792+
String nss = "nss";
793+
String db = "db";
794+
Path nssDirSource = Path.of(getBase()).resolve(nss);
795+
Path nssDirDestination = Path.of(".").resolve(nss);
796+
797+
// copy files from nss directory
798+
copyFiles(nssDirSource, nssDirDestination);
799+
// copy files from nss/db directory
800+
copyFiles(nssDirSource.resolve(db), nssDirDestination.resolve(db));
801+
return nssDirDestination.toString();
802+
}
803+
804+
private static void copyFiles(Path dirSource, Path dirDestination) throws IOException {
805+
List<Path> sourceFiles = Arrays
806+
.stream(dirSource.toFile().listFiles())
807+
.filter(File::isFile)
808+
.map(File::toPath)
809+
.collect(Collectors.toList());
810+
List<Path> destFiles = Utils.copyFiles(sourceFiles, dirDestination,
811+
StandardCopyOption.REPLACE_EXISTING);
812+
destFiles.forEach((Path file) -> file.toFile().setWritable(true));
813+
}
814+
789815
public abstract void main(Provider p) throws Exception;
790816

791817
protected boolean skipTest(Provider p) {

test/jdk/sun/security/pkcs11/Provider/MultipleLogins.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,7 @@
2727
# @library /test/lib/
2828
# @build jdk.test.lib.util.ForceGC
2929
# jdk.test.lib.Platform
30+
# jdk.test.lib.Utils
3031
# @run shell MultipleLogins.sh
3132

3233
# set a few environment variables so that the shell-script can run stand-alone

0 commit comments

Comments
 (0)