diff --git a/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java b/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java index 6b7e2b63d..1c69c8431 100644 --- a/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java +++ b/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java @@ -47,7 +47,7 @@ public class AsyncChangeEmail implements AsynchronousProcess { service.send(player, MessageKey.USAGE_ADD_EMAIL); } else if (newEmail == null || !validationService.validateEmail(newEmail)) { service.send(player, MessageKey.INVALID_NEW_EMAIL); - } else if (!oldEmail.equals(currentEmail)) { + } else if (!oldEmail.equalsIgnoreCase(currentEmail)) { service.send(player, MessageKey.INVALID_OLD_EMAIL); } else if (!validationService.isEmailFreeForRegistration(newEmail, player)) { service.send(player, MessageKey.EMAIL_ALREADY_USED_ERROR); diff --git a/src/test/java/fr/xephi/authme/process/email/AsyncChangeEmailTest.java b/src/test/java/fr/xephi/authme/process/email/AsyncChangeEmailTest.java index 9c2331ca2..f45aef91f 100644 --- a/src/test/java/fr/xephi/authme/process/email/AsyncChangeEmailTest.java +++ b/src/test/java/fr/xephi/authme/process/email/AsyncChangeEmailTest.java @@ -45,7 +45,7 @@ public class AsyncChangeEmailTest { private ValidationService validationService; @Test - public void shouldAddEmail() { + public void shouldChangeEmail() { // given String newEmail = "new@mail.tld"; given(player.getName()).willReturn("Bobby"); @@ -65,6 +65,28 @@ public class AsyncChangeEmailTest { verify(service).send(player, MessageKey.EMAIL_CHANGED_SUCCESS); } + @Test + public void shouldNotBeCaseSensitiveWhenComparingEmails() { + // given + String newEmail = "newmail@example.com"; + given(player.getName()).willReturn("Debra"); + given(playerCache.isAuthenticated("debra")).willReturn(true); + String oldEmail = "OLD-mail@example.org"; + PlayerAuth auth = authWithMail(oldEmail); + given(playerCache.getAuth("debra")).willReturn(auth); + given(dataSource.updateEmail(auth)).willReturn(true); + given(validationService.validateEmail(newEmail)).willReturn(true); + given(validationService.isEmailFreeForRegistration(newEmail, player)).willReturn(true); + + // when + process.changeEmail(player, "old-mail@example.org", newEmail); + + // then + verify(dataSource).updateEmail(auth); + verify(playerCache).updatePlayer(auth); + verify(service).send(player, MessageKey.EMAIL_CHANGED_SUCCESS); + } + @Test public void shouldShowErrorIfSaveFails() { // given