Search in sources :

Example 6 with EnrolledFactorChannel

use of io.gravitee.am.model.factor.EnrolledFactorChannel in project gravitee-access-management by gravitee-io.

the class CallFactorProviderTest method shouldNotBeValidePhoneNumber_WrongCountry.

@Test
public void shouldNotBeValidePhoneNumber_WrongCountry() {
    when(configuration.countries()).thenReturn(Arrays.asList("US", "GB"));
    EnrolledFactor factor = new EnrolledFactor();
    factor.setChannel(new EnrolledFactorChannel(EnrolledFactorChannel.Type.CALL, "+33615492508"));
    assertFalse(provider.checkSecurityFactor(factor));
}
Also used : EnrolledFactorChannel(io.gravitee.am.model.factor.EnrolledFactorChannel) EnrolledFactor(io.gravitee.am.model.factor.EnrolledFactor) Test(org.junit.Test)

Example 7 with EnrolledFactorChannel

use of io.gravitee.am.model.factor.EnrolledFactorChannel in project gravitee-access-management by gravitee-io.

the class EmailFactorProviderTest method shouldNotVerifyCode_Expire.

@Test
public void shouldNotVerifyCode_Expire() {
    when(configuration.getReturnDigits()).thenReturn(6);
    EnrolledFactor enrolled = new EnrolledFactor();
    Map<String, Object> additionalData = new Maps.MapBuilder(new HashMap()).put(FactorDataKeys.KEY_MOVING_FACTOR, 0).put(FactorDataKeys.KEY_EXPIRE_AT, System.currentTimeMillis() - 600).build();
    enrolled.setSecurity(new EnrolledFactorSecurity(FactorSecurityType.SHARED_SECRET, SHARED_SECRET, additionalData));
    enrolled.setChannel(new EnrolledFactorChannel(EnrolledFactorChannel.Type.EMAIL, RECIPIENT));
    when(factorContext.getData(FactorContext.KEY_ENROLLED_FACTOR, EnrolledFactor.class)).thenReturn(enrolled);
    when(factorContext.getData(FactorContext.KEY_CODE, String.class)).thenReturn(CODE);
    TestObserver<Void> test = cut.verify(factorContext).test();
    test.awaitTerminalEvent();
    test.assertNoValues();
    test.assertError(InvalidCodeException.class);
}
Also used : EnrolledFactorChannel(io.gravitee.am.model.factor.EnrolledFactorChannel) Maps(io.gravitee.common.util.Maps) HashMap(java.util.HashMap) EnrolledFactor(io.gravitee.am.model.factor.EnrolledFactor) EnrolledFactorSecurity(io.gravitee.am.model.factor.EnrolledFactorSecurity) Test(org.junit.Test)

Example 8 with EnrolledFactorChannel

use of io.gravitee.am.model.factor.EnrolledFactorChannel in project gravitee-access-management by gravitee-io.

the class EmailFactorProviderTest method shouldNotVerifyCode_UnknownCode.

@Test
public void shouldNotVerifyCode_UnknownCode() {
    EnrolledFactor enrolled = new EnrolledFactor();
    enrolled.setUpdatedAt(new Date());
    Map<String, Object> additionalData = new Maps.MapBuilder(new HashMap()).put(FactorDataKeys.KEY_MOVING_FACTOR, 0).put(FactorDataKeys.KEY_EXPIRE_AT, System.currentTimeMillis() + 600).build();
    enrolled.setSecurity(new EnrolledFactorSecurity(FactorSecurityType.SHARED_SECRET, SHARED_SECRET, additionalData));
    enrolled.setChannel(new EnrolledFactorChannel(EnrolledFactorChannel.Type.EMAIL, RECIPIENT));
    when(factorContext.getData(FactorContext.KEY_ENROLLED_FACTOR, EnrolledFactor.class)).thenReturn(enrolled);
    when(factorContext.getData(FactorContext.KEY_CODE, String.class)).thenReturn(CODE);
    TestObserver<Void> test = cut.verify(factorContext).test();
    test.awaitTerminalEvent();
    test.assertNoValues();
    test.assertError(InvalidCodeException.class);
}
Also used : EnrolledFactorChannel(io.gravitee.am.model.factor.EnrolledFactorChannel) Maps(io.gravitee.common.util.Maps) HashMap(java.util.HashMap) EnrolledFactor(io.gravitee.am.model.factor.EnrolledFactor) Date(java.util.Date) EnrolledFactorSecurity(io.gravitee.am.model.factor.EnrolledFactorSecurity) Test(org.junit.Test)

Example 9 with EnrolledFactorChannel

use of io.gravitee.am.model.factor.EnrolledFactorChannel in project gravitee-access-management by gravitee-io.

the class SMSFactorProviderTest method shouldValidatePhoneNumber_MultipleCountries.

@Test
public void shouldValidatePhoneNumber_MultipleCountries() {
    when(configuration.countries()).thenReturn(Arrays.asList("US", "FR", "GB"));
    EnrolledFactor factor = new EnrolledFactor();
    factor.setChannel(new EnrolledFactorChannel(EnrolledFactorChannel.Type.SMS, "+33615492508"));
    assertTrue(provider.checkSecurityFactor(factor));
}
Also used : EnrolledFactorChannel(io.gravitee.am.model.factor.EnrolledFactorChannel) EnrolledFactor(io.gravitee.am.model.factor.EnrolledFactor) Test(org.junit.Test)

Example 10 with EnrolledFactorChannel

use of io.gravitee.am.model.factor.EnrolledFactorChannel in project gravitee-access-management by gravitee-io.

the class UserFactorUpdaterTest method shouldNotUpdateEmail_EmailRemoved.

@Test
public void shouldNotUpdateEmail_EmailRemoved() {
    User existingUser = new User();
    existingUser.setEmail("email@domain.org");
    EnrolledFactor factor = new EnrolledFactor();
    factor.setChannel(new EnrolledFactorChannel(EnrolledFactorChannel.Type.EMAIL, existingUser.getEmail()));
    User updatedUser = new User();
    updatedUser.setEmail(null);
    UserFactorUpdater.updateFactors(singletonList(factor), existingUser, updatedUser);
    assertEquals("Email should not be updated", existingUser.getEmail(), factor.getChannel().getTarget());
}
Also used : EnrolledFactorChannel(io.gravitee.am.model.factor.EnrolledFactorChannel) User(io.gravitee.am.model.User) EnrolledFactor(io.gravitee.am.model.factor.EnrolledFactor) Test(org.junit.Test)

Aggregations

EnrolledFactorChannel (io.gravitee.am.model.factor.EnrolledFactorChannel)22 EnrolledFactor (io.gravitee.am.model.factor.EnrolledFactor)21 Test (org.junit.Test)15 EnrolledFactorSecurity (io.gravitee.am.model.factor.EnrolledFactorSecurity)10 User (io.gravitee.am.model.User)8 Attribute (io.gravitee.am.model.scim.Attribute)5 Maps (io.gravitee.common.util.Maps)4 HashMap (java.util.HashMap)4 Date (java.util.Date)3 Address (io.gravitee.am.model.scim.Address)2 Certificate (io.gravitee.am.model.scim.Certificate)2 InvalidCodeException (io.gravitee.am.common.exception.mfa.InvalidCodeException)1 FactorDataKeys (io.gravitee.am.common.factor.FactorDataKeys)1 FactorSecurityType (io.gravitee.am.common.factor.FactorSecurityType)1 FactorContext (io.gravitee.am.factor.api.FactorContext)1 EmailFactorConfiguration (io.gravitee.am.factor.email.EmailFactorConfiguration)1 UpdateEnrolledFactor (io.gravitee.am.gateway.handler.account.model.UpdateEnrolledFactor)1 EmailService (io.gravitee.am.gateway.handler.common.email.EmailService)1 ResourceManager (io.gravitee.am.gateway.handler.manager.resource.ResourceManager)1 UserService (io.gravitee.am.gateway.handler.root.service.user.UserService)1