add doesNotRevokeFamily test
This commit is contained in:
@@ -281,6 +281,29 @@ 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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user