Search in sources :

Example 1 with LoginAttempt

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();
}
Also used : AccountSettings(io.gravitee.am.model.account.AccountSettings) LoginAttemptCriteria(io.gravitee.am.repository.management.api.search.LoginAttemptCriteria) LoginAttempt(io.gravitee.am.model.LoginAttempt) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 2 with LoginAttempt

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();
}
Also used : LoginAttempt(io.gravitee.am.model.LoginAttempt) Test(org.junit.Test) AbstractManagementTest(io.gravitee.am.repository.management.AbstractManagementTest)

Example 3 with LoginAttempt

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);
}
Also used : LoginAttempt(io.gravitee.am.model.LoginAttempt) Test(org.junit.Test) AbstractManagementTest(io.gravitee.am.repository.management.AbstractManagementTest)

Example 4 with LoginAttempt

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();
}
Also used : LoginAttemptCriteria(io.gravitee.am.repository.management.api.search.LoginAttemptCriteria) LoginAttempt(io.gravitee.am.model.LoginAttempt) Test(org.junit.Test) AbstractManagementTest(io.gravitee.am.repository.management.AbstractManagementTest)

Example 5 with LoginAttempt

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;
}
Also used : LoginAttempt(io.gravitee.am.model.LoginAttempt) Date(java.util.Date)

Aggregations

LoginAttempt (io.gravitee.am.model.LoginAttempt)16 Test (org.junit.Test)10 AbstractManagementTest (io.gravitee.am.repository.management.AbstractManagementTest)8 LoginAttemptCriteria (io.gravitee.am.repository.management.api.search.LoginAttemptCriteria)7 AccountSettings (io.gravitee.am.model.account.AccountSettings)3 Domain (io.gravitee.am.model.Domain)2 IdentityProvider (io.gravitee.am.model.IdentityProvider)2 ApplicationIdentityProvider (io.gravitee.am.model.idp.ApplicationIdentityProvider)2 Client (io.gravitee.am.model.oidc.Client)2 Maybe (io.reactivex.Maybe)2 TestObserver (io.reactivex.observers.TestObserver)2 Date (java.util.Date)2 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 ConstantKeys (io.gravitee.am.common.utils.ConstantKeys)1 RandomString (io.gravitee.am.common.utils.RandomString)1 IdentityProviderManager (io.gravitee.am.gateway.handler.common.auth.idp.IdentityProviderManager)1 SpyRoutingContext (io.gravitee.am.gateway.handler.root.resources.handler.dummies.SpyRoutingContext)1 MFASettings (io.gravitee.am.model.MFASettings)1 RepositoryIllegalQueryException (io.gravitee.am.repository.jdbc.exceptions.RepositoryIllegalQueryException)1 AbstractJdbcRepository (io.gravitee.am.repository.jdbc.management.AbstractJdbcRepository)1