Skip to content

Commit

Permalink
fix: build failing on Windows (#4484) (#4504)
Browse files Browse the repository at this point in the history
Change path handling to correctly handle Windows pathnames.

Change line ending handling from using `System.lineSeparator` to using
the regex \R to treat all unicode line ending character sequences as the
line endings.

Change unit tests that compared certificates read from file, to ignore
the line ending characters, so differences in line ending did not break
the test.

Refs: #4484
  • Loading branch information
Barium authored Sep 27, 2024
1 parent 9a8329e commit 21f97ef
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import java.nio.file.Paths;
import java.security.PublicKey;
import java.util.Map;

Expand Down Expand Up @@ -73,7 +74,7 @@ void localPublicKeyService_withPathConfig(LocalPublicKeyDefaultExtension extensi
var value = TestUtils.getResourceFileContentAsString("rsa_2048.pem");
var keys = Map.of(
"key1.id", "key1",
"key1.path", path.getPath());
"key1.path", Paths.get(path).toString());

when(keyParserRegistry.parsePublic(value)).thenReturn(Result.success(mock(PublicKey.class)));
when(context.getConfig(EDC_PUBLIC_KEYS_PREFIX)).thenReturn(ConfigFactory.fromMap(keys));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public class ClasspathReader {
*/
public static URL[] classpathFor(String... modules) {
try {
if (modules.length == 0) {
return new URL[0];
}
// Run a Gradle custom task to determine the runtime classpath of the module to run
var printClasspath = Arrays.stream(modules).map(it -> it + ":printClasspath");
var commandStream = Stream.of(GRADLE_WRAPPER.getCanonicalPath(), "-q");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public VaultCertificateResolver(@NotNull Vault vault) {
}

try {
var encoded = certificateRepresentation.replace(HEADER, "").replaceAll(System.lineSeparator(), "").replace(FOOTER, "");
var encoded = certificateRepresentation.replace(HEADER, "").replaceAll("\\R", "").replace(FOOTER, "");
CertificateFactory fact = CertificateFactory.getInstance("X.509");
return (X509Certificate) fact.generateCertificate(new ByteArrayInputStream(Base64.getDecoder().decode(encoded.getBytes())));
} catch (GeneralSecurityException | IllegalArgumentException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void resolveCertificate() throws RuntimeException, IOException {
var pemReceived = convertCertificateToPem(certificate);

verify(vault, times(1)).resolveSecret(KEY);
assertThat(pemReceived).isEqualTo(pemExpected);
assertThat(pemReceived.split("\\R")).isEqualTo(pemExpected.split("\\R"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class X509CertificateDecoratorTest {
private static X509Certificate createCertificate() throws CertificateException, IOException {
var classloader = Thread.currentThread().getContextClassLoader();
var pem = new String(Objects.requireNonNull(classloader.getResourceAsStream(TEST_CERT_FILE)).readAllBytes());
var encoded = pem.replace(HEADER, "").replaceAll(System.lineSeparator(), "").replace(FOOTER, "");
var encoded = pem.replace(HEADER, "").replaceAll("\\R", "").replace(FOOTER, "");
CertificateFactory fact = CertificateFactory.getInstance("X.509");
return (X509Certificate) fact.generateCertificate(new ByteArrayInputStream(Base64.getDecoder().decode(encoded.getBytes())));
}
Expand Down

0 comments on commit 21f97ef

Please sign in to comment.