This is an automated email from the ASF dual-hosted git repository. aduprat pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit ec4717b1e730948b7a8e249097add21e2dbadc1c Author: Gautier DI FOLCO <gdifo...@linagora.com> AuthorDate: Tue Mar 12 11:22:18 2019 +0100 JAMES-2671 Add AwsS3 Extension --- .../james/CassandraRabbitMQJamesServerTest.java | 41 ++++++++++++++- .../james/modules/AwsS3BlobStoreExtension.java | 59 ++++++++++++++++++++++ 2 files changed, 99 insertions(+), 1 deletion(-) diff --git a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQJamesServerTest.java b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQJamesServerTest.java index ae2a724..d683171 100644 --- a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQJamesServerTest.java +++ b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQJamesServerTest.java @@ -27,10 +27,12 @@ import org.apache.james.blob.objectstorage.AESPayloadCodec; import org.apache.james.blob.objectstorage.DefaultPayloadCodec; import org.apache.james.blob.objectstorage.PayloadCodec; import org.apache.james.core.Domain; +import org.apache.james.modules.AwsS3BlobStoreExtension; import org.apache.james.modules.RabbitMQExtension; import org.apache.james.modules.SwiftBlobStoreExtension; import org.apache.james.modules.TestJMAPServerModule; import org.apache.james.modules.objectstorage.PayloadCodecFactory; +import org.apache.james.modules.objectstorage.aws.s3.DockerAwsS3TestRule; import org.apache.james.modules.objectstorage.swift.DockerSwiftTestRule; import org.apache.james.modules.protocols.ImapGuiceProbe; import org.apache.james.modules.protocols.SmtpGuiceProbe; @@ -130,11 +132,48 @@ class CassandraRabbitMQJamesServerTest { @Nested @TestInstance(Lifecycle.PER_METHOD) - class WithoutSwift implements ContractSuite { + class WithoutSwiftOrAwsS3 implements ContractSuite { @RegisterExtension JamesServerExtension testExtension = baseExtensionBuilder().build(); } + @Nested + @TestInstance(Lifecycle.PER_METHOD) + class WithEncryptedAwsS3 implements ContractSuite { + @RegisterExtension + JamesServerExtension testExtension = baseExtensionBuilder() + .extension(new AwsS3BlobStoreExtension(PayloadCodecFactory.AES256)) + .server(CONFIGURATION_BUILDER) + .build(); + + @Test + void encryptedPayloadShouldBeConfiguredWhenProvidingEncryptedPayloadConfiguration(GuiceJamesServer jamesServer) { + PayloadCodec payloadCodec = jamesServer.getProbe(DockerAwsS3TestRule.TestAwsS3BlobStoreProbe.class) + .getAwsS3PayloadCodec(); + + assertThat(payloadCodec) + .isInstanceOf(AESPayloadCodec.class); + } + } + + @Nested + @TestInstance(Lifecycle.PER_METHOD) + class WithDefaultAwsS3 implements ContractSuite { + @RegisterExtension + JamesServerExtension testExtension = baseExtensionBuilder() + .extension(new AwsS3BlobStoreExtension()) + .build(); + + @Test + void defaultPayloadShouldBeByDefault(GuiceJamesServer jamesServer) { + PayloadCodec payloadCodec = jamesServer.getProbe(DockerAwsS3TestRule.TestAwsS3BlobStoreProbe.class) + .getAwsS3PayloadCodec(); + + assertThat(payloadCodec) + .isInstanceOf(DefaultPayloadCodec.class); + } + } + private static JamesServerBuilder baseExtensionBuilder() { return new JamesServerBuilder() .extension(new EmbeddedElasticSearchExtension()) diff --git a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/AwsS3BlobStoreExtension.java b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/AwsS3BlobStoreExtension.java new file mode 100644 index 0000000..44cda7c --- /dev/null +++ b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/AwsS3BlobStoreExtension.java @@ -0,0 +1,59 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.modules; + +import org.apache.james.GuiceModuleTestExtension; +import org.apache.james.modules.blobstore.BlobStoreChoosingConfiguration; +import org.apache.james.modules.objectstorage.PayloadCodecFactory; +import org.apache.james.modules.objectstorage.aws.s3.DockerAwsS3TestRule; +import org.junit.jupiter.api.extension.ExtensionContext; + +import com.google.inject.Module; +import com.google.inject.util.Modules; + +public class AwsS3BlobStoreExtension implements GuiceModuleTestExtension { + + private final DockerAwsS3TestRule swiftRule; + + public AwsS3BlobStoreExtension() { + this.swiftRule = new DockerAwsS3TestRule(); + } + + public AwsS3BlobStoreExtension(PayloadCodecFactory payloadCodecFactory) { + this.swiftRule = new DockerAwsS3TestRule(payloadCodecFactory); + } + + @Override + public void beforeAll(ExtensionContext extensionContext) { + swiftRule.start(); + } + + @Override + public void afterAll(ExtensionContext extensionContext) { + swiftRule.stop(); + } + + @Override + public Module getModule() { + return Modules.override(swiftRule.getModule()) + .with(binder -> binder.bind(BlobStoreChoosingConfiguration.class) + .toInstance(BlobStoreChoosingConfiguration.objectStorage())); + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org