Search in sources :

Example 21 with AuthenticationContext

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

the class SMSOTPUtilsTest method testIsSMSOTPMandatoryFromLocalFile.

@Test
public void testIsSMSOTPMandatoryFromLocalFile() throws AuthenticationFailedException {
    AuthenticationContext authenticationContext = new AuthenticationContext();
    authenticationContext.setProperty(IdentityHelperConstants.GET_PROPERTY_FROM_REGISTRY, IdentityHelperConstants.GET_PROPERTY_FROM_REGISTRY);
    authenticationContext.setProperty(SMSOTPConstants.IS_SMSOTP_MANDATORY, "true");
    authenticationContext.setTenantDomain("carbon.super");
    AuthenticatorConfig authenticatorConfig = new AuthenticatorConfig();
    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put(SMSOTPConstants.IS_SMSOTP_MANDATORY, "true");
    when(FileBasedConfigurationBuilder.getInstance()).thenReturn(fileBasedConfigurationBuilder);
    authenticatorConfig.setParameterMap(parameters);
    when(fileBasedConfigurationBuilder.getAuthenticatorBean(anyString())).thenReturn(authenticatorConfig);
    Assert.assertEquals(SMSOTPUtils.isSMSOTPMandatory(authenticationContext, SMSOTPConstants.AUTHENTICATOR_NAME), true);
}
Also used : AuthenticatorConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.AuthenticatorConfig) AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 22 with AuthenticationContext

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

the class SMSOTPUtilsTest method testGetNoOfDigitsFromRegistry.

@Test
public void testGetNoOfDigitsFromRegistry() throws AuthenticationFailedException {
    AuthenticationContext authenticationContext = new AuthenticationContext();
    authenticationContext.setTenantDomain("wso2.org");
    authenticationContext.setProperty(SMSOTPConstants.NO_DIGITS, "4");
    Assert.assertEquals(SMSOTPUtils.getNoOfDigits(authenticationContext, SMSOTPConstants.AUTHENTICATOR_NAME), "4");
}
Also used : AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 23 with AuthenticationContext

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

the class SMSOTPUtilsTest method testGetLoginPageFromXMLFileFromRegistry.

@Test
public void testGetLoginPageFromXMLFileFromRegistry() throws AuthenticationFailedException {
    AuthenticationContext authenticationContext = new AuthenticationContext();
    authenticationContext.setTenantDomain("wso2.org");
    authenticationContext.setProperty(SMSOTPConstants.SMSOTP_AUTHENTICATION_ENDPOINT_URL, SMSOTPConstants.SMS_LOGIN_PAGE);
    Assert.assertEquals(SMSOTPUtils.getLoginPageFromXMLFile(authenticationContext, SMSOTPConstants.AUTHENTICATOR_NAME), "smsotpauthenticationendpoint/smsotp.jsp");
}
Also used : AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 24 with AuthenticationContext

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

the class SMSOTPUtilsTest method testGetBackupCodeFromRegistry.

@Test
public void testGetBackupCodeFromRegistry() throws AuthenticationFailedException {
    AuthenticationContext authenticationContext = new AuthenticationContext();
    authenticationContext.setTenantDomain("wso2.org");
    authenticationContext.setProperty(SMSOTPConstants.BACKUP_CODE, true);
    Assert.assertEquals(SMSOTPUtils.getBackupCode(authenticationContext, SMSOTPConstants.AUTHENTICATOR_NAME), "true");
}
Also used : AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 25 with AuthenticationContext

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

the class SMSOTPUtilsTest method testIsEnableMobileNoUpdateFromRegistry.

@Test
public void testIsEnableMobileNoUpdateFromRegistry() throws AuthenticationFailedException {
    AuthenticationContext authenticationContext = new AuthenticationContext();
    authenticationContext.setTenantDomain("wso2.org");
    authenticationContext.setProperty(SMSOTPConstants.IS_ENABLE_MOBILE_NO_UPDATE, "true");
    Assert.assertEquals(SMSOTPUtils.isEnableMobileNoUpdate(authenticationContext, SMSOTPConstants.AUTHENTICATOR_NAME), true);
}
Also used : AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)18 Test (org.testng.annotations.Test)18 AuthenticationContext (org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext)18 AuthenticationFailedException (org.wso2.carbon.identity.application.authentication.framework.exception.AuthenticationFailedException)9 IOException (java.io.IOException)5 UserStoreException (org.wso2.carbon.user.api.UserStoreException)5 Matchers.anyString (org.mockito.Matchers.anyString)4 UserRealm (org.wso2.carbon.user.api.UserRealm)4 HashMap (java.util.HashMap)2 AuthenticatorConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.AuthenticatorConfig)2 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)2 SMSOTPException (org.wso2.carbon.identity.authenticator.smsotp.exception.SMSOTPException)2 OutputStreamWriter (java.io.OutputStreamWriter)1 MalformedURLException (java.net.MalformedURLException)1 ProtocolException (java.net.ProtocolException)1 LocalApplicationAuthenticator (org.wso2.carbon.identity.application.authentication.framework.LocalApplicationAuthenticator)1 StepConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig)1 InvalidCredentialsException (org.wso2.carbon.identity.application.authentication.framework.exception.InvalidCredentialsException)1 RealmService (org.wso2.carbon.user.core.service.RealmService)1