Search in sources :

Example 6 with MfaStateHandler

use of com.nike.cerberus.auth.connector.okta.statehandlers.MfaStateHandler in project cerberus by Nike-Inc.

the class OktaAuthConnectorTest method triggerChallengeSuccess.

@Test
public void triggerChallengeSuccess() throws Exception {
    String stateToken = "state token";
    String deviceId = "device id";
    AuthResponse expectedResponse = mock(AuthResponse.class);
    AuthData expectedData = mock(AuthData.class);
    when(expectedData.getStateToken()).thenReturn(stateToken);
    when(expectedResponse.getData()).thenReturn(expectedData);
    doAnswer(invocation -> {
        MfaStateHandler stateHandler = (MfaStateHandler) invocation.getArguments()[2];
        stateHandler.authenticationResponseFuture.complete(expectedResponse);
        return null;
    }).when(client).challengeFactor(any(), any(), any());
    // do the call
    AuthResponse actualResponse = this.oktaAuthConnector.triggerChallenge(stateToken, deviceId);
    // verify results
    assertEquals(expectedResponse, actualResponse);
    assertEquals(expectedResponse.getData().getStateToken(), actualResponse.getData().getStateToken());
}
Also used : AuthData(com.nike.cerberus.auth.connector.AuthData) MfaStateHandler(com.nike.cerberus.auth.connector.okta.statehandlers.MfaStateHandler) AuthResponse(com.nike.cerberus.auth.connector.AuthResponse) Test(org.junit.Test)

Example 7 with MfaStateHandler

use of com.nike.cerberus.auth.connector.okta.statehandlers.MfaStateHandler in project cerberus by Nike-Inc.

the class OktaAuthConnectorTest method mfaCheckSuccess.

@Test
public void mfaCheckSuccess() throws Exception {
    String stateToken = "state token";
    String deviceId = "device id";
    String otpToken = "otp token";
    AuthResponse expectedResponse = mock(AuthResponse.class);
    when(expectedResponse.getStatus()).thenReturn(AuthStatus.SUCCESS);
    DefaultVerifyPassCodeFactorRequest request = mock(DefaultVerifyPassCodeFactorRequest.class);
    doAnswer(invocation -> {
        request.setPassCode(stateToken);
        request.setStateToken(otpToken);
        return request;
    }).when(client).instantiate(DefaultVerifyPassCodeFactorRequest.class);
    doAnswer(invocation -> {
        MfaStateHandler stateHandler = (MfaStateHandler) invocation.getArguments()[2];
        stateHandler.authenticationResponseFuture.complete(expectedResponse);
        return null;
    }).when(client).verifyFactor(anyString(), isA(DefaultVerifyPassCodeFactorRequest.class), any());
    // do the call
    AuthResponse actualResponse = this.oktaAuthConnector.mfaCheck(stateToken, deviceId, otpToken);
    // verify results
    assertEquals(expectedResponse, actualResponse);
}
Also used : DefaultVerifyPassCodeFactorRequest(com.okta.authn.sdk.impl.resource.DefaultVerifyPassCodeFactorRequest) MfaStateHandler(com.nike.cerberus.auth.connector.okta.statehandlers.MfaStateHandler) AuthResponse(com.nike.cerberus.auth.connector.AuthResponse) Test(org.junit.Test)

Aggregations

MfaStateHandler (com.nike.cerberus.auth.connector.okta.statehandlers.MfaStateHandler)7 AuthResponse (com.nike.cerberus.auth.connector.AuthResponse)6 Test (org.junit.Test)4 DefaultVerifyPassCodeFactorRequest (com.okta.authn.sdk.impl.resource.DefaultVerifyPassCodeFactorRequest)3 ApiException (com.nike.backstopper.exception.ApiException)2 AuthData (com.nike.cerberus.auth.connector.AuthData)2 FactorValidationException (com.okta.authn.sdk.FactorValidationException)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 Before (org.junit.Before)1