-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make emails case-insensitive in account service
- Loading branch information
1 parent
0d0efb3
commit 2c78825
Showing
2 changed files
with
28 additions
and
0 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 |
---|---|---|
|
@@ -31,6 +31,8 @@ | |
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.argThat; | ||
import static org.mockito.Mockito.atLeastOnce; | ||
import static org.mockito.Mockito.lenient; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
|
@@ -129,6 +131,19 @@ void signUp_withBlacklistedEmail() { | |
service.signUp(new SignUpParams(authUser.getEmail(), authUser.getName()))); | ||
} | ||
|
||
@Test | ||
void signUp_emailCaseInsensitivity() { | ||
val email = "[email protected]"; | ||
val authUser = buildAuthUser(); | ||
authUser.setEmail(email); | ||
val refreshToken = buildRefreshToken(authUser); | ||
when(authUserRepository.findByEmail(any())).thenReturn(Optional.empty()); | ||
when(authUserRepository.save(any())).thenAnswer(i -> i.getArgument(0)); | ||
when(refreshTokenRepository.save(any())).thenReturn(refreshToken); | ||
assertDoesNotThrow(() -> service.signUp(new SignUpParams(authUser.getEmail(), authUser.getName()))); | ||
verify(authUserRepository, atLeastOnce()).save(argThat(a -> a.getEmail().equals(email.toLowerCase()))); | ||
} | ||
|
||
@Test | ||
void signIn_withExistingAccount() throws AccountNotFoundException, TooManySignInAttemptsException { | ||
val authUser = buildAuthUser(); | ||
|
@@ -167,6 +182,17 @@ void signIn_withBlacklistedEmail() { | |
assertThrows(TooManySignInAttemptsException.class, () -> service.signIn(new SignInParams(authUser.getEmail()))); | ||
} | ||
|
||
@Test | ||
void signIn_emailCaseInsensitivity() { | ||
val email = "[email protected]"; | ||
val authUser = buildAuthUser(); | ||
authUser.setEmail(email); | ||
val refreshToken = buildRefreshToken(authUser); | ||
when(authUserRepository.findByEmail(email.toLowerCase())).thenReturn(Optional.of(authUser)); | ||
when(refreshTokenRepository.save(any())).thenReturn(refreshToken); | ||
assertDoesNotThrow(() -> service.signIn(new SignInParams(authUser.getEmail()))); | ||
} | ||
|
||
@Test | ||
void signOut_withInvalidJWT() { | ||
assertThrows(RefreshTokenVerificationException.class, () -> service.signOut("invalid-jwt", "valid-acess-jwt")); | ||
|