You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2018/12/03 01:57:46 UTC

[1/5] james-project git commit: JAMES-2615 Merge data-ldap and data-ldap-integration-test

Repository: james-project
Updated Branches:
  refs/heads/master b076dab85 -> ce8cf479a


JAMES-2615 Merge data-ldap and data-ldap-integration-test


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/ffded847
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/ffded847
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/ffded847

Branch: refs/heads/master
Commit: ffded8479d75afe29abacc2bb66b5b0eeebd81b1
Parents: b076dab
Author: datph <dp...@linagora.com>
Authored: Thu Nov 29 15:37:46 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Mon Dec 3 08:55:52 2018 +0700

----------------------------------------------------------------------
 .../james/user/ldap/DockerLdapSingleton.java    |  36 ----
 .../james/user/ldap/LdapGenericContainer.java   | 114 ------------
 .../ldap/ReadOnlyUsersLDAPRepositoryTest.java   | 180 -------------------
 .../src/test/resources/ldif-files/Dockerfile    |   3 -
 .../src/test/resources/ldif-files/populate.ldif |  12 --
 .../src/test/resources/logback-test.xml         |  22 ---
 server/data/data-ldap/pom.xml                   |  10 ++
 .../james/user/ldap/DockerLdapSingleton.java    |  36 ++++
 .../james/user/ldap/LdapGenericContainer.java   | 114 ++++++++++++
 .../ldap/ReadOnlyUsersLDAPRepositoryTest.java   | 134 +++++++++++++-
 .../src/test/resources/ldif-files/Dockerfile    |   3 +
 .../src/test/resources/ldif-files/populate.ldif |  12 ++
 .../src/test/resources/logback-test.xml         |  22 +++
 server/pom.xml                                  |   1 -
 14 files changed, 327 insertions(+), 372 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/ffded847/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
deleted file mode 100644
index ca8fdaa..0000000
--- a/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/DockerLdapSingleton.java
+++ /dev/null
@@ -1,36 +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.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/ffded847/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/LdapGenericContainer.java
----------------------------------------------------------------------
diff --git a/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/LdapGenericContainer.java b/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/LdapGenericContainer.java
deleted file mode 100644
index 40ee62d..0000000
--- a/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/LdapGenericContainer.java
+++ /dev/null
@@ -1,114 +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.user.ldap;
-
-import org.apache.james.util.docker.RateLimiters;
-import org.apache.james.util.docker.SwarmGenericContainer;
-import org.junit.rules.ExternalResource;
-import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy;
-import org.testcontainers.images.builder.ImageFromDockerfile;
-
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
-
-public class LdapGenericContainer extends ExternalResource {
-
-    public static final int DEFAULT_LDAP_PORT = 389;
-
-    public static Builder builder() {
-        return new Builder();
-    }
-
-    public static class Builder {
-
-        private String domain;
-        private String password;
-
-        private Builder() {
-        }
-
-        public Builder domain(String domain) {
-            this.domain = domain;
-            return this;
-        }
-
-        public Builder password(String password) {
-            this.password = password;
-            return this;
-        }
-
-        public LdapGenericContainer build() {
-            Preconditions.checkState(!Strings.isNullOrEmpty(domain), "'domain' is mandatory");
-            Preconditions.checkState(!Strings.isNullOrEmpty(password), "'password' is mandatory");
-            return new LdapGenericContainer(createContainer());
-        }
-
-        private SwarmGenericContainer createContainer() {
-            return new SwarmGenericContainer(
-                new ImageFromDockerfile()
-                    .withFileFromClasspath("populate.ldif", "ldif-files/populate.ldif")
-                    .withFileFromClasspath("Dockerfile", "ldif-files/Dockerfile"))
-                .withAffinityToContainer()
-                .withEnv("SLAPD_DOMAIN", domain)
-                .withEnv("SLAPD_PASSWORD", password)
-                .withEnv("SLAPD_CONFIG_PASSWORD", password)
-                .withExposedPorts(LdapGenericContainer.DEFAULT_LDAP_PORT)
-                .waitingFor(new HostPortWaitStrategy().withRateLimiter(RateLimiters.TWENTIES_PER_SECOND));
-        }
-    }
-
-    private final SwarmGenericContainer container;
-
-    private LdapGenericContainer(SwarmGenericContainer container) {
-        this.container = container;
-    }
-
-    @Override
-    protected void before() {
-        start();
-    }
-
-    @Override
-    protected void after() {
-        stop();
-    }
-
-    public void start() {
-        container.start();
-    }
-
-    public void stop() {
-        container.stop();
-    }
-
-    public void pause() {
-        container.pause();
-    }
-
-    public void unpause() {
-        container.unpause();
-    }
-
-    public String getLdapHost() {
-        return "ldap://" +
-                container.getContainerIp() +
-                ":" +
-                LdapGenericContainer.DEFAULT_LDAP_PORT;
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/ffded847/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
deleted file mode 100644
index 25d4622..0000000
--- a/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryTest.java
+++ /dev/null
@@ -1,180 +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.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;
-
-import org.apache.commons.configuration.HierarchicalConfiguration;
-import org.apache.commons.configuration.plist.PropertyListConfiguration;
-import org.apache.james.core.MailAddress;
-import org.apache.james.domainlist.api.DomainList;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class ReadOnlyUsersLDAPRepositoryTest {
-
-    private static final Logger LOGGER = LoggerFactory.getLogger(ReadOnlyUsersLDAPRepositoryTest.class);
-    private static final String JAMES_USER_MAIL = JAMES_USER + "@" + DOMAIN;
-    private static final String UNKNOWN = "unknown";
-    private static final String BAD_PASSWORD = "badpassword";
-
-    @ClassRule
-    public static LdapGenericContainer ldapContainer = LdapGenericContainer.builder()
-        .domain(DOMAIN)
-        .password(ADMIN_PASSWORD)
-        .build();
-
-    private ReadOnlyUsersLDAPRepository ldapRepository;
-    private DomainList domainList;
-
-    @Before
-    public void setup() {
-        domainList = mock(DomainList.class);
-    }
-
-    private void startUsersRepository(HierarchicalConfiguration ldapRepositoryConfiguration) throws Exception {
-        ldapRepository = new ReadOnlyUsersLDAPRepository(domainList);
-        ldapRepository.configure(ldapRepositoryConfiguration);
-        ldapRepository.init();
-    }
-
-    private HierarchicalConfiguration ldapRepositoryConfiguration() {
-        PropertyListConfiguration configuration = new PropertyListConfiguration();
-        configuration.addProperty("[@ldapHost]", ldapContainer.getLdapHost());
-        configuration.addProperty("[@principal]", "cn=admin\\,dc=james\\,dc=org");
-        configuration.addProperty("[@credentials]", ADMIN_PASSWORD);
-        configuration.addProperty("[@userBase]", "ou=People\\,dc=james\\,dc=org");
-        configuration.addProperty("[@userIdAttribute]", "uid");
-        configuration.addProperty("[@userObjectClass]", "inetOrgPerson");
-        configuration.addProperty("[@maxRetries]", "4");
-        configuration.addProperty("[@retryStartInterval]", "0");
-        configuration.addProperty("[@retryMaxInterval]", "8");
-        configuration.addProperty("[@retryIntervalScale]", "1000");
-        return configuration;
-    }
-
-    private HierarchicalConfiguration ldapRepositoryConfigurationWithVirtualHosting() {
-        PropertyListConfiguration configuration = new PropertyListConfiguration();
-        configuration.addProperty("[@ldapHost]", ldapContainer.getLdapHost());
-        configuration.addProperty("[@principal]", "cn=admin\\,dc=james\\,dc=org");
-        configuration.addProperty("[@credentials]", ADMIN_PASSWORD);
-        configuration.addProperty("[@userBase]", "ou=People\\,dc=james\\,dc=org");
-        configuration.addProperty("[@userIdAttribute]", "mail");
-        configuration.addProperty("[@userObjectClass]", "inetOrgPerson");
-        configuration.addProperty("[@maxRetries]", "4");
-        configuration.addProperty("[@retryStartInterval]", "0");
-        configuration.addProperty("[@retryMaxInterval]", "8");
-        configuration.addProperty("[@retryIntervalScale]", "1000");
-        configuration.addProperty("supportsVirtualHosting", true);
-        return configuration;
-    }
-
-    @Test
-    public void knownUserShouldBeAbleToLogInWhenPasswordIsCorrect() throws Exception {
-        startUsersRepository(ldapRepositoryConfiguration());
-        assertThat(ldapRepository.test(JAMES_USER, PASSWORD)).isTrue();
-    }
-
-    @Test
-    public void knownUserShouldNotBeAbleToLogInWhenPasswordIsNotCorrect() throws Exception {
-        startUsersRepository(ldapRepositoryConfiguration());
-        assertThat(ldapRepository.test(JAMES_USER, BAD_PASSWORD)).isFalse();
-    }
-
-    @Test
-    public void unknownUserShouldNotBeAbleToLogIn() throws Exception {
-        startUsersRepository(ldapRepositoryConfiguration());
-        assertThat(ldapRepository.test(UNKNOWN, BAD_PASSWORD)).isFalse();
-    }
-
-    @Test
-    public void unknownUserShouldNotBeAbleToLogInWhenPasswordIsCorrect() throws Exception {
-        startUsersRepository(ldapRepositoryConfiguration());
-        assertThat(ldapRepository.test(UNKNOWN, PASSWORD)).isFalse();
-    }
-
-    @Test
-    public void knownUserShouldBeAbleToLogInWhenPasswordIsCorrectWithVirtualHosting() throws Exception {
-        startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting());
-        assertThat(ldapRepository.test(JAMES_USER_MAIL, PASSWORD)).isTrue();
-    }
-
-    @Test
-    public void testShouldStillWorksAfterRestartingLDAP() throws Exception {
-        startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting());
-        ldapRepository.test(JAMES_USER_MAIL, PASSWORD);
-
-        ldapContainer.pause();
-        try {
-            ldapRepository.test(JAMES_USER_MAIL, PASSWORD);
-        } catch (Exception e) {
-            LOGGER.info("This exception is expected as we shut down the LDAP and forced its use", e);
-        }
-        ldapContainer.unpause();
-
-        assertThat(ldapRepository.test(JAMES_USER_MAIL, PASSWORD)).isTrue();
-    }
-
-
-    @Test
-    public void knownUserShouldNotBeAbleToLogInWhenPasswordIsNotCorrectWithVirtualHosting() throws Exception {
-        startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting());
-        assertThat(ldapRepository.test(JAMES_USER, BAD_PASSWORD)).isFalse();
-    }
-
-    @Test
-    public void unknownUserShouldNotBeAbleToLogInWithVirtualHosting() throws Exception {
-        startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting());
-        assertThat(ldapRepository.test(UNKNOWN, BAD_PASSWORD)).isFalse();
-    }
-
-    @Test
-    public void unknownUserShouldNotBeAbleToLogInWhenPasswordIsCorrectWithVirtualHosting() throws Exception {
-        startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting());
-        assertThat(ldapRepository.test(UNKNOWN, PASSWORD)).isFalse();
-    }
-
-    @Test
-    public void containsWithGetUserShouldBeTrue() throws Exception {
-        startUsersRepository(ldapRepositoryConfiguration());
-        assertThat(ldapRepository.contains(ldapRepository.getUser(new MailAddress(JAMES_USER_MAIL)))).isTrue();
-    }
-
-    @Test
-    public void containsWithGetUserShouldBeTrueWithVirtualHosting() throws Exception {
-        startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting());
-        assertThat(ldapRepository.contains(ldapRepository.getUser(new MailAddress(JAMES_USER_MAIL)))).isTrue();
-    }
-
-    @Test
-    public void specialCharacterInUserInputShouldBeSanitized() throws Exception {
-        String patternMatchingMultipleUsers = "j*";
-
-        startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting());
-        assertThat(ldapRepository.test(patternMatchingMultipleUsers, PASSWORD)).isFalse();
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/ffded847/server/data/data-ldap-integration-testing/src/test/resources/ldif-files/Dockerfile
----------------------------------------------------------------------
diff --git a/server/data/data-ldap-integration-testing/src/test/resources/ldif-files/Dockerfile b/server/data/data-ldap-integration-testing/src/test/resources/ldif-files/Dockerfile
deleted file mode 100644
index d889a35..0000000
--- a/server/data/data-ldap-integration-testing/src/test/resources/ldif-files/Dockerfile
+++ /dev/null
@@ -1,3 +0,0 @@
-FROM dinkel/openldap:latest
-
-COPY populate.ldif /etc/ldap/prepopulate/prepop.ldif

http://git-wip-us.apache.org/repos/asf/james-project/blob/ffded847/server/data/data-ldap-integration-testing/src/test/resources/ldif-files/populate.ldif
----------------------------------------------------------------------
diff --git a/server/data/data-ldap-integration-testing/src/test/resources/ldif-files/populate.ldif b/server/data/data-ldap-integration-testing/src/test/resources/ldif-files/populate.ldif
deleted file mode 100644
index 95f3391..0000000
--- a/server/data/data-ldap-integration-testing/src/test/resources/ldif-files/populate.ldif
+++ /dev/null
@@ -1,12 +0,0 @@
-dn: ou=people, dc=james,dc=org
-ou: people
-objectClass: organizationalUnit
-
-dn: uid=james-user, ou=people, dc=james,dc=org
-objectClass: inetOrgPerson
-uid: james-user
-cn: james-user
-sn: james-user
-mail: james-user@james.org
-userPassword: secret
-description: James user

http://git-wip-us.apache.org/repos/asf/james-project/blob/ffded847/server/data/data-ldap-integration-testing/src/test/resources/logback-test.xml
----------------------------------------------------------------------
diff --git a/server/data/data-ldap-integration-testing/src/test/resources/logback-test.xml b/server/data/data-ldap-integration-testing/src/test/resources/logback-test.xml
deleted file mode 100644
index ddbf62c..0000000
--- a/server/data/data-ldap-integration-testing/src/test/resources/logback-test.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<configuration>
-
-        <contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
-                <resetJUL>true</resetJUL>
-        </contextListener>
-
-        <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
-                <encoder>
-                        <pattern>%d{HH:mm:ss.SSS} [%-5level] %logger{15} - %msg%n%rEx</pattern>
-                        <immediateFlush>false</immediateFlush>
-                </encoder>
-        </appender>
-
-        <root level="WARN">
-                <appender-ref ref="CONSOLE" />
-        </root>
-
-        <logger name="org.testcontainers" level="WARN"/>
-        <logger name="org.apache.james" level="WARN"/>
-
-</configuration>

http://git-wip-us.apache.org/repos/asf/james-project/blob/ffded847/server/data/data-ldap/pom.xml
----------------------------------------------------------------------
diff --git a/server/data/data-ldap/pom.xml b/server/data/data-ldap/pom.xml
index 3c5ae38..4b72c98 100644
--- a/server/data/data-ldap/pom.xml
+++ b/server/data/data-ldap/pom.xml
@@ -88,6 +88,16 @@
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.testcontainers</groupId>
+            <artifactId>testcontainers</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.james</groupId>
+            <artifactId>james-server-testing</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>

http://git-wip-us.apache.org/repos/asf/james-project/blob/ffded847/server/data/data-ldap/src/test/java/org/apache/james/user/ldap/DockerLdapSingleton.java
----------------------------------------------------------------------
diff --git a/server/data/data-ldap/src/test/java/org/apache/james/user/ldap/DockerLdapSingleton.java b/server/data/data-ldap/src/test/java/org/apache/james/user/ldap/DockerLdapSingleton.java
new file mode 100644
index 0000000..ca8fdaa
--- /dev/null
+++ b/server/data/data-ldap/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/ffded847/server/data/data-ldap/src/test/java/org/apache/james/user/ldap/LdapGenericContainer.java
----------------------------------------------------------------------
diff --git a/server/data/data-ldap/src/test/java/org/apache/james/user/ldap/LdapGenericContainer.java b/server/data/data-ldap/src/test/java/org/apache/james/user/ldap/LdapGenericContainer.java
new file mode 100644
index 0000000..40ee62d
--- /dev/null
+++ b/server/data/data-ldap/src/test/java/org/apache/james/user/ldap/LdapGenericContainer.java
@@ -0,0 +1,114 @@
+/****************************************************************
+ * 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;
+
+import org.apache.james.util.docker.RateLimiters;
+import org.apache.james.util.docker.SwarmGenericContainer;
+import org.junit.rules.ExternalResource;
+import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy;
+import org.testcontainers.images.builder.ImageFromDockerfile;
+
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+
+public class LdapGenericContainer extends ExternalResource {
+
+    public static final int DEFAULT_LDAP_PORT = 389;
+
+    public static Builder builder() {
+        return new Builder();
+    }
+
+    public static class Builder {
+
+        private String domain;
+        private String password;
+
+        private Builder() {
+        }
+
+        public Builder domain(String domain) {
+            this.domain = domain;
+            return this;
+        }
+
+        public Builder password(String password) {
+            this.password = password;
+            return this;
+        }
+
+        public LdapGenericContainer build() {
+            Preconditions.checkState(!Strings.isNullOrEmpty(domain), "'domain' is mandatory");
+            Preconditions.checkState(!Strings.isNullOrEmpty(password), "'password' is mandatory");
+            return new LdapGenericContainer(createContainer());
+        }
+
+        private SwarmGenericContainer createContainer() {
+            return new SwarmGenericContainer(
+                new ImageFromDockerfile()
+                    .withFileFromClasspath("populate.ldif", "ldif-files/populate.ldif")
+                    .withFileFromClasspath("Dockerfile", "ldif-files/Dockerfile"))
+                .withAffinityToContainer()
+                .withEnv("SLAPD_DOMAIN", domain)
+                .withEnv("SLAPD_PASSWORD", password)
+                .withEnv("SLAPD_CONFIG_PASSWORD", password)
+                .withExposedPorts(LdapGenericContainer.DEFAULT_LDAP_PORT)
+                .waitingFor(new HostPortWaitStrategy().withRateLimiter(RateLimiters.TWENTIES_PER_SECOND));
+        }
+    }
+
+    private final SwarmGenericContainer container;
+
+    private LdapGenericContainer(SwarmGenericContainer container) {
+        this.container = container;
+    }
+
+    @Override
+    protected void before() {
+        start();
+    }
+
+    @Override
+    protected void after() {
+        stop();
+    }
+
+    public void start() {
+        container.start();
+    }
+
+    public void stop() {
+        container.stop();
+    }
+
+    public void pause() {
+        container.pause();
+    }
+
+    public void unpause() {
+        container.unpause();
+    }
+
+    public String getLdapHost() {
+        return "ldap://" +
+                container.getContainerIp() +
+                ":" +
+                LdapGenericContainer.DEFAULT_LDAP_PORT;
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/ffded847/server/data/data-ldap/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-ldap/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryTest.java b/server/data/data-ldap/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryTest.java
index f7b7a6b..39626ad 100644
--- a/server/data/data-ldap/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryTest.java
+++ b/server/data/data-ldap/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryTest.java
@@ -19,23 +19,43 @@
 
 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;
 
-import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.ConversionException;
 import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.commons.configuration.plist.PropertyListConfiguration;
+import org.apache.james.core.MailAddress;
 import org.apache.james.domainlist.api.DomainList;
 import org.junit.Before;
+import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class ReadOnlyUsersLDAPRepositoryTest {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(ReadOnlyUsersLDAPRepositoryTest.class);
+    private static final String JAMES_USER_MAIL = JAMES_USER + "@" + DOMAIN;
+    private static final String UNKNOWN = "unknown";
+    private static final String BAD_PASSWORD = "badpassword";
+
     @Rule
     public ExpectedException expectedException = ExpectedException.none();
+
+    @ClassRule
+    public static LdapGenericContainer ldapContainer = LdapGenericContainer.builder()
+        .domain(DOMAIN)
+        .password(ADMIN_PASSWORD)
+        .build();
+
+    private ReadOnlyUsersLDAPRepository ldapRepository;
     private DomainList domainList;
 
     @Before
@@ -43,6 +63,12 @@ public class ReadOnlyUsersLDAPRepositoryTest {
         domainList = mock(DomainList.class);
     }
 
+    private void startUsersRepository(HierarchicalConfiguration ldapRepositoryConfiguration) throws Exception {
+        ldapRepository = new ReadOnlyUsersLDAPRepository(domainList);
+        ldapRepository.configure(ldapRepositoryConfiguration);
+        ldapRepository.init();
+    }
+
     @Test
     public void supportVirtualHostingShouldReturnFalseByDefault() throws Exception {
         ReadOnlyUsersLDAPRepository usersLDAPRepository = new ReadOnlyUsersLDAPRepository(domainList);
@@ -85,11 +111,11 @@ public class ReadOnlyUsersLDAPRepositoryTest {
         usersLDAPRepository.configure(configuration);
     }
 
-    private HierarchicalConfiguration ldapRepositoryConfiguration() throws ConfigurationException {
+    private HierarchicalConfiguration ldapRepositoryConfiguration() {
         PropertyListConfiguration configuration = new PropertyListConfiguration();
-        configuration.addProperty("[@ldapHost]", "ldap://127.0.0.1");
+        configuration.addProperty("[@ldapHost]", ldapContainer.getLdapHost());
         configuration.addProperty("[@principal]", "cn=admin\\,dc=james\\,dc=org");
-        configuration.addProperty("[@credentials]", "secret");
+        configuration.addProperty("[@credentials]", ADMIN_PASSWORD);
         configuration.addProperty("[@userBase]", "ou=People\\,dc=james\\,dc=org");
         configuration.addProperty("[@userIdAttribute]", "uid");
         configuration.addProperty("[@userObjectClass]", "inetOrgPerson");
@@ -100,4 +126,104 @@ public class ReadOnlyUsersLDAPRepositoryTest {
         return configuration;
     }
 
+    private HierarchicalConfiguration ldapRepositoryConfigurationWithVirtualHosting() {
+        PropertyListConfiguration configuration = new PropertyListConfiguration();
+        configuration.addProperty("[@ldapHost]", ldapContainer.getLdapHost());
+        configuration.addProperty("[@principal]", "cn=admin\\,dc=james\\,dc=org");
+        configuration.addProperty("[@credentials]", ADMIN_PASSWORD);
+        configuration.addProperty("[@userBase]", "ou=People\\,dc=james\\,dc=org");
+        configuration.addProperty("[@userIdAttribute]", "mail");
+        configuration.addProperty("[@userObjectClass]", "inetOrgPerson");
+        configuration.addProperty("[@maxRetries]", "4");
+        configuration.addProperty("[@retryStartInterval]", "0");
+        configuration.addProperty("[@retryMaxInterval]", "8");
+        configuration.addProperty("[@retryIntervalScale]", "1000");
+        configuration.addProperty("supportsVirtualHosting", true);
+        return configuration;
+    }
+
+    @Test
+    public void knownUserShouldBeAbleToLogInWhenPasswordIsCorrect() throws Exception {
+        startUsersRepository(ldapRepositoryConfiguration());
+        assertThat(ldapRepository.test(JAMES_USER, PASSWORD)).isTrue();
+    }
+
+    @Test
+    public void knownUserShouldNotBeAbleToLogInWhenPasswordIsNotCorrect() throws Exception {
+        startUsersRepository(ldapRepositoryConfiguration());
+        assertThat(ldapRepository.test(JAMES_USER, BAD_PASSWORD)).isFalse();
+    }
+
+    @Test
+    public void unknownUserShouldNotBeAbleToLogIn() throws Exception {
+        startUsersRepository(ldapRepositoryConfiguration());
+        assertThat(ldapRepository.test(UNKNOWN, BAD_PASSWORD)).isFalse();
+    }
+
+    @Test
+    public void unknownUserShouldNotBeAbleToLogInWhenPasswordIsCorrect() throws Exception {
+        startUsersRepository(ldapRepositoryConfiguration());
+        assertThat(ldapRepository.test(UNKNOWN, PASSWORD)).isFalse();
+    }
+
+    @Test
+    public void knownUserShouldBeAbleToLogInWhenPasswordIsCorrectWithVirtualHosting() throws Exception {
+        startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting());
+        assertThat(ldapRepository.test(JAMES_USER_MAIL, PASSWORD)).isTrue();
+    }
+
+    @Test
+    public void testShouldStillWorksAfterRestartingLDAP() throws Exception {
+        startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting());
+        ldapRepository.test(JAMES_USER_MAIL, PASSWORD);
+
+        ldapContainer.pause();
+        try {
+            ldapRepository.test(JAMES_USER_MAIL, PASSWORD);
+        } catch (Exception e) {
+            LOGGER.info("This exception is expected as we shut down the LDAP and forced its use", e);
+        }
+        ldapContainer.unpause();
+
+        assertThat(ldapRepository.test(JAMES_USER_MAIL, PASSWORD)).isTrue();
+    }
+
+
+    @Test
+    public void knownUserShouldNotBeAbleToLogInWhenPasswordIsNotCorrectWithVirtualHosting() throws Exception {
+        startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting());
+        assertThat(ldapRepository.test(JAMES_USER, BAD_PASSWORD)).isFalse();
+    }
+
+    @Test
+    public void unknownUserShouldNotBeAbleToLogInWithVirtualHosting() throws Exception {
+        startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting());
+        assertThat(ldapRepository.test(UNKNOWN, BAD_PASSWORD)).isFalse();
+    }
+
+    @Test
+    public void unknownUserShouldNotBeAbleToLogInWhenPasswordIsCorrectWithVirtualHosting() throws Exception {
+        startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting());
+        assertThat(ldapRepository.test(UNKNOWN, PASSWORD)).isFalse();
+    }
+
+    @Test
+    public void containsWithGetUserShouldBeTrue() throws Exception {
+        startUsersRepository(ldapRepositoryConfiguration());
+        assertThat(ldapRepository.contains(ldapRepository.getUser(new MailAddress(JAMES_USER_MAIL)))).isTrue();
+    }
+
+    @Test
+    public void containsWithGetUserShouldBeTrueWithVirtualHosting() throws Exception {
+        startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting());
+        assertThat(ldapRepository.contains(ldapRepository.getUser(new MailAddress(JAMES_USER_MAIL)))).isTrue();
+    }
+
+    @Test
+    public void specialCharacterInUserInputShouldBeSanitized() throws Exception {
+        String patternMatchingMultipleUsers = "j*";
+
+        startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting());
+        assertThat(ldapRepository.test(patternMatchingMultipleUsers, PASSWORD)).isFalse();
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/ffded847/server/data/data-ldap/src/test/resources/ldif-files/Dockerfile
----------------------------------------------------------------------
diff --git a/server/data/data-ldap/src/test/resources/ldif-files/Dockerfile b/server/data/data-ldap/src/test/resources/ldif-files/Dockerfile
new file mode 100644
index 0000000..d889a35
--- /dev/null
+++ b/server/data/data-ldap/src/test/resources/ldif-files/Dockerfile
@@ -0,0 +1,3 @@
+FROM dinkel/openldap:latest
+
+COPY populate.ldif /etc/ldap/prepopulate/prepop.ldif

http://git-wip-us.apache.org/repos/asf/james-project/blob/ffded847/server/data/data-ldap/src/test/resources/ldif-files/populate.ldif
----------------------------------------------------------------------
diff --git a/server/data/data-ldap/src/test/resources/ldif-files/populate.ldif b/server/data/data-ldap/src/test/resources/ldif-files/populate.ldif
new file mode 100644
index 0000000..95f3391
--- /dev/null
+++ b/server/data/data-ldap/src/test/resources/ldif-files/populate.ldif
@@ -0,0 +1,12 @@
+dn: ou=people, dc=james,dc=org
+ou: people
+objectClass: organizationalUnit
+
+dn: uid=james-user, ou=people, dc=james,dc=org
+objectClass: inetOrgPerson
+uid: james-user
+cn: james-user
+sn: james-user
+mail: james-user@james.org
+userPassword: secret
+description: James user

http://git-wip-us.apache.org/repos/asf/james-project/blob/ffded847/server/data/data-ldap/src/test/resources/logback-test.xml
----------------------------------------------------------------------
diff --git a/server/data/data-ldap/src/test/resources/logback-test.xml b/server/data/data-ldap/src/test/resources/logback-test.xml
new file mode 100644
index 0000000..ddbf62c
--- /dev/null
+++ b/server/data/data-ldap/src/test/resources/logback-test.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+
+        <contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
+                <resetJUL>true</resetJUL>
+        </contextListener>
+
+        <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
+                <encoder>
+                        <pattern>%d{HH:mm:ss.SSS} [%-5level] %logger{15} - %msg%n%rEx</pattern>
+                        <immediateFlush>false</immediateFlush>
+                </encoder>
+        </appender>
+
+        <root level="WARN">
+                <appender-ref ref="CONSOLE" />
+        </root>
+
+        <logger name="org.testcontainers" level="WARN"/>
+        <logger name="org.apache.james" level="WARN"/>
+
+</configuration>

http://git-wip-us.apache.org/repos/asf/james-project/blob/ffded847/server/pom.xml
----------------------------------------------------------------------
diff --git a/server/pom.xml b/server/pom.xml
index f3fa630..6ba5754 100644
--- a/server/pom.xml
+++ b/server/pom.xml
@@ -63,7 +63,6 @@
         <module>data/data-jmap-cassandra</module>
         <module>data/data-jpa</module>
         <module>data/data-ldap</module>
-        <module>data/data-ldap-integration-testing</module>
         <module>data/data-library</module>
         <module>data/data-memory</module>
 


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[3/5] james-project git commit: JAMES-2615 Update pom merged module

Posted by bt...@apache.org.
JAMES-2615 Update pom merged module


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/00ace5d2
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/00ace5d2
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/00ace5d2

Branch: refs/heads/master
Commit: 00ace5d20651473d32d79b3f1664808baa8244a1
Parents: ffded84
Author: datph <dp...@linagora.com>
Authored: Thu Nov 29 16:47:33 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Mon Dec 3 08:55:53 2018 +0700

----------------------------------------------------------------------
 server/data/data-ldap/pom.xml | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/00ace5d2/server/data/data-ldap/pom.xml
----------------------------------------------------------------------
diff --git a/server/data/data-ldap/pom.xml b/server/data/data-ldap/pom.xml
index 4b72c98..31ae9c7 100644
--- a/server/data/data-ldap/pom.xml
+++ b/server/data/data-ldap/pom.xml
@@ -43,6 +43,11 @@
         </dependency>
         <dependency>
             <groupId>${james.groupId}</groupId>
+            <artifactId>james-server-testing</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
             <artifactId>james-server-util</artifactId>
         </dependency>
         <dependency>
@@ -93,11 +98,6 @@
             <artifactId>testcontainers</artifactId>
             <scope>test</scope>
         </dependency>
-        <dependency>
-            <groupId>org.apache.james</groupId>
-            <artifactId>james-server-testing</artifactId>
-            <scope>test</scope>
-        </dependency>
     </dependencies>
 
     <build>


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[5/5] james-project git commit: JAMES-2598 Fix packaging Cassandra + ElasticSearch + Swift + RabbitMQ + LDAP product

Posted by bt...@apache.org.
JAMES-2598 Fix packaging Cassandra + ElasticSearch + Swift + RabbitMQ + LDAP product

Change the image name


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/ce8cf479
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/ce8cf479
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/ce8cf479

Branch: refs/heads/master
Commit: ce8cf479a5b11a2205c426f9fd694a0bab563016
Parents: 9cffabc
Author: datph <dp...@linagora.com>
Authored: Thu Nov 29 15:45:37 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Mon Dec 3 08:56:23 2018 +0700

----------------------------------------------------------------------
 dockerfiles/packaging/guice/cassandra/Dockerfile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/ce8cf479/dockerfiles/packaging/guice/cassandra/Dockerfile
----------------------------------------------------------------------
diff --git a/dockerfiles/packaging/guice/cassandra/Dockerfile b/dockerfiles/packaging/guice/cassandra/Dockerfile
index d031fe8..d05f613 100644
--- a/dockerfiles/packaging/guice/cassandra/Dockerfile
+++ b/dockerfiles/packaging/guice/cassandra/Dockerfile
@@ -1,7 +1,7 @@
 ARG BASE=linagora/james-project
 ARG BASE_LDAP=linagora/james-ldap-project
 ARG BASE_RABBITMQ=linagora/james-rabbitmq-project
-ARG BASE_RABBITMQ_LDAP=linagora/james-rabbitmq-ldap-project
+ARG BASE_RABBITMQ_LDAP=linagora/james-cassandra-rabbitmq-ldap-project
 ARG TAG=latest
 FROM ${BASE}:${TAG} as source
 FROM ${BASE_LDAP}:${TAG} as sourceLdap


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[4/5] james-project git commit: JAMES-2615 Group test for ReadOnlyUsersLDAPRepositoryTest

Posted by bt...@apache.org.
JAMES-2615 Group test for ReadOnlyUsersLDAPRepositoryTest


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/9cffabc8
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/9cffabc8
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/9cffabc8

Branch: refs/heads/master
Commit: 9cffabc83c1818571f57e9f45f6a209d583a3d5b
Parents: 077f51c
Author: datph <dp...@linagora.com>
Authored: Fri Nov 30 12:10:23 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Mon Dec 3 08:55:53 2018 +0700

----------------------------------------------------------------------
 .../ldap/ReadOnlyUsersLDAPRepositoryTest.java   | 274 +++++++++----------
 1 file changed, 135 insertions(+), 139 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/9cffabc8/server/data/data-ldap/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-ldap/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryTest.java b/server/data/data-ldap/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryTest.java
index 39626ad..b217ae1 100644
--- a/server/data/data-ldap/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryTest.java
+++ b/server/data/data-ldap/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryTest.java
@@ -24,6 +24,7 @@ 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.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.mockito.Mockito.mock;
 
 import org.apache.commons.configuration.ConversionException;
@@ -31,11 +32,9 @@ import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.commons.configuration.plist.PropertyListConfiguration;
 import org.apache.james.core.MailAddress;
 import org.apache.james.domainlist.api.DomainList;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -46,74 +45,156 @@ public class ReadOnlyUsersLDAPRepositoryTest {
     private static final String UNKNOWN = "unknown";
     private static final String BAD_PASSWORD = "badpassword";
 
-    @Rule
-    public ExpectedException expectedException = ExpectedException.none();
-
-    @ClassRule
-    public static LdapGenericContainer ldapContainer = LdapGenericContainer.builder()
-        .domain(DOMAIN)
-        .password(ADMIN_PASSWORD)
-        .build();
-
-    private ReadOnlyUsersLDAPRepository ldapRepository;
     private DomainList domainList;
 
-    @Before
-    public void setUp() {
+    @BeforeEach
+    void setUp() {
         domainList = mock(DomainList.class);
     }
 
-    private void startUsersRepository(HierarchicalConfiguration ldapRepositoryConfiguration) throws Exception {
-        ldapRepository = new ReadOnlyUsersLDAPRepository(domainList);
-        ldapRepository.configure(ldapRepositoryConfiguration);
-        ldapRepository.init();
-    }
+    @Nested
+    class SupportVirtualHosting {
 
-    @Test
-    public void supportVirtualHostingShouldReturnFalseByDefault() throws Exception {
-        ReadOnlyUsersLDAPRepository usersLDAPRepository = new ReadOnlyUsersLDAPRepository(domainList);
-        usersLDAPRepository.configure(ldapRepositoryConfiguration());
+        @Test
+        public void supportVirtualHostingShouldReturnFalseByDefault() throws Exception {
+            ReadOnlyUsersLDAPRepository usersLDAPRepository = new ReadOnlyUsersLDAPRepository(domainList);
+            usersLDAPRepository.configure(ldapRepositoryConfiguration());
 
-        assertThat(usersLDAPRepository.supportVirtualHosting()).isFalse();
-    }
+            assertThat(usersLDAPRepository.supportVirtualHosting()).isFalse();
+        }
 
-    @Test
-    public void supportVirtualHostingShouldReturnTrueWhenReportedInConfig() throws Exception {
-        HierarchicalConfiguration configuration = ldapRepositoryConfiguration();
-        configuration.addProperty(ReadOnlyUsersLDAPRepository.SUPPORTS_VIRTUAL_HOSTING, "true");
+        @Test
+        public void supportVirtualHostingShouldReturnTrueWhenReportedInConfig() throws Exception {
+            HierarchicalConfiguration configuration = ldapRepositoryConfiguration();
+            configuration.addProperty(ReadOnlyUsersLDAPRepository.SUPPORTS_VIRTUAL_HOSTING, "true");
 
-        ReadOnlyUsersLDAPRepository usersLDAPRepository = new ReadOnlyUsersLDAPRepository(domainList);
-        usersLDAPRepository.configure(configuration);
+            ReadOnlyUsersLDAPRepository usersLDAPRepository = new ReadOnlyUsersLDAPRepository(domainList);
+            usersLDAPRepository.configure(configuration);
 
-        assertThat(usersLDAPRepository.supportVirtualHosting()).isTrue();
-    }
+            assertThat(usersLDAPRepository.supportVirtualHosting()).isTrue();
+        }
+
+        @Test
+        public void supportVirtualHostingShouldReturnFalseWhenReportedInConfig() throws Exception {
+            HierarchicalConfiguration configuration = ldapRepositoryConfiguration();
+            configuration.addProperty(ReadOnlyUsersLDAPRepository.SUPPORTS_VIRTUAL_HOSTING, "false");
+
+            ReadOnlyUsersLDAPRepository usersLDAPRepository = new ReadOnlyUsersLDAPRepository(domainList);
+            usersLDAPRepository.configure(configuration);
 
-    @Test
-    public void supportVirtualHostingShouldReturnFalseWhenReportedInConfig() throws Exception {
-        HierarchicalConfiguration configuration = ldapRepositoryConfiguration();
-        configuration.addProperty(ReadOnlyUsersLDAPRepository.SUPPORTS_VIRTUAL_HOSTING, "false");
+            assertThat(usersLDAPRepository.supportVirtualHosting()).isFalse();
+        }
+
+        @Test
+        public void configureShouldThrowOnNonBooleanValueForSupportsVirtualHosting() throws Exception {
+            HierarchicalConfiguration configuration = ldapRepositoryConfiguration();
+            configuration.addProperty(ReadOnlyUsersLDAPRepository.SUPPORTS_VIRTUAL_HOSTING, "bad");
 
-        ReadOnlyUsersLDAPRepository usersLDAPRepository = new ReadOnlyUsersLDAPRepository(domainList);
-        usersLDAPRepository.configure(configuration);
+            ReadOnlyUsersLDAPRepository usersLDAPRepository = new ReadOnlyUsersLDAPRepository(domainList);
 
-        assertThat(usersLDAPRepository.supportVirtualHosting()).isFalse();
+            assertThatThrownBy(()-> usersLDAPRepository.configure(configuration))
+                .isInstanceOf(ConversionException.class);
+        }
     }
 
-    @Test
-    public void configureShouldThrowOnNonBooleanValueForSupportsVirtualHosting() throws Exception {
-        HierarchicalConfiguration configuration = ldapRepositoryConfiguration();
-        configuration.addProperty(ReadOnlyUsersLDAPRepository.SUPPORTS_VIRTUAL_HOSTING, "bad");
+    @Nested
+    class TestUser {
 
-        ReadOnlyUsersLDAPRepository usersLDAPRepository = new ReadOnlyUsersLDAPRepository(domainList);
+        @Test
+        public void knownUserShouldBeAbleToLogInWhenPasswordIsCorrect() throws Exception {
+            ReadOnlyUsersLDAPRepository ldapRepository = startUsersRepository(ldapRepositoryConfiguration());
+            assertThat(ldapRepository.test(JAMES_USER, PASSWORD)).isTrue();
+        }
 
-        expectedException.expect(ConversionException.class);
+        @Test
+        public void knownUserShouldNotBeAbleToLogInWhenPasswordIsNotCorrect() throws Exception {
+            ReadOnlyUsersLDAPRepository ldapRepository = startUsersRepository(ldapRepositoryConfiguration());
+            assertThat(ldapRepository.test(JAMES_USER, BAD_PASSWORD)).isFalse();
+        }
+
+        @Test
+        public void unknownUserShouldNotBeAbleToLogIn() throws Exception {
+            ReadOnlyUsersLDAPRepository ldapRepository = startUsersRepository(ldapRepositoryConfiguration());
+            assertThat(ldapRepository.test(UNKNOWN, BAD_PASSWORD)).isFalse();
+        }
+
+        @Test
+        public void unknownUserShouldNotBeAbleToLogInWhenPasswordIsCorrect() throws Exception {
+            ReadOnlyUsersLDAPRepository ldapRepository = startUsersRepository(ldapRepositoryConfiguration());
+            assertThat(ldapRepository.test(UNKNOWN, PASSWORD)).isFalse();
+        }
 
-        usersLDAPRepository.configure(configuration);
+        @Test
+        public void knownUserShouldBeAbleToLogInWhenPasswordIsCorrectWithVirtualHosting() throws Exception {
+            ReadOnlyUsersLDAPRepository ldapRepository = startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting());
+            assertThat(ldapRepository.test(JAMES_USER_MAIL, PASSWORD)).isTrue();
+        }
+
+        @Test
+        public void testShouldStillWorksAfterRestartingLDAP() throws Exception {
+            ReadOnlyUsersLDAPRepository ldapRepository = startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting());
+            ldapRepository.test(JAMES_USER_MAIL, PASSWORD);
+
+            DockerLdapSingleton.ldapContainer.pause();
+            try {
+                ldapRepository.test(JAMES_USER_MAIL, PASSWORD);
+            } catch (Exception e) {
+                LOGGER.info("This exception is expected as we shut down the LDAP and forced its use", e);
+            }
+            DockerLdapSingleton.ldapContainer.unpause();
+
+            assertThat(ldapRepository.test(JAMES_USER_MAIL, PASSWORD)).isTrue();
+        }
+
+        @Test
+        public void knownUserShouldNotBeAbleToLogInWhenPasswordIsNotCorrectWithVirtualHosting() throws Exception {
+            ReadOnlyUsersLDAPRepository ldapRepository = startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting());
+            assertThat(ldapRepository.test(JAMES_USER, BAD_PASSWORD)).isFalse();
+        }
+
+        @Test
+        public void unknownUserShouldNotBeAbleToLogInWithVirtualHosting() throws Exception {
+            ReadOnlyUsersLDAPRepository ldapRepository = startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting());
+            assertThat(ldapRepository.test(UNKNOWN, BAD_PASSWORD)).isFalse();
+        }
+
+        @Test
+        public void unknownUserShouldNotBeAbleToLogInWhenPasswordIsCorrectWithVirtualHosting() throws Exception {
+            ReadOnlyUsersLDAPRepository ldapRepository = startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting());
+            assertThat(ldapRepository.test(UNKNOWN, PASSWORD)).isFalse();
+        }
+
+        @Test
+        public void specialCharacterInUserInputShouldBeSanitized() throws Exception {
+            String patternMatchingMultipleUsers = "j*";
+
+            ReadOnlyUsersLDAPRepository ldapRepository = startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting());
+            assertThat(ldapRepository.test(patternMatchingMultipleUsers, PASSWORD)).isFalse();
+        }
+
+        @Test
+        public void containsWithGetUserShouldBeTrue() throws Exception {
+            ReadOnlyUsersLDAPRepository ldapRepository = startUsersRepository(ldapRepositoryConfiguration());
+            assertThat(ldapRepository.contains(ldapRepository.getUser(new MailAddress(JAMES_USER_MAIL)))).isTrue();
+        }
+
+        @Test
+        public void containsWithGetUserShouldBeTrueWithVirtualHosting() throws Exception {
+            ReadOnlyUsersLDAPRepository ldapRepository = startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting());
+            assertThat(ldapRepository.contains(ldapRepository.getUser(new MailAddress(JAMES_USER_MAIL)))).isTrue();
+        }
+
+        private ReadOnlyUsersLDAPRepository startUsersRepository(HierarchicalConfiguration ldapRepositoryConfiguration) throws Exception {
+            ReadOnlyUsersLDAPRepository ldapRepository = new ReadOnlyUsersLDAPRepository(domainList);
+            ldapRepository.configure(ldapRepositoryConfiguration);
+            ldapRepository.init();
+            return ldapRepository;
+        }
     }
 
-    private HierarchicalConfiguration ldapRepositoryConfiguration() {
+    private static HierarchicalConfiguration ldapRepositoryConfiguration() {
         PropertyListConfiguration configuration = new PropertyListConfiguration();
-        configuration.addProperty("[@ldapHost]", ldapContainer.getLdapHost());
+        configuration.addProperty("[@ldapHost]", DockerLdapSingleton.ldapContainer.getLdapHost());
         configuration.addProperty("[@principal]", "cn=admin\\,dc=james\\,dc=org");
         configuration.addProperty("[@credentials]", ADMIN_PASSWORD);
         configuration.addProperty("[@userBase]", "ou=People\\,dc=james\\,dc=org");
@@ -126,9 +207,9 @@ public class ReadOnlyUsersLDAPRepositoryTest {
         return configuration;
     }
 
-    private HierarchicalConfiguration ldapRepositoryConfigurationWithVirtualHosting() {
+    private static HierarchicalConfiguration ldapRepositoryConfigurationWithVirtualHosting() {
         PropertyListConfiguration configuration = new PropertyListConfiguration();
-        configuration.addProperty("[@ldapHost]", ldapContainer.getLdapHost());
+        configuration.addProperty("[@ldapHost]", DockerLdapSingleton.ldapContainer.getLdapHost());
         configuration.addProperty("[@principal]", "cn=admin\\,dc=james\\,dc=org");
         configuration.addProperty("[@credentials]", ADMIN_PASSWORD);
         configuration.addProperty("[@userBase]", "ou=People\\,dc=james\\,dc=org");
@@ -141,89 +222,4 @@ public class ReadOnlyUsersLDAPRepositoryTest {
         configuration.addProperty("supportsVirtualHosting", true);
         return configuration;
     }
-
-    @Test
-    public void knownUserShouldBeAbleToLogInWhenPasswordIsCorrect() throws Exception {
-        startUsersRepository(ldapRepositoryConfiguration());
-        assertThat(ldapRepository.test(JAMES_USER, PASSWORD)).isTrue();
-    }
-
-    @Test
-    public void knownUserShouldNotBeAbleToLogInWhenPasswordIsNotCorrect() throws Exception {
-        startUsersRepository(ldapRepositoryConfiguration());
-        assertThat(ldapRepository.test(JAMES_USER, BAD_PASSWORD)).isFalse();
-    }
-
-    @Test
-    public void unknownUserShouldNotBeAbleToLogIn() throws Exception {
-        startUsersRepository(ldapRepositoryConfiguration());
-        assertThat(ldapRepository.test(UNKNOWN, BAD_PASSWORD)).isFalse();
-    }
-
-    @Test
-    public void unknownUserShouldNotBeAbleToLogInWhenPasswordIsCorrect() throws Exception {
-        startUsersRepository(ldapRepositoryConfiguration());
-        assertThat(ldapRepository.test(UNKNOWN, PASSWORD)).isFalse();
-    }
-
-    @Test
-    public void knownUserShouldBeAbleToLogInWhenPasswordIsCorrectWithVirtualHosting() throws Exception {
-        startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting());
-        assertThat(ldapRepository.test(JAMES_USER_MAIL, PASSWORD)).isTrue();
-    }
-
-    @Test
-    public void testShouldStillWorksAfterRestartingLDAP() throws Exception {
-        startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting());
-        ldapRepository.test(JAMES_USER_MAIL, PASSWORD);
-
-        ldapContainer.pause();
-        try {
-            ldapRepository.test(JAMES_USER_MAIL, PASSWORD);
-        } catch (Exception e) {
-            LOGGER.info("This exception is expected as we shut down the LDAP and forced its use", e);
-        }
-        ldapContainer.unpause();
-
-        assertThat(ldapRepository.test(JAMES_USER_MAIL, PASSWORD)).isTrue();
-    }
-
-
-    @Test
-    public void knownUserShouldNotBeAbleToLogInWhenPasswordIsNotCorrectWithVirtualHosting() throws Exception {
-        startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting());
-        assertThat(ldapRepository.test(JAMES_USER, BAD_PASSWORD)).isFalse();
-    }
-
-    @Test
-    public void unknownUserShouldNotBeAbleToLogInWithVirtualHosting() throws Exception {
-        startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting());
-        assertThat(ldapRepository.test(UNKNOWN, BAD_PASSWORD)).isFalse();
-    }
-
-    @Test
-    public void unknownUserShouldNotBeAbleToLogInWhenPasswordIsCorrectWithVirtualHosting() throws Exception {
-        startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting());
-        assertThat(ldapRepository.test(UNKNOWN, PASSWORD)).isFalse();
-    }
-
-    @Test
-    public void containsWithGetUserShouldBeTrue() throws Exception {
-        startUsersRepository(ldapRepositoryConfiguration());
-        assertThat(ldapRepository.contains(ldapRepository.getUser(new MailAddress(JAMES_USER_MAIL)))).isTrue();
-    }
-
-    @Test
-    public void containsWithGetUserShouldBeTrueWithVirtualHosting() throws Exception {
-        startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting());
-        assertThat(ldapRepository.contains(ldapRepository.getUser(new MailAddress(JAMES_USER_MAIL)))).isTrue();
-    }
-
-    @Test
-    public void specialCharacterInUserInputShouldBeSanitized() throws Exception {
-        String patternMatchingMultipleUsers = "j*";
-
-        startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting());
-        assertThat(ldapRepository.test(patternMatchingMultipleUsers, PASSWORD)).isFalse();
-    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[2/5] james-project git commit: JAMES-2615 Update dependency for merged data-ldap module

Posted by bt...@apache.org.
JAMES-2615 Update dependency for merged data-ldap module


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/077f51cf
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/077f51cf
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/077f51cf

Branch: refs/heads/master
Commit: 077f51cf39044ffebe35eab58304bc1184333c3a
Parents: 00ace5d
Author: datph <dp...@linagora.com>
Authored: Fri Nov 30 10:19:19 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Mon Dec 3 08:55:53 2018 +0700

----------------------------------------------------------------------
 pom.xml                                         |  5 --
 .../guice/cassandra-ldap-guice/pom.xml          |  7 +-
 .../guice/cassandra-rabbitmq-ldap-guice/pom.xml |  2 +-
 .../data/data-ldap-integration-testing/pom.xml  | 86 --------------------
 4 files changed, 2 insertions(+), 98 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/077f51cf/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index d755d6a..300a18b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1241,11 +1241,6 @@
             </dependency>
             <dependency>
                 <groupId>${james.groupId}</groupId>
-                <artifactId>james-server-data-ldap-integration-testing</artifactId>
-                <version>${project.version}</version>
-            </dependency>
-            <dependency>
-                <groupId>${james.groupId}</groupId>
                 <artifactId>james-server-data-library</artifactId>
                 <version>${project.version}</version>
             </dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/077f51cf/server/container/guice/cassandra-ldap-guice/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-ldap-guice/pom.xml b/server/container/guice/cassandra-ldap-guice/pom.xml
index edeffb9..cea373c 100644
--- a/server/container/guice/cassandra-ldap-guice/pom.xml
+++ b/server/container/guice/cassandra-ldap-guice/pom.xml
@@ -71,12 +71,7 @@
         </dependency>
         <dependency>
             <groupId>${james.groupId}</groupId>
-            <artifactId>james-server-data-ldap-integration-testing</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>${james.groupId}</groupId>
-            <artifactId>james-server-data-ldap-integration-testing</artifactId>
+            <artifactId>james-server-data-ldap</artifactId>
             <version>${project.version}</version>
             <type>test-jar</type>
             <scope>test</scope>

http://git-wip-us.apache.org/repos/asf/james-project/blob/077f51cf/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 d2b5672..b6c68d9 100644
--- a/server/container/guice/cassandra-rabbitmq-ldap-guice/pom.xml
+++ b/server/container/guice/cassandra-rabbitmq-ldap-guice/pom.xml
@@ -91,7 +91,7 @@
         </dependency>
         <dependency>
             <groupId>org.apache.james</groupId>
-            <artifactId>james-server-data-ldap-integration-testing</artifactId>
+            <artifactId>james-server-data-ldap</artifactId>
             <type>test-jar</type>
             <version>${project.version}</version>
             <scope>test</scope>

http://git-wip-us.apache.org/repos/asf/james-project/blob/077f51cf/server/data/data-ldap-integration-testing/pom.xml
----------------------------------------------------------------------
diff --git a/server/data/data-ldap-integration-testing/pom.xml b/server/data/data-ldap-integration-testing/pom.xml
deleted file mode 100644
index 4006dbe..0000000
--- a/server/data/data-ldap-integration-testing/pom.xml
+++ /dev/null
@@ -1,86 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-    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.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-    <modelVersion>4.0.0</modelVersion>
-
-    <parent>
-        <groupId>org.apache.james</groupId>
-        <artifactId>james-server</artifactId>
-        <version>3.3.0-SNAPSHOT</version>
-        <relativePath>../../pom.xml</relativePath>
-    </parent>
-
-    <artifactId>james-server-data-ldap-integration-testing</artifactId>
-    <packaging>bundle</packaging>
-
-    <name>Apache James :: Server :: Data :: LDAP Implementation :: Integration testing</name>
-
-    <dependencies>
-        <dependency>
-            <groupId>${james.groupId}</groupId>
-            <artifactId>james-server-data-ldap</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>${james.groupId}</groupId>
-            <artifactId>james-server-util</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>${james.groupId}</groupId>
-            <artifactId>james-server-testing</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>ch.qos.logback</groupId>
-            <artifactId>logback-classic</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>com.google.guava</groupId>
-            <artifactId>guava</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.assertj</groupId>
-            <artifactId>assertj-core</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.mockito</groupId>
-            <artifactId>mockito-core</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.slf4j</groupId>
-            <artifactId>jcl-over-slf4j</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.testcontainers</groupId>
-            <artifactId>testcontainers</artifactId>
-            <scope>test</scope>
-        </dependency>
-    </dependencies>
-</project>


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org