-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUG] 🐛 Fix conflict when getting by mail a user with a similar mail
Signed-off-by: Cécile Chemin <[email protected]>
- Loading branch information
Showing
3 changed files
with
106 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,9 +15,11 @@ | |
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import fr.insee.sugoi.ldap.utils.config.LdapConfigKeys; | ||
import fr.insee.sugoi.model.*; | ||
import fr.insee.sugoi.model.exceptions.MultipleUserWithSameMailException; | ||
import fr.insee.sugoi.model.fixtures.StoreMappingFixture; | ||
import fr.insee.sugoi.model.paging.PageResult; | ||
import fr.insee.sugoi.model.paging.PageableResult; | ||
|
@@ -371,4 +373,44 @@ public void userWithoutPasswordShouldHaveValueHasPassword() { | |
ldapReaderStore.getUser("agarder").get().getAttributes().get("hasPassword"), | ||
is(false)); | ||
} | ||
|
||
@Test | ||
@DisplayName( | ||
"Given a user which mail is unique in the realm" | ||
+ "the user should be retrievable via its mail") | ||
public void getUserByMailTest() { | ||
assertThat( | ||
"Should be the user mail1", | ||
ldapReaderStore.getUserByMail("[email protected]").get().getUsername(), | ||
is("mail1")); | ||
} | ||
|
||
@Test | ||
@DisplayName( | ||
"Given a user which mail is unique in the realm " | ||
+ "even though his mail is a sub of another user mail " | ||
+ "the user should be retrievable via its mail") | ||
public void getUserByMailWithSubMailTest() { | ||
assertThat( | ||
"Should be the user mailsub", | ||
ldapReaderStore.getUserByMail("[email protected]").get().getUsername(), | ||
is("mailsub")); | ||
} | ||
|
||
@Test | ||
@DisplayName("Given we search a user by a mail that does not exist, " + "no user should be given") | ||
public void getNoneExistingUserByMailTest() { | ||
assertThat( | ||
"Should not get a user", | ||
ldapReaderStore.getUserByMail("[email protected]").isEmpty(), | ||
is(true)); | ||
} | ||
|
||
@Test | ||
@DisplayName("Given several users have the same mail, " + "an exception should be raised") | ||
public void getConflictingMailUserTest() { | ||
assertThrows( | ||
MultipleUserWithSameMailException.class, | ||
() -> ldapReaderStore.getUserByMail("[email protected]")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -397,6 +397,61 @@ pwdReset: false | |
uid: havepwdreset | ||
cn: havepwdreset | ||
|
||
dn: uid=mail1,ou=contacts,ou=clients_domaine1,o=insee,c=fr | ||
objectClass: top | ||
objectClass: inseeCompte | ||
objectClass: inseeContact | ||
objectClass: inseeAttributsAuthentification | ||
objectClass: inseeAttributsHabilitation | ||
objectClass: inseeAttributsCommunication | ||
uid: mail1 | ||
cn: mail1 | ||
mail: [email protected] | ||
|
||
dn: uid=mailsub,ou=contacts,ou=clients_domaine1,o=insee,c=fr | ||
objectClass: top | ||
objectClass: inseeCompte | ||
objectClass: inseeContact | ||
objectClass: inseeAttributsAuthentification | ||
objectClass: inseeAttributsHabilitation | ||
objectClass: inseeAttributsCommunication | ||
uid: mailsub | ||
cn: mailsub | ||
mail: [email protected] | ||
|
||
dn: uid=mailext,ou=contacts,ou=clients_domaine1,o=insee,c=fr | ||
objectClass: top | ||
objectClass: inseeCompte | ||
objectClass: inseeContact | ||
objectClass: inseeAttributsAuthentification | ||
objectClass: inseeAttributsHabilitation | ||
objectClass: inseeAttributsCommunication | ||
uid: mailext | ||
cn: mailext | ||
mail: [email protected] | ||
|
||
dn: uid=mailconflict1,ou=contacts,ou=clients_domaine1,o=insee,c=fr | ||
objectClass: top | ||
objectClass: inseeCompte | ||
objectClass: inseeContact | ||
objectClass: inseeAttributsAuthentification | ||
objectClass: inseeAttributsHabilitation | ||
objectClass: inseeAttributsCommunication | ||
uid: mailconflict1 | ||
cn: mailconflict1 | ||
mail: [email protected] | ||
|
||
dn: uid=mailconflict2,ou=contacts,ou=clients_domaine1,o=insee,c=fr | ||
objectClass: top | ||
objectClass: inseeCompte | ||
objectClass: inseeContact | ||
objectClass: inseeAttributsAuthentification | ||
objectClass: inseeAttributsHabilitation | ||
objectClass: inseeAttributsCommunication | ||
uid: mailconflict2 | ||
cn: mailconflict2 | ||
mail: [email protected] | ||
|
||
dn: uid=testo,ou=organisations,ou=clients_domaine1,o=insee,c=fr | ||
objectClass: top | ||
objectClass: inseeOrganisation | ||
|