Skip to content

Commit 342fe42

Browse files
committed
8342270: Test sun/security/pkcs11/Provider/RequiredMechCheck.java needs write access to src tree
Reviewed-by: rhalade, erikj
1 parent 78b378a commit 342fe42

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;
@@ -496,14 +498,13 @@ public static String getNssConfig() throws Exception {
496498
return null;
497499
}
498500

499-
String base = getBase();
500-
501+
String nssConfigDir = copyNssFiles();
501502
String libfile = libdir + System.mapLibraryName(nss_library);
502503

503504
String customDBdir = System.getProperty("CUSTOM_DB_DIR");
504505
String dbdir = (customDBdir != null) ?
505506
customDBdir :
506-
base + SEP + "nss" + SEP + "db";
507+
nssConfigDir + SEP + "db";
507508
// NSS always wants forward slashes for the config path
508509
dbdir = dbdir.replace('\\', '/');
509510

@@ -513,7 +514,7 @@ public static String getNssConfig() throws Exception {
513514
System.setProperty("pkcs11test.nss.db", dbdir);
514515
return (customConfig != null) ?
515516
customConfig :
516-
base + SEP + "nss" + SEP + customConfigName;
517+
nssConfigDir + SEP + customConfigName;
517518
}
518519

519520
// Generate a vector of supported elliptic curves of a given provider
@@ -796,6 +797,31 @@ private static Path findNSSLibrary(Path path, Path libraryName) throws IOExcepti
796797
}
797798
}
798799

800+
//Copy the nss config files to the current directory for tests. Returns the destination path
801+
private static String copyNssFiles() throws Exception {
802+
String nss = "nss";
803+
String db = "db";
804+
Path nssDirSource = Path.of(getBase()).resolve(nss);
805+
Path nssDirDestination = Path.of(".").resolve(nss);
806+
807+
// copy files from nss directory
808+
copyFiles(nssDirSource, nssDirDestination);
809+
// copy files from nss/db directory
810+
copyFiles(nssDirSource.resolve(db), nssDirDestination.resolve(db));
811+
return nssDirDestination.toString();
812+
}
813+
814+
private static void copyFiles(Path dirSource, Path dirDestination) throws IOException {
815+
List<Path> sourceFiles = Arrays
816+
.stream(dirSource.toFile().listFiles())
817+
.filter(File::isFile)
818+
.map(File::toPath)
819+
.collect(Collectors.toList());
820+
List<Path> destFiles = Utils.copyFiles(sourceFiles, dirDestination,
821+
StandardCopyOption.REPLACE_EXISTING);
822+
destFiles.forEach((Path file) -> file.toFile().setWritable(true));
823+
}
824+
799825
public abstract void main(Provider p) throws Exception;
800826

801827
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)