use of io.gravitee.am.model.LoginAttempt in project gravitee-access-management by gravitee-io.
the class LoginAttemptServiceTest method shouldCreateUser_accountLockFirstConnection.
@Test
public void shouldCreateUser_accountLockFirstConnection() {
final LoginAttemptCriteria loginAttemptCriteria = new LoginAttemptCriteria.Builder().client("client-1").domain("domain-1").username("user-1").identityProvider("idp-1").build();
final LoginAttempt loginAttempt = new LoginAttempt();
loginAttempt.setAttempts(1);
final AccountSettings accountSettings = new AccountSettings();
accountSettings.setLoginAttemptsDetectionEnabled(true);
accountSettings.setMaxLoginAttempts(1);
accountSettings.setAccountBlockedDuration(24 * 60 * 60 * 1000);
when(loginAttemptRepository.findByCriteria(loginAttemptCriteria)).thenReturn(Maybe.just(loginAttempt));
when(loginAttemptRepository.update(loginAttempt)).thenReturn(Single.just(loginAttempt));
TestObserver testObserver = loginAttemptService.loginFailed(loginAttemptCriteria, accountSettings).test();
testObserver.awaitTerminalEvent();
testObserver.assertNoErrors();
}
use of io.gravitee.am.model.LoginAttempt in project gravitee-access-management by gravitee-io.
the class LoginAttemptRepositoryTest method shouldDeleteById.
@Test
public void shouldDeleteById() {
LoginAttempt attempt = buildLoginAttempt();
LoginAttempt createdAttempt = repository.create(attempt).blockingGet();
TestObserver<LoginAttempt> testObserver = repository.findById(createdAttempt.getId()).test();
testObserver.awaitTerminalEvent();
testObserver.assertNoErrors();
testObserver.assertValue(l -> l != null);
TestObserver<Void> deleteObserver = repository.delete(createdAttempt.getId()).test();
deleteObserver.awaitTerminalEvent();
deleteObserver.assertNoErrors();
testObserver = repository.findById(createdAttempt.getId()).test();
testObserver.awaitTerminalEvent();
testObserver.assertNoErrors();
testObserver.assertNoValues();
}
use of io.gravitee.am.model.LoginAttempt in project gravitee-access-management by gravitee-io.
the class LoginAttemptRepositoryTest method shouldCreate.
@Test
public void shouldCreate() {
LoginAttempt attempt = buildLoginAttempt();
TestObserver<LoginAttempt> testObserver = repository.create(attempt).test();
testObserver.awaitTerminalEvent();
testObserver.assertNoErrors();
testObserver.assertValue(l -> l.getId() != null);
assertEqualsTo(attempt, testObserver);
}
use of io.gravitee.am.model.LoginAttempt in project gravitee-access-management by gravitee-io.
the class LoginAttemptRepositoryTest method shouldNotFindByCriteria_invalidDomain.
@Test
public void shouldNotFindByCriteria_invalidDomain() {
LoginAttempt attempt = buildLoginAttempt();
repository.create(attempt).blockingGet();
TestObserver<LoginAttempt> testObserver = repository.findByCriteria(new LoginAttemptCriteria.Builder().client(attempt.getClient()).domain("unknown").username(attempt.getUsername()).identityProvider(attempt.getIdentityProvider()).build()).test();
testObserver.awaitTerminalEvent();
testObserver.assertNoErrors();
testObserver.assertNoValues();
}
use of io.gravitee.am.model.LoginAttempt in project gravitee-access-management by gravitee-io.
the class LoginAttemptRepositoryTest method buildLoginAttempt.
private LoginAttempt buildLoginAttempt() {
LoginAttempt attempt = new LoginAttempt();
String random = UUID.randomUUID().toString();
attempt.setAttempts(1);
attempt.setClient("client" + random);
attempt.setDomain("domain" + random);
attempt.setIdentityProvider("idp" + random);
attempt.setUsername("user" + random);
Date createdAt = new Date();
attempt.setCreatedAt(createdAt);
attempt.setUpdatedAt(createdAt);
attempt.setExpireAt(new Date(Instant.now().plusSeconds(60).toEpochMilli()));
return attempt;
}
Aggregations