use of com.nexblocks.authguard.service.model.AuthRequestBO in project AuthGuard by AuthGuard.
the class AuthRouteTest method authenticate.
@Test
void authenticate() {
final AuthRequestDTO requestDTO = randomObject(AuthRequestDTO.class);
final AuthRequestBO requestBO = restMapper.toBO(requestDTO);
final AuthResponseBO tokensBO = AuthResponseBO.builder().token("token").build();
final AuthResponseDTO tokensDTO = mapper().toDTO(tokensBO);
Mockito.when(authenticationService.authenticate(Mockito.eq(requestBO), Mockito.any())).thenReturn(Optional.of(tokensBO));
final ValidatableResponse httpResponse = given().body(requestDTO).post(url("authenticate")).then().statusCode(200).contentType(ContentType.JSON);
final AuthResponseDTO responseBody = httpResponse.extract().response().body().as(AuthResponseDTO.class);
assertThat(responseBody).isEqualTo(tokensDTO);
}
use of com.nexblocks.authguard.service.model.AuthRequestBO in project AuthGuard by AuthGuard.
the class ActionTokenServiceImplTest method generateFromBasicAuth.
@Test
void generateFromBasicAuth() {
final AuthRequestBO authRequest = AuthRequestBO.builder().identifier("username").password("password").build();
final AccountBO account = AccountBO.builder().id("account").build();
Mockito.when(basicAuthProvider.getAccount(authRequest)).thenReturn(Either.right(account));
Mockito.when(accountTokensRepository.save(Mockito.any())).thenReturn(CompletableFuture.completedFuture(null));
final Try<ActionTokenBO> actual = actionTokenService.generateFromBasicAuth(authRequest, "something");
final ActionTokenBO expected = ActionTokenBO.builder().accountId(account.getId()).validFor(Duration.ofMinutes(5).toSeconds()).build();
assertThat(actual.isSuccess());
assertThat(actual.get()).isEqualToIgnoringGivenFields(expected, "token");
assertThat(actual.get().getToken()).isNotNull();
}
use of com.nexblocks.authguard.service.model.AuthRequestBO in project AuthGuard by AuthGuard.
the class AuthenticationServiceImplTest method authenticateLockedAccount.
@Test
void authenticateLockedAccount() {
final String username = "username";
final String password = "password";
final AuthRequestBO authRequest = AuthRequestBO.builder().identifier(username).password(password).build();
final AuthResponseBO tokens = RANDOM.nextObject(AuthResponseBO.class);
final RequestContextBO requestContext = RequestContextBO.builder().build();
Mockito.when(exchangeService.exchange(authRequest, "basic", "accessToken", requestContext)).thenReturn(tokens);
Mockito.when(accountLocksService.getActiveLocksByAccountId(tokens.getEntityId())).thenReturn(Collections.singleton(AccountLockBO.builder().build()));
assertThatThrownBy(() -> authenticationService.authenticate(authRequest, requestContext)).isInstanceOf(ServiceAuthorizationException.class).hasFieldOrPropertyWithValue("errorCode", ErrorCode.ACCOUNT_IS_LOCKED.getCode());
}
use of com.nexblocks.authguard.service.model.AuthRequestBO in project AuthGuard by AuthGuard.
the class AuthenticationServiceImplTest method authenticate.
@Test
void authenticate() {
final String username = "username";
final String password = "password";
final AuthRequestBO authRequest = AuthRequestBO.builder().identifier(username).password(password).build();
final AuthResponseBO tokens = RANDOM.nextObject(AuthResponseBO.class);
final RequestContextBO requestContext = RequestContextBO.builder().build();
Mockito.when(exchangeService.exchange(authRequest, "basic", "accessToken", requestContext)).thenReturn(tokens);
Mockito.when(accountLocksService.getActiveLocksByAccountId(tokens.getEntityId())).thenReturn(Collections.emptyList());
final Optional<AuthResponseBO> result = authenticationService.authenticate(authRequest, requestContext);
assertThat(result).isPresent().contains(tokens);
}
Aggregations