diff --git a/src/main/java/org/testcontainers/containers/CephContainer.java b/src/main/java/org/testcontainers/containers/CephContainer.java index 81cef6d..963fa52 100644 --- a/src/main/java/org/testcontainers/containers/CephContainer.java +++ b/src/main/java/org/testcontainers/containers/CephContainer.java @@ -58,6 +58,12 @@ public CephContainer(final String dockerImageName) { this(DockerImageName.parse(dockerImageName)); } + + /** + * Constructor + * @param dockerImageName + * Sets default Ulimit so the container isn't limited by docker default security (it would take 5 minutes to load) + */ public CephContainer(final DockerImageName dockerImageName) { super(dockerImageName); dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME); @@ -67,6 +73,11 @@ public CephContainer(final DockerImageName dockerImageName) { .withUlimits(DEFAULT_ULIMITS)); } + /** + * @Override default configure of generic container + * set necessary env variables for Ceph + * Set wait strategy to wait for log if not set + */ @Override public void configure() { addExposedPorts(CEPH_MON_DEFAULT_PORT, CEPH_RGW_DEFAULT_PORT); @@ -102,15 +113,15 @@ public void configure() { } public CephContainer withSslDisabled() { - return super.withCreateContainerCmdModifier((cmd) -> { - cmd.withEntrypoint( - "bash", - "-c", - "sed -i '/^rgw frontends = .*/a rgw verify ssl = false\\\n" + - "rgw crypt require ssl = false' /opt/ceph-container/bin/demo;\n" + - "/opt/ceph-container/bin/demo;" - ); - }); + return super.withCreateContainerCmdModifier(cmd -> + cmd.withEntrypoint( + "bash", + "-c", + "sed -i '/^rgw frontends = .*/a rgw verify ssl = false\\\n" + + "rgw crypt require ssl = false' /opt/ceph-container/bin/demo;\n" + + "/opt/ceph-container/bin/demo;" + ) + ); } public CephContainer withCephAccessKey(String cephAccessKey) { diff --git a/src/test/java/org/testcontainers/containers/CephContainerTest.java b/src/test/java/org/testcontainers/containers/CephContainerTest.java index 23988fb..c4f892c 100644 --- a/src/test/java/org/testcontainers/containers/CephContainerTest.java +++ b/src/test/java/org/testcontainers/containers/CephContainerTest.java @@ -38,21 +38,19 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -public class CephContainerTest { +class CephContainerTest { @Test - public void testBasicUsage() throws Exception { + void testBasicUsage() throws Exception { try ( - // minioContainer { - CephContainer container = new CephContainer() - // } + CephContainer container = new CephContainer() ) { container.start(); // We should not modify demo script by default assertThat(getDemoScriptFromContainer(container)).doesNotContain( "rgw frontends = ${RGW_FRONTEND}\n" + - "rgw verify ssl = false\n" + - "rgw crypt require ssl = false" + "rgw verify ssl = false\n" + + "rgw crypt require ssl = false" ); assertThat(container.getCephAccessKey()).isEqualTo("demo"); assertThat(container.getCephSecretKey()).isSameAs("b36361c4-1589-42f7-a369-d9dafb926d55"); @@ -63,9 +61,9 @@ public void testBasicUsage() throws Exception { HeadBucketResponse headBucketResponse = s3client.headBucket(HeadBucketRequest.builder().bucket("demo").build()); assertThat(headBucketResponse.sdkHttpResponse().isSuccessful()) - .isTrue(); + .isTrue(); assertThat(headBucketResponse.sdkHttpResponse().headers().get("X-RGW-Quota-Max-Buckets").get(0)) - .isEqualTo("1000"); + .isEqualTo("1000"); final String key = "my-objectname"; @@ -76,41 +74,40 @@ public void testBasicUsage() throws Exception { assertThat(putObjectResponse.expiration()).isNull(); ResponseInputStream - responseInputStream = s3client.getObject(request -> request.bucket("demo").key(key)); + responseInputStream = s3client.getObject(request -> request.bucket("demo").key(key)); assertThat(responseInputStream).hasContent("This is a file"); - ListObjectsV2Response objets = s3client.listObjectsV2((builder) -> builder.bucket("demo")); - assertThat(objets.contents().size()).isEqualTo(1); + ListObjectsV2Response objets = s3client.listObjectsV2(builder -> builder.bucket("demo")); + assertThat(objets.contents()).hasSize(1); assertThat(objets.contents().get(0).key()).isEqualTo(key); - assertThatThrownBy(() -> { - s3client.putObject( - getSSECPutObjectRequest("demo", key), - RequestBody.fromFile(getTestFile()) - ); - }) + assertThatThrownBy(() -> + s3client.putObject( + getSSECPutObjectRequest("demo", key), + RequestBody.fromFile(getTestFile()) + ) + ) .isInstanceOf(software.amazon.awssdk.services.s3.model.S3Exception.class) .hasMessageContaining("Service: S3, Status Code: 400, Request ID: "); } } @Test - public void testOverrides() throws Exception { + void testOverrides() throws Exception { try ( - // cephOverrides { - CephContainer container = new CephContainer("quay.io/ceph/demo:latest") - .withCephAccessKey("testuser123") - .withCephSecretKey("testpassword123") - .withCephBucket("testbucket123") - .withSslDisabled() - // } + CephContainer container = new CephContainer("quay.io/ceph/demo:latest") + .withCephAccessKey("testuser123") + .withCephSecretKey("testpassword123") + .withCephBucket("testbucket123") + .withSslDisabled() + ) { container.start(); // we should have modified the demo script assertThat(getDemoScriptFromContainer(container)).contains( "rgw frontends = ${RGW_FRONTEND}\n" + - "rgw verify ssl = false\n" + - "rgw crypt require ssl = false" + "rgw verify ssl = false\n" + + "rgw crypt require ssl = false" ); assertThat(container.getWaitStrategy()).isInstanceOf(LogMessageWaitStrategy.class); assertThat(container.getCephAccessKey()).isEqualTo("testuser123"); @@ -132,18 +129,16 @@ public void testOverrides() throws Exception { } @Test - public void testSpecificDaemonImage() throws URISyntaxException { + void testSpecificDaemonImage() throws URISyntaxException { DockerImageName daemonImage = DockerImageName.parse("quay.io/ceph/daemon:v7.0.3-stable-7.0-quincy-centos-stream8-x86_64") .asCompatibleSubstituteFor("quay.io/ceph/demo"); try ( - // cephOverrides { CephContainer container = new CephContainer(daemonImage) .withCephAccessKey("testuser123") .withCephSecretKey("testpassword123") .withCephBucket("testbucket123") .withCommand("demo") - // } ) { container.start(); assertThat(container.getWaitStrategy()).isInstanceOf(LogMessageWaitStrategy.class); @@ -155,6 +150,10 @@ public void testSpecificDaemonImage() throws URISyntaxException { } } + /** + * Test that startupStrategy override works + * Keep validating issue #176 + */ @Test void testOverrideStartupStrategy() { DockerImageName daemonImage = @@ -165,7 +164,7 @@ void testOverrideStartupStrategy() { .withCephAccessKey("testuser123") .withCephSecretKey("testpassword123") .withCephBucket("testbucket123") - .withCommand("demo"); + .withCommand("demo") ) { container.setWaitStrategy(Wait.forListeningPort()); container.start(); @@ -174,6 +173,10 @@ void testOverrideStartupStrategy() { } } + /** + * Test that WaitingFor override works + * Keep validating issue #176 + */ @Test void testOverrideWaitingFor() { DockerImageName daemonImage = @@ -184,7 +187,7 @@ void testOverrideWaitingFor() { .withCephAccessKey("testuser123") .withCephSecretKey("testpassword123") .withCephBucket("testbucket123") - .withCommand("demo"); + .withCommand("demo") ) { container.waitingFor(Wait.forListeningPort()); container.start(); @@ -192,7 +195,6 @@ void testOverrideWaitingFor() { assertThat(container.getWaitStrategy()).isInstanceOf(HostPortWaitStrategy.class); } } - // configuringClient { private static S3Client getS3client(CephContainer container) throws URISyntaxException { final AwsBasicCredentials credentials = AwsBasicCredentials.create( @@ -209,12 +211,13 @@ private static S3Client getS3client(CephContainer container) throws URISyntaxExc .build()) .build(); } - // } + private static String getDemoScriptFromContainer(CephContainer container) throws IOException { container.copyFileFromContainer("/opt/ceph-container/bin/demo", "demo-script"); return new String(Files.readAllBytes(Paths.get("demo-script"))); } + @NotNull private File getTestFile() throws URISyntaxException { return Paths.get(Objects.requireNonNull(this.getClass().getResource("/object_to_upload.txt")).toURI()).toFile(); @@ -228,7 +231,7 @@ private static SecretKey getPasswordBasedKey(char[] password) throws NoSuchAlgor return SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256").generateSecret(pbeKeySpec); } - private static PutObjectRequest getSSECPutObjectRequest(String bucket, String key) throws NoSuchAlgorithmException, InvalidKeySpecException, URISyntaxException { + private static PutObjectRequest getSSECPutObjectRequest(String bucket, String key) throws NoSuchAlgorithmException, InvalidKeySpecException { SecretKey secretKey = getPasswordBasedKey("testtesttesttesttesttest123".toCharArray()); byte[] customerKeyBytes = secretKey.getEncoded(); String customerKeyMD5;