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 d56e5ef944d6084068410debd0ff674e6e0550c6 Author: Tran Tien Duc <dt...@linagora.com> AuthorDate: Thu Mar 5 13:22:19 2020 +0700 JAMES-3088 Apply contract tests to the LDAPUserRepository --- .../james/user/ldap/DockerLdapSingleton.java | 2 + .../ReadOnlyUsersLDAPRepositoryInvalidDnTest.java | 4 - .../user/ldap/ReadOnlyUsersLDAPRepositoryTest.java | 628 +++++++++++++++++---- .../user/lib/AbstractUsersRepositoryContract.java | 12 +- 4 files changed, 542 insertions(+), 104 deletions(-) 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 index 1a61bd9..9de0fa7 100644 --- 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 @@ -26,6 +26,8 @@ public class DockerLdapSingleton { public static final String PASSWORD = "secret"; public static final String DOMAIN = "james.org"; public static final String ADMIN_PASSWORD = "mysecretpassword"; + public static final String ADMIN_LOCAL_PART = "admin"; + public static final Username ADMIN = Username.fromLocalPartWithDomain(ADMIN_LOCAL_PART, DOMAIN); public static final LdapGenericContainer ldapContainer = LdapGenericContainer.builder() .domain(DOMAIN) diff --git a/server/data/data-ldap/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryInvalidDnTest.java b/server/data/data-ldap/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryInvalidDnTest.java index 33fd239..d558dd7 100644 --- a/server/data/data-ldap/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryInvalidDnTest.java +++ b/server/data/data-ldap/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryInvalidDnTest.java @@ -27,16 +27,12 @@ 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.plist.PropertyListConfiguration; import org.apache.commons.configuration2.tree.ImmutableNode; -import org.apache.james.core.Username; import org.apache.james.domainlist.api.DomainList; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.google.common.collect.ImmutableList; 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 9b09f06..8fbaa63 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,6 +19,8 @@ package org.apache.james.user.ldap; +import static org.apache.james.user.ldap.DockerLdapSingleton.ADMIN; +import static org.apache.james.user.ldap.DockerLdapSingleton.ADMIN_LOCAL_PART; 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; @@ -37,9 +39,13 @@ import org.junit.jupiter.api.BeforeAll; import org.apache.james.domainlist.api.mock.SimpleDomainList; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.apache.james.user.lib.AbstractUsersRepository; +import org.apache.james.user.lib.AbstractUsersRepositoryContract; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -57,8 +63,6 @@ class ReadOnlyUsersLDAPRepositoryTest { .password(ADMIN_PASSWORD) .build(); - DomainList domainList; - @BeforeAll static void setUpAll() { ldapContainer.start(); @@ -69,188 +73,620 @@ class ReadOnlyUsersLDAPRepositoryTest { ldapContainer.start(); } - @BeforeEach - void setUp() { - domainList = new SimpleDomainList(); - } - @Nested - class SupportVirtualHosting { + class WhenEnableVirtualHosting implements AbstractUsersRepositoryContract.WithVirtualHostingContract { + @RegisterExtension + UserRepositoryExtension extension = UserRepositoryExtension.withVirtualHost(); + + private ReadOnlyUsersLDAPRepository usersRepository; + @BeforeEach + void setUp(TestSystem testSystem) throws Exception { + usersRepository = startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting(ldapContainer), testSystem.getDomainList()); + } + + @Override + public AbstractUsersRepository testee() { + return usersRepository; + } + + @Override @Test - void supportVirtualHostingShouldReturnFalseByDefault() throws Exception { - ReadOnlyUsersLDAPRepository usersLDAPRepository = new ReadOnlyUsersLDAPRepository(domainList); - usersLDAPRepository.configure(ldapRepositoryConfiguration(ldapContainer)); + public void isAdministratorShouldReturnTrueWhenConfiguredAndUserIsAdmin(TestSystem testSystem) throws Exception { + assertThat(testee().isAdministrator(testSystem.getAdmin())).isTrue(); + } - assertThat(usersLDAPRepository.supportVirtualHosting()).isFalse(); + @Test + void knownUserShouldBeAbleToLogInWhenPasswordIsCorrectWithVirtualHosting() throws Exception { + assertThat(usersRepository.test(JAMES_USER_MAIL, PASSWORD)).isTrue(); } @Test - void supportVirtualHostingShouldReturnTrueWhenReportedInConfig() throws Exception { - HierarchicalConfiguration<ImmutableNode> configuration = ldapRepositoryConfiguration(ldapContainer); - configuration.addProperty(ReadOnlyUsersLDAPRepository.SUPPORTS_VIRTUAL_HOSTING, "true"); + void testShouldStillWorkAfterRestartingLDAP() throws Exception { + usersRepository.test(JAMES_USER_MAIL, PASSWORD); - ReadOnlyUsersLDAPRepository usersLDAPRepository = new ReadOnlyUsersLDAPRepository(domainList); - usersLDAPRepository.configure(configuration); + DockerLdapSingleton.ldapContainer.pause(); + try { + usersRepository.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(usersLDAPRepository.supportVirtualHosting()).isTrue(); + assertThat(usersRepository.test(JAMES_USER_MAIL, PASSWORD)).isTrue(); } @Test - void supportVirtualHostingShouldReturnFalseWhenReportedInConfig() throws Exception { - HierarchicalConfiguration<ImmutableNode> configuration = ldapRepositoryConfiguration(ldapContainer); - configuration.addProperty(ReadOnlyUsersLDAPRepository.SUPPORTS_VIRTUAL_HOSTING, "false"); + void knownUserShouldNotBeAbleToLogInWhenPasswordIsNotCorrectWithVirtualHosting() throws Exception { + assertThat(usersRepository.test(JAMES_USER, BAD_PASSWORD)).isFalse(); + } - ReadOnlyUsersLDAPRepository usersLDAPRepository = new ReadOnlyUsersLDAPRepository(domainList); - usersLDAPRepository.configure(configuration); + @Test + void unknownUserShouldNotBeAbleToLogInWithVirtualHosting() throws Exception { + assertThat(usersRepository.test(UNKNOWN, BAD_PASSWORD)).isFalse(); + } - assertThat(usersLDAPRepository.supportVirtualHosting()).isFalse(); + @Test + void unknownUserShouldNotBeAbleToLogInWhenPasswordIsCorrectWithVirtualHosting() throws Exception { + assertThat(usersRepository.test(UNKNOWN, PASSWORD)).isFalse(); } @Test - void configureShouldThrowOnNonBooleanValueForSupportsVirtualHosting() { - HierarchicalConfiguration<ImmutableNode> configuration = ldapRepositoryConfiguration(ldapContainer); - configuration.addProperty(ReadOnlyUsersLDAPRepository.SUPPORTS_VIRTUAL_HOSTING, "bad"); + void specialCharacterInUserInputShouldBeSanitized() throws Exception { + Username patternMatchingMultipleUsers = Username.of("j*"); - ReadOnlyUsersLDAPRepository usersLDAPRepository = new ReadOnlyUsersLDAPRepository(domainList); + assertThat(usersRepository.test(patternMatchingMultipleUsers, PASSWORD)).isFalse(); + } - assertThatThrownBy(() -> usersLDAPRepository.configure(configuration)) - .isInstanceOf(ConversionException.class); + @Test + void containsWithGetUserShouldBeTrueWithVirtualHosting() throws Exception { + assertThat(usersRepository.contains(usersRepository.getUsername(JAMES_USER_MAIL.asMailAddress()))).isTrue(); + } + + @Disabled("JAMES-3088 isAdministrator is case sensitive") + @Override + @Test + public void isAdministratorShouldBeCaseInsentive(TestSystem testSystem) throws Exception { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void isAdministratorShouldReturnFalseWhenNotConfigured(TestSystem testSystem) throws Exception { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void addUserShouldThrowWhenSameUsernameWithDifferentCase(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void updateUserShouldThrowWhenAUserIsNoMoreInRepository(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void removeUserShouldBeCaseInsentive(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 Users are provisioned by default from Dockerfile, cannot setup this test case") + @Override + @Test + public void listShouldReturnEmptyIteratorWhenEmptyRepository(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void countUsersShouldReturnNumberOfUsersWhenNotEmptyRepository(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void addUserShouldDisableCaseVariation(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void updateUserShouldAllowToAuthenticateWithNewPassword(TestSystem testSystem){ + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void addUserShouldAddAUserWhenNotEmptyRepository(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void testShouldReturnFalseWhenAUserHasAnIncorrectCasePassword(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void listShouldReturnExactlyUsersInRepository(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void testShouldReturnTrueWhenAUserHasACorrectPassword(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void containsShouldBeCaseInsentiveWhenOriginalValueLowerCased(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void getUserByNameShouldReturnLowerCaseAddedUser(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 Users are provisioned by default from Dockerfile, cannot setup this test case") + @Override + @Test + public void countUsersShouldReturnZeroWhenEmptyRepository() { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void testShouldReturnFalseWhenAUserIsNotInRepository(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void testShouldReturnTrueWhenAUserHasACorrectPasswordAndOtherCaseInDomain(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void addUserShouldDisableCaseVariationWhenOriginalValueLowerCased(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void testShouldReturnTrueWhenAUserHasAnIncorrectCaseName(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void addUserShouldAddAUserWhenEmptyRepository(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void testShouldBeCaseInsentive(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void containsShouldBeCaseInsentive(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void containsShouldPreserveCaseVariation(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void updateUserShouldNotAllowToAuthenticateWithOldPassword(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void getUserByNameShouldReturnAUserWhenContainedInRepository(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void removeUserShouldRemoveAUserWhenPresentInRepository(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void testShouldReturnFalseWhenAUserHasAnIncorrectPassword(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void testShouldReturnFalseWhenAUserIsRemovedFromRepository(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void removeUserShouldBeCaseInsentiveOnCaseVariationUser(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void listShouldReturnLowerCaseUser(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void getUserByNameShouldBeCaseInsentive(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void getUserByNameShouldReturnUserWhenDifferentCase(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void addUserShouldThrowWhenUserAlreadyPresentInRepository(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void testShouldBeCaseInsentiveOnCaseVariationUser(TestSystem testSystem) { } } @Nested - class TestUser { + class WhenDisableVirtualHosting implements AbstractUsersRepositoryContract.WithOutVirtualHostingContract { + @RegisterExtension + UserRepositoryExtension extension = UserRepositoryExtension.withoutVirtualHosting(); + + private ReadOnlyUsersLDAPRepository usersRepository; + + @BeforeEach + void setUp(TestSystem testSystem) throws Exception { + usersRepository = startUsersRepository(ldapRepositoryConfiguration(ldapContainer), testSystem.getDomainList()); + } + + @Override + public AbstractUsersRepository testee() { + return usersRepository; + } @Test void knownUserShouldBeAbleToLogInWhenPasswordIsCorrect() throws Exception { - ReadOnlyUsersLDAPRepository ldapRepository = startUsersRepository(ldapRepositoryConfiguration(ldapContainer)); - assertThat(ldapRepository.test(JAMES_USER, PASSWORD)).isTrue(); + assertThat(usersRepository.test(JAMES_USER, PASSWORD)).isTrue(); } @Test void knownUserShouldNotBeAbleToLogInWhenPasswordIsNotCorrect() throws Exception { - ReadOnlyUsersLDAPRepository ldapRepository = startUsersRepository(ldapRepositoryConfiguration(ldapContainer)); - assertThat(ldapRepository.test(JAMES_USER, BAD_PASSWORD)).isFalse(); + assertThat(usersRepository.test(JAMES_USER, BAD_PASSWORD)).isFalse(); } @Test void unknownUserShouldNotBeAbleToLogIn() throws Exception { - ReadOnlyUsersLDAPRepository ldapRepository = startUsersRepository(ldapRepositoryConfiguration(ldapContainer)); - assertThat(ldapRepository.test(UNKNOWN, BAD_PASSWORD)).isFalse(); + assertThat(usersRepository.test(UNKNOWN, BAD_PASSWORD)).isFalse(); } @Test void unknownUserShouldNotBeAbleToLogInWhenPasswordIsCorrect() throws Exception { - ReadOnlyUsersLDAPRepository ldapRepository = startUsersRepository(ldapRepositoryConfiguration(ldapContainer)); - assertThat(ldapRepository.test(UNKNOWN, PASSWORD)).isFalse(); + assertThat(usersRepository.test(UNKNOWN, PASSWORD)).isFalse(); } @Test - void knownUserShouldBeAbleToLogInWhenPasswordIsCorrectWithVirtualHosting() throws Exception { - ReadOnlyUsersLDAPRepository ldapRepository = startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting(ldapContainer)); - assertThat(ldapRepository.test(JAMES_USER_MAIL, PASSWORD)).isTrue(); + void containsWithGetUserShouldBeTrue() throws Exception { + assertThat(usersRepository.contains(usersRepository.getUsername(JAMES_USER_MAIL.asMailAddress()))).isTrue(); } + @Override @Test - void testShouldListUsers() throws Exception { - ReadOnlyUsersLDAPRepository ldapRepository = startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting(ldapContainer)); - assertThat(ImmutableList.copyOf(ldapRepository.list())) - .containsOnly(JAMES_USER_MAIL); + public void isAdministratorShouldReturnTrueWhenConfiguredAndUserIsAdmin(TestSystem testSystem) throws Exception { + assertThat(testee().isAdministrator(testSystem.getAdmin())).isTrue(); } + @Disabled("JAMES-3088 isAdministrator is case sensitive") + @Override @Test - void testShouldStillWorkAfterRestartingLDAP() throws Exception { - ReadOnlyUsersLDAPRepository ldapRepository = startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting(ldapContainer)); - ldapRepository.test(JAMES_USER_MAIL, PASSWORD); + public void isAdministratorShouldBeCaseInsentive(TestSystem testSystem) throws Exception { + } - 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(); + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void isAdministratorShouldReturnFalseWhenNotConfigured(TestSystem testSystem) throws Exception { + } - assertThat(ldapRepository.test(JAMES_USER_MAIL, PASSWORD)).isTrue(); + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void addUserShouldThrowWhenSameUsernameWithDifferentCase(TestSystem testSystem) { } + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override @Test - void knownUserShouldNotBeAbleToLogInWhenPasswordIsNotCorrectWithVirtualHosting() throws Exception { - ReadOnlyUsersLDAPRepository ldapRepository = startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting(ldapContainer)); - assertThat(ldapRepository.test(JAMES_USER, BAD_PASSWORD)).isFalse(); + public void updateUserShouldThrowWhenAUserIsNoMoreInRepository(TestSystem testSystem) { } + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override @Test - void unknownUserShouldNotBeAbleToLogInWithVirtualHosting() throws Exception { - ReadOnlyUsersLDAPRepository ldapRepository = startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting(ldapContainer)); - assertThat(ldapRepository.test(UNKNOWN, BAD_PASSWORD)).isFalse(); + public void removeUserShouldBeCaseInsentive(TestSystem testSystem) { } + @Disabled("JAMES-3088 Users are provisioned by default from Dockerfile, cannot setup this test case") + @Override @Test - void unknownUserShouldNotBeAbleToLogInWhenPasswordIsCorrectWithVirtualHosting() throws Exception { - ReadOnlyUsersLDAPRepository ldapRepository = startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting(ldapContainer)); - assertThat(ldapRepository.test(UNKNOWN, PASSWORD)).isFalse(); + public void listShouldReturnEmptyIteratorWhenEmptyRepository(TestSystem testSystem) { } + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override @Test - void specialCharacterInUserInputShouldBeSanitized() throws Exception { - Username patternMatchingMultipleUsers = Username.of("j*"); + public void countUsersShouldReturnNumberOfUsersWhenNotEmptyRepository(TestSystem testSystem) { + } - ReadOnlyUsersLDAPRepository ldapRepository = startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting(ldapContainer)); - assertThat(ldapRepository.test(patternMatchingMultipleUsers, PASSWORD)).isFalse(); + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void addUserShouldDisableCaseVariation(TestSystem testSystem) { } + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override @Test - void containsWithGetUserShouldBeTrue() throws Exception { - ReadOnlyUsersLDAPRepository ldapRepository = startUsersRepository(ldapRepositoryConfiguration(ldapContainer)); - assertThat(ldapRepository.contains(ldapRepository.getUsername(JAMES_USER_MAIL.asMailAddress()))).isTrue(); + public void updateUserShouldAllowToAuthenticateWithNewPassword(TestSystem testSystem){ } + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override @Test - void containsWithGetUserShouldBeTrueWithVirtualHosting() throws Exception { - ReadOnlyUsersLDAPRepository ldapRepository = startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting(ldapContainer)); - assertThat(ldapRepository.contains(ldapRepository.getUsername(JAMES_USER_MAIL.asMailAddress()))).isTrue(); + public void addUserShouldAddAUserWhenNotEmptyRepository(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void testShouldReturnFalseWhenAUserHasAnIncorrectCasePassword(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void listShouldReturnExactlyUsersInRepository(TestSystem testSystem) { } - private ReadOnlyUsersLDAPRepository startUsersRepository(HierarchicalConfiguration<ImmutableNode> ldapRepositoryConfiguration) throws Exception { - ReadOnlyUsersLDAPRepository ldapRepository = new ReadOnlyUsersLDAPRepository(domainList); - ldapRepository.configure(ldapRepositoryConfiguration); - ldapRepository.init(); - return ldapRepository; + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void testShouldReturnTrueWhenAUserHasACorrectPassword(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void containsShouldBeCaseInsentiveWhenOriginalValueLowerCased(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void getUserByNameShouldReturnLowerCaseAddedUser(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 Users are provisioned by default from Dockerfile, cannot setup this test case") + @Override + @Test + public void countUsersShouldReturnZeroWhenEmptyRepository() { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void testShouldReturnFalseWhenAUserIsNotInRepository(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void addUserShouldDisableCaseVariationWhenOriginalValueLowerCased(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void testShouldReturnTrueWhenAUserHasAnIncorrectCaseName(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void addUserShouldAddAUserWhenEmptyRepository(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void testShouldBeCaseInsentive(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void containsShouldBeCaseInsentive(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void containsShouldPreserveCaseVariation(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void updateUserShouldNotAllowToAuthenticateWithOldPassword(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void getUserByNameShouldReturnAUserWhenContainedInRepository(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void removeUserShouldRemoveAUserWhenPresentInRepository(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void testShouldReturnFalseWhenAUserHasAnIncorrectPassword(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void testShouldReturnFalseWhenAUserIsRemovedFromRepository(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void removeUserShouldBeCaseInsentiveOnCaseVariationUser(TestSystem testSystem) { } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void listShouldReturnLowerCaseUser(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void getUserByNameShouldBeCaseInsentive(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void getUserByNameShouldReturnUserWhenDifferentCase(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void addUserShouldThrowWhenUserAlreadyPresentInRepository(TestSystem testSystem) { + } + + @Disabled("JAMES-3088 This user-repository is read-only. Modifications are not permitted.") + @Override + @Test + public void testShouldBeCaseInsentiveOnCaseVariationUser(TestSystem testSystem) { + } + } - private HierarchicalConfiguration<ImmutableNode> ldapRepositoryConfiguration(LdapGenericContainer ldapContainer) { - 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"); + @Nested + class SupportVirtualHosting { + + @Test + void supportVirtualHostingShouldReturnFalseByDefault() throws Exception { + ReadOnlyUsersLDAPRepository usersLDAPRepository = new ReadOnlyUsersLDAPRepository(new SimpleDomainList()); + usersLDAPRepository.configure(ldapRepositoryConfiguration(ldapContainer)); + + assertThat(usersLDAPRepository.supportVirtualHosting()).isFalse(); + } + + @Test + void supportVirtualHostingShouldReturnTrueWhenReportedInConfig() throws Exception { + HierarchicalConfiguration<ImmutableNode> configuration = ldapRepositoryConfiguration(ldapContainer); + configuration.addProperty(ReadOnlyUsersLDAPRepository.SUPPORTS_VIRTUAL_HOSTING, "true"); + + ReadOnlyUsersLDAPRepository usersLDAPRepository = new ReadOnlyUsersLDAPRepository(new SimpleDomainList()); + usersLDAPRepository.configure(configuration); + + assertThat(usersLDAPRepository.supportVirtualHosting()).isTrue(); + } + + @Test + void supportVirtualHostingShouldReturnFalseWhenReportedInConfig() throws Exception { + HierarchicalConfiguration<ImmutableNode> configuration = ldapRepositoryConfiguration(ldapContainer); + configuration.addProperty(ReadOnlyUsersLDAPRepository.SUPPORTS_VIRTUAL_HOSTING, "false"); + + ReadOnlyUsersLDAPRepository usersLDAPRepository = new ReadOnlyUsersLDAPRepository(new SimpleDomainList()); + usersLDAPRepository.configure(configuration); + + assertThat(usersLDAPRepository.supportVirtualHosting()).isFalse(); + } + + @Test + void configureShouldThrowOnNonBooleanValueForSupportsVirtualHosting() { + HierarchicalConfiguration<ImmutableNode> configuration = ldapRepositoryConfiguration(ldapContainer); + configuration.addProperty(ReadOnlyUsersLDAPRepository.SUPPORTS_VIRTUAL_HOSTING, "bad"); + + ReadOnlyUsersLDAPRepository usersLDAPRepository = new ReadOnlyUsersLDAPRepository(new SimpleDomainList()); + + assertThatThrownBy(() -> usersLDAPRepository.configure(configuration)) + .isInstanceOf(ConversionException.class); + } + } + + private static ReadOnlyUsersLDAPRepository startUsersRepository(HierarchicalConfiguration<ImmutableNode> ldapRepositoryConfiguration, + DomainList domainList) throws Exception { + ReadOnlyUsersLDAPRepository ldapRepository = new ReadOnlyUsersLDAPRepository(domainList); + ldapRepository.configure(ldapRepositoryConfiguration); + ldapRepository.init(); + return ldapRepository; + } + + private static HierarchicalConfiguration<ImmutableNode> ldapRepositoryConfiguration(LdapGenericContainer ldapContainer) { + PropertyListConfiguration configuration = baseConfiguration(ldapContainer); configuration.addProperty("[@userIdAttribute]", "uid"); - configuration.addProperty("[@userObjectClass]", "inetOrgPerson"); - configuration.addProperty("[@maxRetries]", "1"); - configuration.addProperty("[@retryStartInterval]", "0"); - configuration.addProperty("[@retryMaxInterval]", "2"); - configuration.addProperty("[@retryIntervalScale]", "100"); - configuration.addProperty("[@connectionTimeout]", "100"); - configuration.addProperty("[@readTimeout]", "100"); + configuration.addProperty("[@administratorId]", ADMIN_LOCAL_PART); return configuration; } static HierarchicalConfiguration<ImmutableNode> ldapRepositoryConfigurationWithVirtualHosting(LdapGenericContainer ldapContainer) { + PropertyListConfiguration configuration = baseConfiguration(ldapContainer); + configuration.addProperty("[@userIdAttribute]", "mail"); + configuration.addProperty("supportsVirtualHosting", true); + configuration.addProperty("[@administratorId]", ADMIN.asString()); + return configuration; + } + + private static PropertyListConfiguration baseConfiguration(LdapGenericContainer ldapContainer) { 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]", "1"); configuration.addProperty("[@retryStartInterval]", "0"); configuration.addProperty("[@retryMaxInterval]", "2"); configuration.addProperty("[@retryIntervalScale]", "100"); - configuration.addProperty("supportsVirtualHosting", true); configuration.addProperty("[@connectionTimeout]", "100"); configuration.addProperty("[@readTimeout]", "100"); return configuration; diff --git a/server/data/data-library/src/test/java/org/apache/james/user/lib/AbstractUsersRepositoryContract.java b/server/data/data-library/src/test/java/org/apache/james/user/lib/AbstractUsersRepositoryContract.java index 6c0fd3b..4780b02 100644 --- a/server/data/data-library/src/test/java/org/apache/james/user/lib/AbstractUsersRepositoryContract.java +++ b/server/data/data-library/src/test/java/org/apache/james/user/lib/AbstractUsersRepositoryContract.java @@ -88,7 +88,7 @@ public interface AbstractUsersRepositoryContract { } class TestSystem { - static final Domain DOMAIN = Domain.of("domain"); + static final Domain DOMAIN = Domain.of("james.org"); private final boolean supportVirtualHosting; private final SimpleDomainList domainList; @@ -122,18 +122,22 @@ public interface AbstractUsersRepositoryContract { public SimpleDomainList getDomainList() { return domainList; } + + public Username getAdmin() { + return admin; + } } interface WithVirtualHostingContract extends AbstractUsersRepositoryContract { @Test default void testShouldReturnTrueWhenAUserHasACorrectPasswordAndOtherCaseInDomain(TestSystem testSystem) throws Exception { - testSystem.domainList.addDomain(Domain.of("jAmEs.oRg")); + testSystem.domainList.addDomain(Domain.of("Domain.OrG")); String username = "myuser"; String password = "password"; - testee().addUser(Username.of(username + "@jAmEs.oRg"), password); + testee().addUser(Username.of(username + "@Domain.OrG"), password); - boolean actual = testee().test(Username.of(username + "@james.org"), password); + boolean actual = testee().test(Username.of(username + "@domain.org"), password); assertThat(actual).isTrue(); } --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org