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 2020/03/26 02:41:33 UTC

[james-project] 11/16: JAMES-3088 Add tests when empty LDAP

This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit f82b46b8d0fff2a25a92f50031c850e327e25721
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed Mar 25 11:42:20 2020 +0700

    JAMES-3088 Add tests when empty LDAP
---
 .../ReadOnlyUsersLDAPRepositoryEmptyListTest.java  | 121 +++++++++++++++++++++
 .../user/ldap/ReadOnlyUsersLDAPRepositoryTest.java |  14 ++-
 .../src/test/resources/ldif-files/populate.ldif    |   4 +
 3 files changed, 134 insertions(+), 5 deletions(-)

diff --git a/server/data/data-ldap/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryEmptyListTest.java b/server/data/data-ldap/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryEmptyListTest.java
new file mode 100644
index 0000000..0f9e17c
--- /dev/null
+++ b/server/data/data-ldap/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryEmptyListTest.java
@@ -0,0 +1,121 @@
+/****************************************************************
+ * 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.ReadOnlyUsersLDAPRepositoryTest.ldapRepositoryConfiguration;
+import static org.apache.james.user.ldap.ReadOnlyUsersLDAPRepositoryTest.ldapRepositoryConfigurationWithVirtualHosting;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+
+import org.apache.commons.configuration2.HierarchicalConfiguration;
+import org.apache.commons.configuration2.tree.ImmutableNode;
+import org.apache.james.domainlist.api.DomainList;
+import org.apache.james.user.api.UsersRepositoryException;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+
+import com.google.common.collect.ImmutableList;
+
+class ReadOnlyUsersLDAPRepositoryEmptyListTest {
+    static LdapGenericContainer ldapContainer = LdapGenericContainer.builder()
+        .domain(DOMAIN)
+        .password(ADMIN_PASSWORD)
+        .build();
+
+    DomainList domainList;
+    private ReadOnlyUsersLDAPRepository ldapRepository;
+
+    @BeforeAll
+    static void setUpAll() {
+        ldapContainer.start();
+    }
+
+    @AfterAll
+    static void afterAll() {
+        ldapContainer.stop();
+    }
+
+    @Nested
+    class WhenDisableVirtualHosting {
+
+        @BeforeEach
+        void setUp() throws Exception {
+            domainList = mock(DomainList.class);
+            HierarchicalConfiguration<ImmutableNode> config = ldapRepositoryConfiguration(ldapContainer);
+            config.setProperty("[@userBase]", "ou=empty,dc=james,dc=org");
+            ldapRepository = startUsersRepository(config);
+        }
+
+        @Test
+        void listShouldReturnEmptyWhenNoEntity() throws Exception {
+            assertThat(ImmutableList.copyOf(ldapRepository.list()))
+                .isEmpty();
+        }
+
+        @Test
+        void countUsersShouldReturnZeroWhenEmptyRepository() throws UsersRepositoryException {
+            //Given
+            int expected = 0;
+            //When
+            int actual = ldapRepository.countUsers();
+            //Then
+            assertThat(actual).isEqualTo(expected);
+        }
+    }
+
+    @Nested
+    class SupportVirtualHosting {
+        @BeforeEach
+        void setUp() throws Exception {
+            domainList = mock(DomainList.class);
+            HierarchicalConfiguration<ImmutableNode> config = ldapRepositoryConfigurationWithVirtualHosting(ldapContainer);
+            config.setProperty("[@userBase]", "ou=empty,dc=james,dc=org");
+            ldapRepository = startUsersRepository(config);
+        }
+
+        @Test
+        void listShouldReturnEmptyWhenNoEntity() throws Exception {
+            assertThat(ImmutableList.copyOf(ldapRepository.list()))
+                .isEmpty();
+        }
+
+        @Test
+        void countUsersShouldReturnZeroWhenEmptyRepository() throws UsersRepositoryException {
+            //Given
+            int expected = 0;
+            //When
+            int actual = ldapRepository.countUsers();
+            //Then
+            assertThat(actual).isEqualTo(expected);
+        }
+    }
+
+    private ReadOnlyUsersLDAPRepository startUsersRepository(HierarchicalConfiguration<ImmutableNode> ldapRepositoryConfiguration) throws Exception {
+        ReadOnlyUsersLDAPRepository ldapRepository = new ReadOnlyUsersLDAPRepository(domainList);
+        ldapRepository.configure(ldapRepositoryConfiguration);
+        ldapRepository.init();
+        return ldapRepository;
+    }
+}
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 44491b8..4ce4d74 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
@@ -133,13 +133,15 @@ class ReadOnlyUsersLDAPRepositoryTest {
             assertThat(usersRepository.contains(usersRepository.getUsername(JAMES_USER_MAIL.asMailAddress()))).isTrue();
         }
 
-        @Disabled("JAMES-3088 Users are provisioned by default from Dockerfile, cannot setup this test case")
+        @Disabled("JAMES-3088 Users are provisioned by default from Dockerfile, cannot setup this test case," +
+            "See @link{ReadOnlyUsersLDAPRepositoryEmptyListTest}")
         @Override
         @Test
         public void listShouldReturnEmptyIteratorWhenEmptyRepository(TestSystem testSystem) {
         }
 
-        @Disabled("JAMES-3088 Users are provisioned by default from Dockerfile, cannot setup this test case")
+        @Disabled("JAMES-3088 Users are provisioned by default from Dockerfile, cannot setup this test case," +
+            "See @link{ReadOnlyUsersLDAPRepositoryEmptyListTest}")
         @Override
         @Test
         public void countUsersShouldReturnZeroWhenEmptyRepository() {
@@ -193,13 +195,15 @@ class ReadOnlyUsersLDAPRepositoryTest {
             assertThat(testee().isAdministrator(testSystem.getAdmin())).isTrue();
         }
 
-        @Disabled("JAMES-3088 Users are provisioned by default from Dockerfile, cannot setup this test case")
+        @Disabled("JAMES-3088 Users are provisioned by default from Dockerfile, cannot setup this test case," +
+            "See @link{ReadOnlyUsersLDAPRepositoryEmptyListTest}")
         @Override
         @Test
         public void listShouldReturnEmptyIteratorWhenEmptyRepository(TestSystem testSystem) {
         }
 
-        @Disabled("JAMES-3088 Users are provisioned by default from Dockerfile, cannot setup this test case")
+        @Disabled("JAMES-3088 Users are provisioned by default from Dockerfile, cannot setup this test case," +
+            "See @link{ReadOnlyUsersLDAPRepositoryEmptyListTest}")
         @Override
         @Test
         public void countUsersShouldReturnZeroWhenEmptyRepository() {
@@ -259,7 +263,7 @@ class ReadOnlyUsersLDAPRepositoryTest {
         return ldapRepository;
     }
 
-    private static HierarchicalConfiguration<ImmutableNode> ldapRepositoryConfiguration(LdapGenericContainer ldapContainer) {
+    static HierarchicalConfiguration<ImmutableNode> ldapRepositoryConfiguration(LdapGenericContainer ldapContainer) {
         PropertyListConfiguration configuration = baseConfiguration(ldapContainer);
         configuration.addProperty("[@userIdAttribute]", "uid");
         configuration.addProperty("[@administratorId]", ADMIN_LOCAL_PART);
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
index 95f3391..586125d 100644
--- a/server/data/data-ldap/src/test/resources/ldif-files/populate.ldif
+++ b/server/data/data-ldap/src/test/resources/ldif-files/populate.ldif
@@ -2,6 +2,10 @@ dn: ou=people, dc=james,dc=org
 ou: people
 objectClass: organizationalUnit
 
+dn: ou=empty, dc=james,dc=org
+ou: empty
+objectClass: organizationalUnit
+
 dn: uid=james-user, ou=people, dc=james,dc=org
 objectClass: inetOrgPerson
 uid: james-user


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