use of com.nexblocks.authguard.service.model.SessionBO in project AuthGuard by AuthGuard.
the class OAuthServiceTest method exchangeAuthorizationCodeAndGetAccount.
@Test
void exchangeAuthorizationCodeAndGetAccount() {
Mockito.when(sessionsService.getByToken(Mockito.any())).thenAnswer(invocation -> {
final SessionBO session = SessionBO.builder().sessionToken(invocation.getArgument(0)).expiresAt(OffsetDateTime.now().plus(Duration.ofMinutes(2))).build();
return Optional.of(session);
});
Mockito.when(accountsService.getByExternalId("1")).thenReturn(Optional.of(AccountBO.builder().id("1").build()));
final TokensResponse actual = oAuthService.exchangeAuthorizationCode("account_test", "random", "code").join();
final TokensResponse expected = testIdentityServer.getSuccessResponse();
expected.setAccountId("1");
assertThat(actual).isEqualTo(expected);
}
use of com.nexblocks.authguard.service.model.SessionBO in project AuthGuard by AuthGuard.
the class OAuthServiceTest method exchangeAuthorizationCode.
@Test
void exchangeAuthorizationCode() {
Mockito.when(sessionsService.getByToken(Mockito.any())).thenAnswer(invocation -> {
final SessionBO session = SessionBO.builder().sessionToken(invocation.getArgument(0)).expiresAt(OffsetDateTime.now().plus(Duration.ofMinutes(2))).build();
return Optional.of(session);
});
final TokensResponse actual = oAuthService.exchangeAuthorizationCode("test", "random", "code").join();
final TokensResponse expected = testIdentityServer.getSuccessResponse();
assertThat(actual).isEqualTo(expected);
}
use of com.nexblocks.authguard.service.model.SessionBO in project AuthGuard by AuthGuard.
the class SessionsServiceImpl method create.
@Override
public SessionBO create(final SessionBO session) {
final SessionDO sessionDO = serviceMapper.toDO(session);
sessionDO.setId(ID.generate());
sessionDO.setSessionToken(cryptographicRandom.base64Url(config.getRandomSize()));
return sessionsRepository.save(sessionDO).thenApply(created -> {
emb.publish(CHANNEL, Messages.created(created));
return serviceMapper.toBO(created);
}).join();
}
use of com.nexblocks.authguard.service.model.SessionBO in project AuthGuard by AuthGuard.
the class SessionsServiceImplTest method deleteByToken.
@Test
void deleteByToken() {
final SessionDO sessionDO = SessionDO.builder().id("session-id").accountId("account").sessionToken("token").data(Collections.singletonMap("key", "value")).build();
Mockito.when(repository.deleteByToken(sessionDO.getSessionToken())).thenReturn(CompletableFuture.completedFuture(Optional.of(sessionDO)));
final SessionBO expected = serviceMapper.toBO(sessionDO);
final Optional<SessionBO> actual = service.deleteByToken(sessionDO.getSessionToken());
assertThat(actual).contains(expected);
}
use of com.nexblocks.authguard.service.model.SessionBO in project AuthGuard by AuthGuard.
the class OAuthServiceTest method exchangeAuthorizationCodeExpiredState.
@Test
void exchangeAuthorizationCodeExpiredState() {
Mockito.when(sessionsService.getByToken(Mockito.any())).thenAnswer(invocation -> {
final SessionBO session = SessionBO.builder().sessionToken(invocation.getArgument(0)).expiresAt(OffsetDateTime.now().minus(Duration.ofMinutes(2))).build();
return Optional.of(session);
});
assertThatThrownBy(() -> oAuthService.exchangeAuthorizationCode("test", "random", "code").join()).hasCauseInstanceOf(ServiceAuthorizationException.class);
}
Aggregations