diff options
author | Belen Pruvost <belen.pruvost@sonarsource.com> | 2022-06-30 14:33:29 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-07-01 20:03:06 +0000 |
commit | ff39efb89b4a7f03fef62fd715e0e13f7c7230e5 (patch) | |
tree | 4d74e94cc4cafd1647341cfe4b5a2d5ab3aa1869 /server/sonar-webserver-auth | |
parent | 1fdc44a1f76cdcc179037dd630b43d621df43481 (diff) | |
download | sonarqube-ff39efb89b4a7f03fef62fd715e0e13f7c7230e5.tar.gz sonarqube-ff39efb89b4a7f03fef62fd715e0e13f7c7230e5.zip |
SONAR-16592 - Make email matching case insensitive
Diffstat (limited to 'server/sonar-webserver-auth')
2 files changed, 19 insertions, 1 deletions
diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/UserRegistrarImpl.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/UserRegistrarImpl.java index 0a7c66a1f9b..1baa5cf5fa8 100644 --- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/UserRegistrarImpl.java +++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/UserRegistrarImpl.java @@ -113,7 +113,7 @@ public class UserRegistrarImpl implements UserRegistrar { String externalEmail = userIdentity.getEmail(); - if (!dbEmail.equals(externalEmail)) { + if (!dbEmail.equalsIgnoreCase(externalEmail)) { LOGGER.warn("User with login '{}' tried to login with email '{}' which doesn't match the email on record '{}'", userIdentity.getProviderLogin(), externalEmail, dbEmail); throw failAuthenticationException(userIdentity, source); } diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/UserRegistrarImplTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/UserRegistrarImplTest.java index 97991e5945b..43def63369f 100644 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/UserRegistrarImplTest.java +++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/UserRegistrarImplTest.java @@ -386,6 +386,24 @@ public class UserRegistrarImplTest { } @Test + public void authenticate_and_update_existing_github_user_matching_external_login_if_emails_match_case_insensitive() { + UserDto user = db.users().insertUser(u -> u + .setLogin("Old login") + .setName("Old name") + .setEmail("John@Email.com") + .setExternalId(USER_IDENTITY.getProviderId()) + .setExternalLogin("old identity") + .setExternalIdentityProvider(GH_IDENTITY_PROVIDER.getKey())); + + underTest.register(newUserRegistration()); + + assertThat(db.getDbClient().userDao().selectByUuid(db.getSession(), user.getUuid())) + .extracting(UserDto::getLogin, UserDto::getName, UserDto::getEmail, UserDto::getExternalId, UserDto::getExternalLogin, UserDto::getExternalIdentityProvider, + UserDto::isActive) + .contains(USER_LOGIN, "John", "john@email.com", "ABCD", "johndoo", "github", true); + } + + @Test public void authenticate_and_update_existing_user_matching_external_login_and_emails_mismatch() { UserRegistration registration = UserRegistration.builder() .setUserIdentity(USER_IDENTITY) |