Search in sources :

Example 1 with AuthenticatorFlowStatus

use of org.wso2.carbon.identity.application.authentication.framework.AuthenticatorFlowStatus in project identity-outbound-auth-sms-otp by wso2-extensions.

the class SMSOTPAuthenticatorTest method testProcessWithLogoutFalse.

@Test
public void testProcessWithLogoutFalse() throws Exception {
    mockStatic(FederatedAuthenticatorUtil.class);
    mockStatic(SMSOTPUtils.class);
    mockStatic(FrameworkUtils.class);
    when(context.isLogoutRequest()).thenReturn(false);
    when(httpServletRequest.getParameter(SMSOTPConstants.MOBILE_NUMBER)).thenReturn("true");
    context.setTenantDomain("carbon.super");
    when((AuthenticatedUser) context.getProperty(SMSOTPConstants.AUTHENTICATED_USER)).thenReturn(AuthenticatedUser.createLocalAuthenticatedUserFromSubjectIdentifier("admin"));
    FederatedAuthenticatorUtil.setUsernameFromFirstStep(context);
    when(SMSOTPUtils.isSMSOTPMandatory(context, SMSOTPConstants.AUTHENTICATOR_NAME)).thenReturn(true);
    when(SMSOTPUtils.getErrorPageFromXMLFile(context, SMSOTPConstants.AUTHENTICATOR_NAME)).thenReturn(SMSOTPConstants.ERROR_PAGE);
    when(SMSOTPUtils.isSendOTPDirectlyToMobile(context, SMSOTPConstants.AUTHENTICATOR_NAME)).thenReturn(false);
    when(FrameworkUtils.getQueryStringWithFrameworkContextId(context.getQueryParams(), context.getCallerSessionKey(), context.getContextIdentifier())).thenReturn(null);
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    Whitebox.invokeMethod(smsotpAuthenticator, "processSMSOTPFlow", context, httpServletRequest, httpServletResponse, false, "John@carbon.super", "", "carbon.super", SMSOTPConstants.ERROR_PAGE);
    verify(httpServletResponse).sendRedirect(captor.capture());
    AuthenticatorFlowStatus status = spy.process(httpServletRequest, httpServletResponse, context);
    Assert.assertTrue(captor.getValue().contains(SMSOTPConstants.SEND_OTP_DIRECTLY_DISABLE));
    Assert.assertEquals(status, AuthenticatorFlowStatus.INCOMPLETE);
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) AuthenticatorFlowStatus(org.wso2.carbon.identity.application.authentication.framework.AuthenticatorFlowStatus) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with AuthenticatorFlowStatus

use of org.wso2.carbon.identity.application.authentication.framework.AuthenticatorFlowStatus in project identity-outbound-auth-sms-otp by wso2-extensions.

the class SMSOTPAuthenticatorTest method testProcessWithLogout.

@Test
public void testProcessWithLogout() throws AuthenticationFailedException, LogoutFailedException {
    mockStatic(FederatedAuthenticatorUtil.class);
    mockStatic(SMSOTPUtils.class);
    mockStatic(FrameworkUtils.class);
    when(context.isLogoutRequest()).thenReturn(false);
    when(httpServletRequest.getParameter(SMSOTPConstants.CODE)).thenReturn("");
    context.setTenantDomain("carbon.super");
    when((AuthenticatedUser) context.getProperty(SMSOTPConstants.AUTHENTICATED_USER)).thenReturn(AuthenticatedUser.createLocalAuthenticatedUserFromSubjectIdentifier("admin"));
    FederatedAuthenticatorUtil.setUsernameFromFirstStep(context);
    when(SMSOTPUtils.isSMSOTPMandatory(context, SMSOTPConstants.AUTHENTICATOR_NAME)).thenReturn(true);
    when(SMSOTPUtils.getErrorPageFromXMLFile(context, SMSOTPConstants.AUTHENTICATOR_NAME)).thenReturn(SMSOTPConstants.ERROR_PAGE);
    when(SMSOTPUtils.isSendOTPDirectlyToMobile(context, SMSOTPConstants.AUTHENTICATOR_NAME)).thenReturn(false);
    when(FrameworkUtils.getQueryStringWithFrameworkContextId(context.getQueryParams(), context.getCallerSessionKey(), context.getContextIdentifier())).thenReturn(null);
    when(SMSOTPUtils.getBackupCode(context, SMSOTPConstants.AUTHENTICATOR_NAME)).thenReturn("false");
    AuthenticatorFlowStatus status = spy.process(httpServletRequest, httpServletResponse, context);
    Assert.assertEquals(status, AuthenticatorFlowStatus.INCOMPLETE);
}
Also used : AuthenticatorFlowStatus(org.wso2.carbon.identity.application.authentication.framework.AuthenticatorFlowStatus) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with AuthenticatorFlowStatus

use of org.wso2.carbon.identity.application.authentication.framework.AuthenticatorFlowStatus in project identity-outbound-auth-sms-otp by wso2-extensions.

the class SMSOTPAuthenticatorTest method testProcessWithLogoutTrue.

@Test
public void testProcessWithLogoutTrue() throws AuthenticationFailedException, LogoutFailedException {
    when(context.isLogoutRequest()).thenReturn(true);
    AuthenticatorFlowStatus status = smsotpAuthenticator.process(httpServletRequest, httpServletResponse, context);
    Assert.assertEquals(status, AuthenticatorFlowStatus.SUCCESS_COMPLETED);
}
Also used : AuthenticatorFlowStatus(org.wso2.carbon.identity.application.authentication.framework.AuthenticatorFlowStatus) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 Test (org.testng.annotations.Test)3 AuthenticatorFlowStatus (org.wso2.carbon.identity.application.authentication.framework.AuthenticatorFlowStatus)3 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)2 Matchers.anyString (org.mockito.Matchers.anyString)1