use of com.nexblocks.authguard.service.model.RequestContextBO 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.RequestContextBO 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