Compare commits
2 Commits
19a5a49cbb
...
2bf369c2ad
| Author | SHA1 | Date | |
|---|---|---|---|
| 2bf369c2ad | |||
| 9af70c33d9 |
@@ -281,6 +281,47 @@ class TokenServiceTest {
|
|||||||
assertEquals(savedToken.getUsedAt(), clock.instant());
|
assertEquals(savedToken.getUsedAt(), clock.instant());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void unusedToken_doesNotRevokeFamily() {
|
||||||
|
TokenFamily tokenFamily = new TokenFamily();
|
||||||
|
tokenFamily.setId(1L);
|
||||||
|
tokenFamily.setUser(createUser(1L, "user", "user"));
|
||||||
|
tokenFamily.setExpiresAt(Instant.now(clock).plusSeconds(10));
|
||||||
|
|
||||||
|
RefreshToken refreshToken = new RefreshToken();
|
||||||
|
refreshToken.setTokenFamily(tokenFamily);
|
||||||
|
refreshToken.setExpiresAt(Instant.now(clock).plusSeconds(10));
|
||||||
|
|
||||||
|
when(refreshTokenRepository.findByHash(any()))
|
||||||
|
.thenReturn(Optional.of(refreshToken));
|
||||||
|
|
||||||
|
tokenService.rotate(rawToken);
|
||||||
|
|
||||||
|
verify(refreshTokenRepository, times(2)).save(tokenCaptor.capture());
|
||||||
|
RefreshToken newToken = tokenCaptor.getAllValues().stream()
|
||||||
|
.filter(t -> t.getUsedAt() == null)
|
||||||
|
.reduce((a, b) -> { throw new AssertionError("expected exactly one unused token saved"); })
|
||||||
|
.orElseThrow(() -> new AssertionError("no unused token was saved"));
|
||||||
|
assertNull(newToken.getTokenFamily().getRevokedAt());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void unusedToken_newTokenIsDifferentFromOldToken() {
|
||||||
|
TokenFamily tokenFamily = new TokenFamily();
|
||||||
|
tokenFamily.setId(1L);
|
||||||
|
tokenFamily.setUser(createUser(1L, "user", "user"));
|
||||||
|
tokenFamily.setExpiresAt(Instant.now(clock).plusSeconds(10));
|
||||||
|
|
||||||
|
RefreshToken refreshToken = new RefreshToken();
|
||||||
|
refreshToken.setTokenHash(rawToken.getBytes());
|
||||||
|
refreshToken.setTokenFamily(tokenFamily);
|
||||||
|
refreshToken.setExpiresAt(Instant.now(clock).plusSeconds(10));
|
||||||
|
|
||||||
|
when(refreshTokenRepository.findByHash(any()))
|
||||||
|
.thenReturn(Optional.of(refreshToken));
|
||||||
|
|
||||||
|
TokenService.Rotation rotation = tokenService.rotate(rawToken);
|
||||||
|
assertNotEquals(rawToken, rotation.newRefreshToken());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user