Search in sources :

Example 11 with RememberDeviceSettings

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

the class DeviceIdentifierHandlerTest method mustDoNext_DeviceNotExists.

@Test
public void mustDoNext_DeviceNotExists() {
    final MFASettings mfaSettings = new MFASettings();
    final RememberDeviceSettings rememberDevice = new RememberDeviceSettings();
    rememberDevice.setActive(true);
    rememberDevice.setDeviceIdentifierId(UUID.randomUUID().toString());
    mfaSettings.setRememberDevice(rememberDevice);
    client.setMfaSettings(mfaSettings);
    spyRoutingContext.put(CLIENT_CONTEXT_KEY, client);
    final User user = new User();
    user.setId(userId);
    spyRoutingContext.put(USER_CONTEXT_KEY, user);
    spyRoutingContext.putParam(DEVICE_ID, "deviceId2");
    spyRoutingContext.putParam(DEVICE_TYPE, "deviceType");
    doReturn(Single.just(true)).when(deviceService).deviceExists(anyString(), anyString(), anyString(), anyString(), anyString());
    handler.handle(spyRoutingContext);
    Assert.assertFalse(spyRoutingContext.session().get(DEVICE_ALREADY_EXISTS_KEY));
    Assert.assertEquals(spyRoutingContext.session().get(DEVICE_ID), "deviceId2");
    Assert.assertEquals(spyRoutingContext.session().get(DEVICE_TYPE), "deviceType");
    verify(spyRoutingContext, times(1)).next();
}
Also used : User(io.gravitee.am.model.User) RememberDeviceSettings(io.gravitee.am.model.RememberDeviceSettings) MFASettings(io.gravitee.am.model.MFASettings) Test(org.junit.Test)

Example 12 with RememberDeviceSettings

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

the class DeviceIdentifierHandlerTest method mustDoNext_deviceIdIsEmpty.

@Test
public void mustDoNext_deviceIdIsEmpty() {
    final MFASettings mfaSettings = new MFASettings();
    final RememberDeviceSettings rememberDevice = new RememberDeviceSettings();
    rememberDevice.setActive(true);
    rememberDevice.setDeviceIdentifierId(deviceIdentifierId);
    mfaSettings.setRememberDevice(rememberDevice);
    client.setMfaSettings(mfaSettings);
    spyRoutingContext.put(CLIENT_CONTEXT_KEY, client);
    final User user = new User();
    user.setId(userId);
    spyRoutingContext.put(USER_CONTEXT_KEY, user);
    handler.handle(spyRoutingContext);
    Assert.assertNull(spyRoutingContext.get(DEVICE_ALREADY_EXISTS_KEY));
    verify(spyRoutingContext, times(1)).next();
    verify(deviceService, times(0)).deviceExists(anyString(), anyString(), anyString(), anyString(), anyString());
}
Also used : User(io.gravitee.am.model.User) RememberDeviceSettings(io.gravitee.am.model.RememberDeviceSettings) MFASettings(io.gravitee.am.model.MFASettings) Test(org.junit.Test)

Example 13 with RememberDeviceSettings

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

the class RememberDeviceHandlerTest method mustDoNext_RememberDeviceSettingsIsNotActive.

@Test
public void mustDoNext_RememberDeviceSettingsIsNotActive() {
    spyRoutingContext.setMethod(HttpMethod.GET);
    final MFASettings mfaSettings = new MFASettings();
    mfaSettings.setRememberDevice(new RememberDeviceSettings());
    client.setMfaSettings(mfaSettings);
    spyRoutingContext.put(CLIENT_CONTEXT_KEY, client);
    handler.handle(spyRoutingContext);
    Assert.assertNull(spyRoutingContext.get(REMEMBER_DEVICE_CONSENT_TIME_SECONDS));
    verify(spyRoutingContext, times(0)).fail(405);
    verify(spyRoutingContext, times(1)).next();
}
Also used : RememberDeviceSettings(io.gravitee.am.model.RememberDeviceSettings) MFASettings(io.gravitee.am.model.MFASettings) Test(org.junit.Test)

Example 14 with RememberDeviceSettings

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

the class RememberDeviceHandlerTest method mustDoNext_defaultDeviceConsentTimeSecond.

@Test
public void mustDoNext_defaultDeviceConsentTimeSecond() {
    spyRoutingContext.setMethod(HttpMethod.GET);
    final MFASettings mfaSettings = new MFASettings();
    final RememberDeviceSettings rememberDevice = new RememberDeviceSettings();
    rememberDevice.setActive(true);
    mfaSettings.setRememberDevice(rememberDevice);
    client.setMfaSettings(mfaSettings);
    spyRoutingContext.put(CLIENT_CONTEXT_KEY, client);
    spyRoutingContext.session().put(DEVICE_ALREADY_EXISTS_KEY, false);
    handler.handle(spyRoutingContext);
    Assert.assertEquals((long) spyRoutingContext.get(REMEMBER_DEVICE_CONSENT_TIME_SECONDS), 36000L);
    verify(spyRoutingContext, times(0)).fail(405);
    verify(spyRoutingContext, times(1)).next();
}
Also used : RememberDeviceSettings(io.gravitee.am.model.RememberDeviceSettings) MFASettings(io.gravitee.am.model.MFASettings) Test(org.junit.Test)

Example 15 with RememberDeviceSettings

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

the class AuthenticationFlowHandlerTest method shouldContinue_user_device_known.

@Test
public void shouldContinue_user_device_known() throws Exception {
    router.route().order(-1).handler(rc -> {
        // set client
        Client client = new Client();
        client.setFactors(Collections.singleton("factor-1"));
        rc.put(ConstantKeys.CLIENT_CONTEXT_KEY, client);
        // set user
        MFASettings mfaSettings = new MFASettings();
        final RememberDeviceSettings rememberDevice = new RememberDeviceSettings();
        rememberDevice.setActive(true);
        mfaSettings.setRememberDevice(rememberDevice);
        rc.session().put(DEVICE_ALREADY_EXISTS_KEY, true);
        client.setMfaSettings(mfaSettings);
        // set user
        EnrolledFactor enrolledFactor = new EnrolledFactor();
        enrolledFactor.setFactorId("factor-1");
        io.gravitee.am.model.User endUser = new io.gravitee.am.model.User();
        endUser.setFactors(Collections.singletonList(enrolledFactor));
        rc.getDelegate().setUser(new User(endUser));
        rc.session().put(ConstantKeys.STRONG_AUTH_COMPLETED_KEY, true);
        rc.next();
    });
    testRequest(HttpMethod.GET, "/login", HttpStatusCode.OK_200, "OK");
}
Also used : User(io.gravitee.am.gateway.handler.common.vertx.web.auth.user.User) RememberDeviceSettings(io.gravitee.am.model.RememberDeviceSettings) EnrolledFactor(io.gravitee.am.model.factor.EnrolledFactor) MFASettings(io.gravitee.am.model.MFASettings) Client(io.gravitee.am.model.oidc.Client) Test(org.junit.Test)

Aggregations

RememberDeviceSettings (io.gravitee.am.model.RememberDeviceSettings)17 MFASettings (io.gravitee.am.model.MFASettings)16 Test (org.junit.Test)16 Client (io.gravitee.am.model.oidc.Client)8 User (io.gravitee.am.gateway.handler.common.vertx.web.auth.user.User)5 User (io.gravitee.am.model.User)4 EnrolledFactor (io.gravitee.am.model.factor.EnrolledFactor)4 JsonObject (io.vertx.core.json.JsonObject)2 Objects (java.util.Objects)1