use of com.nexblocks.authguard.service.SessionsService in project AuthGuard by AuthGuard.
the class SessionProviderTest method deleteInvalidToken.
@Test
void deleteInvalidToken() {
final SessionsService sessionsService = Mockito.mock(SessionsService.class);
final SessionProvider sessionProvider = new SessionProvider(sessionsService, sessionsConfig());
final String sessionToken = "session-token";
Mockito.when(sessionsService.deleteByToken(sessionToken)).thenReturn(Optional.empty());
assertThatThrownBy(() -> sessionProvider.delete(AuthRequestBO.builder().token(sessionToken).build())).isInstanceOf(ServiceAuthorizationException.class);
}
use of com.nexblocks.authguard.service.SessionsService in project AuthGuard by AuthGuard.
the class SessionVerifierTest method verifyExpiredSession.
@Test
void verifyExpiredSession() {
final SessionsService sessionsService = Mockito.mock(SessionsService.class);
final SessionVerifier sessionVerifier = new SessionVerifier(sessionsService);
final SessionBO session = SessionBO.builder().id("session-id").sessionToken("token").accountId("account-id").expiresAt(OffsetDateTime.now().minus(Duration.ofMinutes(20))).build();
Mockito.when(sessionsService.getByToken(session.getSessionToken())).thenReturn(Optional.of(session));
final Either<Exception, String> result = sessionVerifier.verifyAccountToken("session-id");
assertThat(result.isLeft());
assertThat(result.getLeft()).isInstanceOf(ServiceAuthorizationException.class);
}
use of com.nexblocks.authguard.service.SessionsService in project AuthGuard by AuthGuard.
the class SessionVerifierTest method verify.
@Test
void verify() {
final SessionsService sessionsService = Mockito.mock(SessionsService.class);
final SessionVerifier sessionVerifier = new SessionVerifier(sessionsService);
final SessionBO session = SessionBO.builder().id("session-id").sessionToken("token").accountId("account-id").expiresAt(OffsetDateTime.now().plus(Duration.ofMinutes(20))).build();
Mockito.when(sessionsService.getByToken(session.getSessionToken())).thenReturn(Optional.of(session));
final Either<Exception, String> accountId = sessionVerifier.verifyAccountToken(session.getSessionToken());
assertThat(accountId.get()).isEqualTo(session.getAccountId());
}
Aggregations