From fda981dbdffaf2372dbf53becd21a02f4d288890 Mon Sep 17 00:00:00 2001 From: Tommy Andersen Date: Fri, 27 Sep 2024 11:49:03 +0200 Subject: [PATCH] fix: build failing on Windows (#4484) 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 --- .../edc/connector/core/LocalPublicKeyDefaultExtensionTest.java | 3 ++- .../java/org/eclipse/edc/junit/extensions/ClasspathReader.java | 3 +++ .../java/org/eclipse/edc/keys/VaultCertificateResolver.java | 2 +- .../org/eclipse/edc/keys/VaultCertificateResolverTest.java | 2 +- .../edc/iam/oauth2/jwt/X509CertificateDecoratorTest.java | 2 +- 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/core/common/connector-core/src/test/java/org/eclipse/edc/connector/core/LocalPublicKeyDefaultExtensionTest.java b/core/common/connector-core/src/test/java/org/eclipse/edc/connector/core/LocalPublicKeyDefaultExtensionTest.java index 2fa61df874b..63e0198c859 100644 --- a/core/common/connector-core/src/test/java/org/eclipse/edc/connector/core/LocalPublicKeyDefaultExtensionTest.java +++ b/core/common/connector-core/src/test/java/org/eclipse/edc/connector/core/LocalPublicKeyDefaultExtensionTest.java @@ -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; @@ -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)); diff --git a/core/common/junit/src/main/java/org/eclipse/edc/junit/extensions/ClasspathReader.java b/core/common/junit/src/main/java/org/eclipse/edc/junit/extensions/ClasspathReader.java index 97e6b72fbfc..e3e6638fc32 100644 --- a/core/common/junit/src/main/java/org/eclipse/edc/junit/extensions/ClasspathReader.java +++ b/core/common/junit/src/main/java/org/eclipse/edc/junit/extensions/ClasspathReader.java @@ -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"); diff --git a/core/common/lib/keys-lib/src/main/java/org/eclipse/edc/keys/VaultCertificateResolver.java b/core/common/lib/keys-lib/src/main/java/org/eclipse/edc/keys/VaultCertificateResolver.java index 3615fc1ec3a..ca311c06bf8 100644 --- a/core/common/lib/keys-lib/src/main/java/org/eclipse/edc/keys/VaultCertificateResolver.java +++ b/core/common/lib/keys-lib/src/main/java/org/eclipse/edc/keys/VaultCertificateResolver.java @@ -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) { diff --git a/core/common/lib/keys-lib/src/test/java/org/eclipse/edc/keys/VaultCertificateResolverTest.java b/core/common/lib/keys-lib/src/test/java/org/eclipse/edc/keys/VaultCertificateResolverTest.java index 58c077444ae..f720bf18814 100644 --- a/core/common/lib/keys-lib/src/test/java/org/eclipse/edc/keys/VaultCertificateResolverTest.java +++ b/core/common/lib/keys-lib/src/test/java/org/eclipse/edc/keys/VaultCertificateResolverTest.java @@ -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 diff --git a/extensions/common/iam/oauth2/oauth2-core/src/test/java/org/eclipse/edc/iam/oauth2/jwt/X509CertificateDecoratorTest.java b/extensions/common/iam/oauth2/oauth2-core/src/test/java/org/eclipse/edc/iam/oauth2/jwt/X509CertificateDecoratorTest.java index ccb3ae7fee9..7fcba868f02 100644 --- a/extensions/common/iam/oauth2/oauth2-core/src/test/java/org/eclipse/edc/iam/oauth2/jwt/X509CertificateDecoratorTest.java +++ b/extensions/common/iam/oauth2/oauth2-core/src/test/java/org/eclipse/edc/iam/oauth2/jwt/X509CertificateDecoratorTest.java @@ -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()))); }