diff --git a/src/adapter/outbound/objectstorage/src/integrationTest/java/dev/caskeleton/adapter/outbound/objectstorage/s3/MinioS3ManagedObjectProviderContractTest.java b/src/adapter/outbound/objectstorage/src/integrationTest/java/dev/caskeleton/adapter/outbound/objectstorage/s3/MinioS3ManagedObjectProviderContractTest.java index f4409a48..c1547434 100644 --- a/src/adapter/outbound/objectstorage/src/integrationTest/java/dev/caskeleton/adapter/outbound/objectstorage/s3/MinioS3ManagedObjectProviderContractTest.java +++ b/src/adapter/outbound/objectstorage/src/integrationTest/java/dev/caskeleton/adapter/outbound/objectstorage/s3/MinioS3ManagedObjectProviderContractTest.java @@ -15,6 +15,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.testcontainers.DockerClientFactory; import org.testcontainers.containers.GenericContainer; import org.testcontainers.utility.MountableFile; import software.amazon.awssdk.services.s3.S3AsyncClient; @@ -53,7 +54,11 @@ class MinioS3ManagedObjectProviderContractTest extends ObjectStorageProviderCont String secretKey = UUID.randomUUID().toString().replace("-", "") + UUID.randomUUID(); byte[] keyBytes = new byte[32]; SECURE_RANDOM.nextBytes(keyBytes); - Path certificates = SelfSignedServerCertificate.writeTo(Files.createTempDirectory("minio-tls")); + // The host the mapped port is published on: localhost on a workstation, the Docker daemon's + // address inside a CI job container. The certificate has to name it. + String containerHost = DockerClientFactory.instance().dockerHostIpAddress(); + Path certificates = + SelfSignedServerCertificate.writeTo(Files.createTempDirectory("minio-tls"), containerHost); trustStoreBefore = SelfSignedServerCertificate.trustForThisJvm(certificates); minio = new GenericContainer<>(QualificationImages.minio()) @@ -90,7 +95,12 @@ class MinioS3ManagedObjectProviderContractTest extends ObjectStorageProviderCont .retryBaseDelay(Duration.ofMillis(10)) .retryMaximumBackoff(Duration.ofMillis(20)) .shutdownGrace(Duration.ofSeconds(2)) - .endpointOverride(URI.create("https://localhost:" + minio.getMappedPort(9000))) + .endpointOverride( + URI.create( + "https://" + + endpointHost(containerHost) + + ":" + + minio.getMappedPort(9000))) .pathStyleAccess(true) .staticCredentials(accessKey, secretKey) .build()); @@ -138,4 +148,9 @@ class MinioS3ManagedObjectProviderContractTest extends ObjectStorageProviderCont protected ObjectStorageProvider provider() { return provider; } + + // An IPv6 literal needs brackets in a URI authority. + private static String endpointHost(String containerHost) { + return containerHost.contains(":") ? "[" + containerHost + "]" : containerHost; + } } diff --git a/src/adapter/outbound/objectstorage/src/integrationTest/java/dev/caskeleton/adapter/outbound/objectstorage/s3/SelfSignedServerCertificate.java b/src/adapter/outbound/objectstorage/src/integrationTest/java/dev/caskeleton/adapter/outbound/objectstorage/s3/SelfSignedServerCertificate.java index 35624b4b..c02a22fb 100644 --- a/src/adapter/outbound/objectstorage/src/integrationTest/java/dev/caskeleton/adapter/outbound/objectstorage/s3/SelfSignedServerCertificate.java +++ b/src/adapter/outbound/objectstorage/src/integrationTest/java/dev/caskeleton/adapter/outbound/objectstorage/s3/SelfSignedServerCertificate.java @@ -11,10 +11,14 @@ import java.util.UUID; import java.util.concurrent.TimeUnit; /** - * A throwaway localhost server certificate for one lane run, made with the running JDK's keytool so - * no key material is committed. MinIO reads {@code public.crt} and {@code private.key} (PKCS#8 PEM) - * from its certs directory; the JVM trusts the same certificate through its default trust store + * A throwaway server certificate for one lane run, made with the running JDK's keytool so no key + * material is committed. MinIO reads {@code public.crt} and {@code private.key} (PKCS#8 PEM) from + * its certs directory; the JVM trusts the same certificate through its default trust store * properties, which the SDK's Netty client reads. + * + *

The certificate names localhost and the host the test reaches the container on. They differ + * when the tests run inside a CI job container: there the Docker daemon is another host, and {@code + * localhost} is the job container itself. */ final class SelfSignedServerCertificate { @@ -23,7 +27,7 @@ final class SelfSignedServerCertificate { private SelfSignedServerCertificate() {} - static Path writeTo(Path directory) throws Exception { + static Path writeTo(Path directory, String containerHost) throws Exception { String password = password(directory); Path keytool = Path.of(System.getProperty("java.home"), "bin", "keytool"); Process process = @@ -44,7 +48,7 @@ final class SelfSignedServerCertificate { "-dname", "CN=localhost", "-ext", - "SAN=dns:localhost,ip:127.0.0.1", + subjectAlternativeNames(containerHost), "-storetype", "PKCS12", "-keystore", @@ -74,6 +78,15 @@ final class SelfSignedServerCertificate { return directory; } + private static String subjectAlternativeNames(String containerHost) { + String names = "SAN=dns:localhost,ip:127.0.0.1"; + if (containerHost.equals("localhost") || containerHost.equals("127.0.0.1")) { + return names; + } + boolean ipLiteral = containerHost.contains(":") || containerHost.matches("[0-9.]+"); + return names + (ipLiteral ? ",ip:" : ",dns:") + containerHost; + } + /** Points the JVM default trust store at the certificate; the returned action restores it. */ static Runnable trustForThisJvm(Path directory) throws Exception { String[] names = {