WIP: feat(security): implement refresh tokens #49
@@ -304,6 +304,24 @@ class TokenServiceTest {
|
||||
.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