JAMES-2597 Implement DockerLdapSingleton
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/bf8c0b84 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/bf8c0b84 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/bf8c0b84 Branch: refs/heads/master Commit: bf8c0b84b43e0cb351cab6e6d51c95cc655de4ae Parents: 93a9124 Author: datph <[email protected]> Authored: Wed Nov 21 15:09:15 2018 +0700 Committer: Benoit Tellier <[email protected]> Committed: Mon Nov 26 16:41:05 2018 +0700 ---------------------------------------------------------------------- .../james/CassandraLdapJamesServerTest.java | 6 +- .../james/CassandraLdapJmapJamesServerTest.java | 2 +- .../java/org/apache/james/DockerLdapRule.java | 72 +++++++++++++++++++ .../org/apache/james/LdapTestExtension.java | 52 ++++++++++++++ .../org/apache/james/LdapTestExtention.java | 73 -------------------- .../guice/cassandra-rabbitmq-ldap-guice/pom.xml | 4 +- ...assandraRabbitMQLdapJmapJamesServerTest.java | 7 +- server/container/guice/pom.xml | 7 -- .../james/user/ldap/DockerLdapSingleton.java | 36 ++++++++++ .../ldap/ReadOnlyUsersLDAPRepositoryTest.java | 10 +-- 10 files changed, 175 insertions(+), 94 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/bf8c0b84/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJamesServerTest.java ---------------------------------------------------------------------- diff --git a/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJamesServerTest.java b/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJamesServerTest.java index 8a0b9e1..61f11c6 100644 --- a/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJamesServerTest.java +++ b/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJamesServerTest.java @@ -19,6 +19,8 @@ package org.apache.james; +import static org.apache.james.user.ldap.DockerLdapSingleton.JAMES_USER; +import static org.apache.james.user.ldap.DockerLdapSingleton.PASSWORD; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Duration.ONE_HUNDRED_MILLISECONDS; @@ -38,8 +40,6 @@ import org.junit.jupiter.api.extension.RegisterExtension; class CassandraLdapJamesServerTest implements JamesServerContract { private static final int LIMIT_TO_10_MESSAGES = 10; - private static final String JAMES_USER = "james-user"; - private static final String PASSWORD = "secret"; private static Duration slowPacedPollInterval = ONE_HUNDRED_MILLISECONDS; private static ConditionFactory calmlyAwait = Awaitility.with() .pollInterval(slowPacedPollInterval) @@ -57,7 +57,7 @@ class CassandraLdapJamesServerTest implements JamesServerContract { static JamesServerExtension testExtension = new JamesServerExtensionBuilder() .extension(new EmbeddedElasticSearchExtension()) .extension(new CassandraExtension()) - .extension(new LdapTestExtention()) + .extension(new LdapTestExtension()) .server(configuration -> GuiceJamesServer.forConfiguration(configuration) .combineWith(CassandraLdapJamesServerMain.MODULES) .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES)) http://git-wip-us.apache.org/repos/asf/james-project/blob/bf8c0b84/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJmapJamesServerTest.java ---------------------------------------------------------------------- diff --git a/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJmapJamesServerTest.java b/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJmapJamesServerTest.java index 16476e9..853603a 100644 --- a/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJmapJamesServerTest.java +++ b/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJmapJamesServerTest.java @@ -29,7 +29,7 @@ class CassandraLdapJmapJamesServerTest implements JmapJamesServerContract { static JamesServerExtension testExtension = new JamesServerExtensionBuilder() .extension(new EmbeddedElasticSearchExtension()) .extension(new CassandraExtension()) - .extension(new LdapTestExtention()) + .extension(new LdapTestExtension()) .server(configuration -> GuiceJamesServer.forConfiguration(configuration) .combineWith(CassandraLdapJamesServerMain.MODULES) .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES)) http://git-wip-us.apache.org/repos/asf/james-project/blob/bf8c0b84/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/DockerLdapRule.java ---------------------------------------------------------------------- diff --git a/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/DockerLdapRule.java b/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/DockerLdapRule.java new file mode 100644 index 0000000..b8a36e3 --- /dev/null +++ b/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/DockerLdapRule.java @@ -0,0 +1,72 @@ +/**************************************************************** + * 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; + +import org.apache.commons.configuration.ConfigurationException; +import org.apache.james.user.ldap.DockerLdapSingleton; +import org.apache.james.user.ldap.LdapRepositoryConfiguration; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; + +import com.google.inject.Module; + +public class DockerLdapRule implements GuiceModuleTestRule { + + @Override + public Module getModule() { + return binder -> binder.bind(LdapRepositoryConfiguration.class) + .toInstance(computeConfiguration(DockerLdapSingleton.ldapContainer.getLdapHost())); + } + + @Override + public void await() { + } + + @Override + public Statement apply(Statement statement, Description description) { + return statement; + } + + private LdapRepositoryConfiguration computeConfiguration(String ldapIp) { + try { + return LdapRepositoryConfiguration.builder() + .ldapHost(ldapIp) + .principal("cn=admin,dc=james,dc=org") + .credentials("mysecretpassword") + .userBase("ou=People,dc=james,dc=org") + .userIdAttribute("uid") + .userObjectClass("inetOrgPerson") + .maxRetries(4) + .retryStartInterval(0) + .retryMaxInterval(8) + .scale(1000) + .build(); + } catch (ConfigurationException e) { + throw new RuntimeException(e); + } + } + + public void start() { + DockerLdapSingleton.ldapContainer.start(); + } + + public void stop() { + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/bf8c0b84/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/LdapTestExtension.java ---------------------------------------------------------------------- diff --git a/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/LdapTestExtension.java b/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/LdapTestExtension.java new file mode 100644 index 0000000..8ac99fc --- /dev/null +++ b/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/LdapTestExtension.java @@ -0,0 +1,52 @@ +/**************************************************************** + * 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; + +import org.junit.jupiter.api.extension.ExtensionContext; + +import com.google.inject.Module; + +public class LdapTestExtension implements GuiceModuleTestExtension { + + private DockerLdapRule ldapRule; + + LdapTestExtension() { + this(new DockerLdapRule()); + } + + LdapTestExtension(DockerLdapRule ldapRule) { + this.ldapRule = ldapRule; + } + + @Override + public void beforeAll(ExtensionContext extensionContext) { + ldapRule.start(); + } + + @Override + public void afterAll(ExtensionContext extensionContext) { + ldapRule.stop(); + } + + @Override + public Module getModule() { + return ldapRule.getModule(); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/bf8c0b84/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/LdapTestExtention.java ---------------------------------------------------------------------- diff --git a/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/LdapTestExtention.java b/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/LdapTestExtention.java deleted file mode 100644 index a0aaea5..0000000 --- a/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/LdapTestExtention.java +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************** - * 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; - -import org.apache.commons.configuration.ConfigurationException; -import org.apache.james.user.ldap.LdapGenericContainer; -import org.apache.james.user.ldap.LdapRepositoryConfiguration; -import org.junit.jupiter.api.extension.ExtensionContext; - -import com.google.inject.Module; - -public class LdapTestExtention implements GuiceModuleTestExtension { - private static final String DOMAIN = "james.org"; - private static final String ADMIN_PASSWORD = "mysecretpassword"; - - private LdapGenericContainer ldapContainer; - - @Override - public void beforeAll(ExtensionContext extensionContext) { - ldapContainer = LdapGenericContainer.builder() - .domain(DOMAIN) - .password(ADMIN_PASSWORD) - .build(); - ldapContainer.start(); - } - - @Override - public void afterAll(ExtensionContext extensionContext) { - ldapContainer.stop(); - } - - @Override - public Module getModule() { - return binder -> binder.bind(LdapRepositoryConfiguration.class) - .toInstance(computeConfiguration(ldapContainer.getLdapHost())); - } - - private LdapRepositoryConfiguration computeConfiguration(String ldapIp) { - try { - return LdapRepositoryConfiguration.builder() - .ldapHost(ldapIp) - .principal("cn=admin,dc=james,dc=org") - .credentials("mysecretpassword") - .userBase("ou=People,dc=james,dc=org") - .userIdAttribute("uid") - .userObjectClass("inetOrgPerson") - .maxRetries(4) - .retryStartInterval(0) - .retryMaxInterval(8) - .scale(1000) - .build(); - } catch (ConfigurationException e) { - throw new RuntimeException(e); - } - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/bf8c0b84/server/container/guice/cassandra-rabbitmq-ldap-guice/pom.xml ---------------------------------------------------------------------- diff --git a/server/container/guice/cassandra-rabbitmq-ldap-guice/pom.xml b/server/container/guice/cassandra-rabbitmq-ldap-guice/pom.xml index 6ba6d33..f7c713f 100644 --- a/server/container/guice/cassandra-rabbitmq-ldap-guice/pom.xml +++ b/server/container/guice/cassandra-rabbitmq-ldap-guice/pom.xml @@ -93,6 +93,7 @@ <groupId>org.apache.james</groupId> <artifactId>james-server-data-ldap-integration-testing</artifactId> <type>test-jar</type> + <version>${project.version}</version> <scope>test</scope> </dependency> <dependency> @@ -118,8 +119,7 @@ </dependency> <dependency> <groupId>org.junit.jupiter</groupId> - <artifactId>junit-jupiter-api</artifactId> - <version>${junit.jupiter.version}</version> + <artifactId>junit-jupiter-engine</artifactId> <scope>test</scope> </dependency> </dependencies> http://git-wip-us.apache.org/repos/asf/james-project/blob/bf8c0b84/server/container/guice/cassandra-rabbitmq-ldap-guice/src/test/java/org/apache/james/CassandraRabbitMQLdapJmapJamesServerTest.java ---------------------------------------------------------------------- diff --git a/server/container/guice/cassandra-rabbitmq-ldap-guice/src/test/java/org/apache/james/CassandraRabbitMQLdapJmapJamesServerTest.java b/server/container/guice/cassandra-rabbitmq-ldap-guice/src/test/java/org/apache/james/CassandraRabbitMQLdapJmapJamesServerTest.java index e79f136..62284a5 100644 --- a/server/container/guice/cassandra-rabbitmq-ldap-guice/src/test/java/org/apache/james/CassandraRabbitMQLdapJmapJamesServerTest.java +++ b/server/container/guice/cassandra-rabbitmq-ldap-guice/src/test/java/org/apache/james/CassandraRabbitMQLdapJmapJamesServerTest.java @@ -85,7 +85,8 @@ class CassandraRabbitMQLdapJmapJamesServerTest { } } - interface ContractSuite extends JmapJamesServerContract, MailsShouldBeWellReceived, UserFromLdapShouldLogin {} + interface ContractSuite extends JmapJamesServerContract, MailsShouldBeWellReceived, + UserFromLdapShouldLogin, JamesServerContract {} @Nested @TestInstance(TestInstance.Lifecycle.PER_CLASS) @@ -95,7 +96,7 @@ class CassandraRabbitMQLdapJmapJamesServerTest { .extension(new EmbeddedElasticSearchExtension()) .extension(new CassandraExtension()) .extension(new RabbitMQExtension()) - .extension(new LdapTestExtention()) + .extension(new LdapTestExtension()) .extension(new SwiftBlobStoreExtension()) .server(configuration -> GuiceJamesServer.forConfiguration(configuration) .combineWith(CassandraRabbitMQLdapJamesServerMain.MODULES) @@ -114,7 +115,7 @@ class CassandraRabbitMQLdapJmapJamesServerTest { .extension(new EmbeddedElasticSearchExtension()) .extension(new CassandraExtension()) .extension(new RabbitMQExtension()) - .extension(new LdapTestExtention()) + .extension(new LdapTestExtension()) .server(configuration -> GuiceJamesServer.forConfiguration(configuration) .combineWith(CassandraRabbitMQLdapJamesServerMain.MODULES) .overrideWith(binder -> binder.bind(BlobStoreChoosingConfiguration.class) http://git-wip-us.apache.org/repos/asf/james-project/blob/bf8c0b84/server/container/guice/pom.xml ---------------------------------------------------------------------- diff --git a/server/container/guice/pom.xml b/server/container/guice/pom.xml index fbd2fda..b4e4e3e 100644 --- a/server/container/guice/pom.xml +++ b/server/container/guice/pom.xml @@ -84,13 +84,6 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> - <artifactId>james-server-data-ldap-integration-testing</artifactId> - <version>${project.version}</version> - <type>test-jar</type> - <scope>test</scope> - </dependency> - <dependency> - <groupId>${james.groupId}</groupId> <artifactId>james-server-guice-configuration</artifactId> <version>${project.version}</version> </dependency> http://git-wip-us.apache.org/repos/asf/james-project/blob/bf8c0b84/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/DockerLdapSingleton.java ---------------------------------------------------------------------- diff --git a/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/DockerLdapSingleton.java b/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/DockerLdapSingleton.java new file mode 100644 index 0000000..ca8fdaa --- /dev/null +++ b/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/DockerLdapSingleton.java @@ -0,0 +1,36 @@ +/**************************************************************** + * 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.user.ldap; + +public class DockerLdapSingleton { + public static final String JAMES_USER = "james-user"; + public static final String PASSWORD = "secret"; + public static final String DOMAIN = "james.org"; + public static final String ADMIN_PASSWORD = "mysecretpassword"; + + public static final LdapGenericContainer ldapContainer = LdapGenericContainer.builder() + .domain(DOMAIN) + .password(ADMIN_PASSWORD) + .build(); + + static { + ldapContainer.start(); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/bf8c0b84/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryTest.java ---------------------------------------------------------------------- diff --git a/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryTest.java b/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryTest.java index 2fdbe54..25d4622 100644 --- a/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryTest.java +++ b/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryTest.java @@ -18,6 +18,10 @@ ****************************************************************/ package org.apache.james.user.ldap; +import static org.apache.james.user.ldap.DockerLdapSingleton.ADMIN_PASSWORD; +import static org.apache.james.user.ldap.DockerLdapSingleton.DOMAIN; +import static org.apache.james.user.ldap.DockerLdapSingleton.JAMES_USER; +import static org.apache.james.user.ldap.DockerLdapSingleton.PASSWORD; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -34,12 +38,8 @@ import org.slf4j.LoggerFactory; public class ReadOnlyUsersLDAPRepositoryTest { private static final Logger LOGGER = LoggerFactory.getLogger(ReadOnlyUsersLDAPRepositoryTest.class); - private static final String DOMAIN = "james.org"; - private static final String ADMIN_PASSWORD = "mysecretpassword"; - private static final String JAMES_USER = "james-user"; - private static final String JAMES_USER_MAIL = "james-user" + "@" + DOMAIN; + private static final String JAMES_USER_MAIL = JAMES_USER + "@" + DOMAIN; private static final String UNKNOWN = "unknown"; - private static final String PASSWORD = "secret"; private static final String BAD_PASSWORD = "badpassword"; @ClassRule --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
