54
54
import java .util .ServiceConfigurationError ;
55
55
import java .util .ServiceLoader ;
56
56
import java .util .Set ;
57
+ import java .util .stream .Collectors ;
57
58
import java .util .stream .Stream ;
58
59
59
60
import javax .crypto .SecretKey ;
60
61
import javax .crypto .spec .SecretKeySpec ;
61
62
62
63
import jdk .test .lib .Platform ;
64
+ import jdk .test .lib .Utils ;
63
65
import jdk .test .lib .artifacts .Artifact ;
64
66
import jdk .test .lib .artifacts .ArtifactResolver ;
65
67
import jdk .test .lib .artifacts .ArtifactResolverException ;
@@ -486,14 +488,13 @@ public static String getNssConfig() throws Exception {
486
488
return null ;
487
489
}
488
490
489
- String base = getBase ();
490
-
491
+ String nssConfigDir = copyNssFiles ();
491
492
String libfile = libdir + System .mapLibraryName (nss_library );
492
493
493
494
String customDBdir = System .getProperty ("CUSTOM_DB_DIR" );
494
495
String dbdir = (customDBdir != null ) ?
495
496
customDBdir :
496
- base + SEP + "nss" + SEP + "db" ;
497
+ nssConfigDir + SEP + "db" ;
497
498
// NSS always wants forward slashes for the config path
498
499
dbdir = dbdir .replace ('\\' , '/' );
499
500
@@ -503,7 +504,7 @@ public static String getNssConfig() throws Exception {
503
504
System .setProperty ("pkcs11test.nss.db" , dbdir );
504
505
return (customConfig != null ) ?
505
506
customConfig :
506
- base + SEP + "nss" + SEP + customConfigName ;
507
+ nssConfigDir + SEP + customConfigName ;
507
508
}
508
509
509
510
// 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
786
787
}
787
788
}
788
789
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
+
789
815
public abstract void main (Provider p ) throws Exception ;
790
816
791
817
protected boolean skipTest (Provider p ) {
0 commit comments