Skip to content

Commit b1ee454

Browse files
committed
Cater for Windows mess with backslashes in file path when rendering as
string
1 parent 4b84dca commit b1ee454

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Server/src/test/java/org/openas2/app/CertificatesTest.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,15 @@ public void setUp() throws Exception {
8484
String tgtHostName = "test.openas2.org";
8585
this.alias = tgtHostName;
8686
// Create the SSL file for the server to use
87-
String sslCertsFilePath = sslCertsFile.getAbsolutePath();
87+
// Switch to forward slash to avoid backslash being dropped when creating property string when on Windows
88+
String sslCertsFilePath = sslCertsFile.getAbsolutePath().replace("\\", "/");
8889
this.certFx = genSelfSignedCert(alias, sslCertsFilePath, "RSA", "SHA256", 2048, tgtHostName);
8990
// Create the trust store with the public key so the certificate returned from the server is trusted
9091
sslTrustCertsFile = Files.createFile(Paths.get(tmpDirAbsolutePath, "ssl_trust_certs.p12")).toFile();
92+
// Switch to forward slash to avoid backslash being dropped when creating property string when on Windows
93+
String sslTrustCertsFilePath = sslTrustCertsFile.getAbsolutePath().replace("\\", "/");
9194
String trustAlias = "trust-" + tgtHostName;
92-
this.certFx.exportPublicKey(sslTrustCertsFile.getAbsolutePath(), this.alias, trustAlias, password);
95+
this.certFx.exportPublicKey(sslTrustCertsFilePath, this.alias, trustAlias, password);
9396
this.trustFx = new X509CertificateFactory();
9497
this.trustFx.setFilename(sslTrustCertsFile.getAbsolutePath());
9598
this.trustFx.setPassword(password);
@@ -99,6 +102,7 @@ public void setUp() throws Exception {
99102
customPropsFile = Files.createFile(Paths.get(tmpDirAbsolutePath, "openas2.properties")).toFile();
100103
System.setProperty(Properties.OPENAS2_PROPERTIES_FILE_PROP, customPropsFile.getAbsolutePath());
101104
FileOutputStream fos = new FileOutputStream(customPropsFile);
105+
// Switch to forward slash to avoid backslash being dropped when creating property string when on Windows
102106
fos.write(("ssl_keystore=" + sslCertsFilePath + "\n").getBytes());
103107
fos.write(("ssl_keystore_password=" + new String(password) + "\n").getBytes());
104108
//fos.write(("ssl_trust_keystore=" + sslTrustCertsFile.getAbsolutePath() + "\n").getBytes());

0 commit comments

Comments
 (0)