use of org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser in project identity-outbound-auth-sms-otp by wso2-extensions.
the class SMSOTPAuthenticatorTest method testCheckWithBackUpCodes.
@Test
public void testCheckWithBackUpCodes() throws Exception {
mockStatic(IdentityTenantUtil.class);
context.setProperty(SMSOTPConstants.USER_NAME, "admin");
when(IdentityTenantUtil.getTenantId("carbon.super")).thenReturn(-1234);
when(IdentityTenantUtil.getRealmService()).thenReturn(realmService);
when(realmService.getTenantUserRealm(-1234)).thenReturn(userRealm);
when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
when((AuthenticatedUser) context.getProperty(SMSOTPConstants.AUTHENTICATED_USER)).thenReturn(AuthenticatedUser.createLocalAuthenticatedUserFromSubjectIdentifier("admin"));
when(userRealm.getUserStoreManager().getUserClaimValue(MultitenantUtils.getTenantAwareUsername("admin"), SMSOTPConstants.SAVED_OTP_LIST, null)).thenReturn("12345,4568,1234,7896");
AuthenticatedUser user = (AuthenticatedUser) context.getProperty(SMSOTPConstants.AUTHENTICATED_USER);
Whitebox.invokeMethod(smsotpAuthenticator, "checkWithBackUpCodes", context, "1234", user);
}
use of org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser in project identity-outbound-auth-sms-otp by wso2-extensions.
the class SMSOTPAuthenticatorTest method testCheckWithInvalidBackUpCodes.
@Test(expectedExceptions = { AuthenticationFailedException.class })
public void testCheckWithInvalidBackUpCodes() throws Exception {
mockStatic(IdentityTenantUtil.class);
context.setProperty(SMSOTPConstants.USER_NAME, "admin");
when(IdentityTenantUtil.getTenantId("carbon.super")).thenReturn(-1234);
when(IdentityTenantUtil.getRealmService()).thenReturn(realmService);
when(realmService.getTenantUserRealm(-1234)).thenReturn(userRealm);
when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
when((AuthenticatedUser) context.getProperty(SMSOTPConstants.AUTHENTICATED_USER)).thenReturn(AuthenticatedUser.createLocalAuthenticatedUserFromSubjectIdentifier("admin"));
when(userRealm.getUserStoreManager().getUserClaimValue(MultitenantUtils.getTenantAwareUsername("admin"), SMSOTPConstants.SAVED_OTP_LIST, null)).thenReturn("12345,4568,1234,7896");
AuthenticatedUser user = (AuthenticatedUser) context.getProperty(SMSOTPConstants.AUTHENTICATED_USER);
Whitebox.invokeMethod(smsotpAuthenticator, "checkWithBackUpCodes", context, "45698789", user);
}
use of org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser 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);
}
Aggregations