Search in sources :

Example 6 with SessionsService

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);
}
Also used : SessionsService(com.nexblocks.authguard.service.SessionsService) Test(org.junit.jupiter.api.Test)

Example 7 with SessionsService

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);
}
Also used : SessionsService(com.nexblocks.authguard.service.SessionsService) ServiceAuthorizationException(com.nexblocks.authguard.service.exceptions.ServiceAuthorizationException) SessionBO(com.nexblocks.authguard.service.model.SessionBO) Test(org.junit.jupiter.api.Test)

Example 8 with SessionsService

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());
}
Also used : SessionsService(com.nexblocks.authguard.service.SessionsService) ServiceAuthorizationException(com.nexblocks.authguard.service.exceptions.ServiceAuthorizationException) SessionBO(com.nexblocks.authguard.service.model.SessionBO) Test(org.junit.jupiter.api.Test)

Aggregations

SessionsService (com.nexblocks.authguard.service.SessionsService)8 Test (org.junit.jupiter.api.Test)7 ServiceAuthorizationException (com.nexblocks.authguard.service.exceptions.ServiceAuthorizationException)3 SessionBO (com.nexblocks.authguard.service.model.SessionBO)2 TestIdentityServer (com.nexblocks.authguard.jwt.oauth.TestIdentityServer)1 ImmutableOAuthConfiguration (com.nexblocks.authguard.jwt.oauth.config.ImmutableOAuthConfiguration)1 AccountsService (com.nexblocks.authguard.service.AccountsService)1