Search in sources :

Example 1 with SessionNonceCookieUtil.validateNonceCookie

use of org.wso2.carbon.identity.application.authentication.framework.util.SessionNonceCookieUtil.validateNonceCookie in project carbon-identity-framework by wso2.

the class DefaultAuthenticationRequestHandlerTest method testHandleRememberMeOptionFromLoginPage.

@Test(dataProvider = "rememberMeParamProvider")
public void testHandleRememberMeOptionFromLoginPage(String rememberMeParam, boolean expectedResult) throws Exception {
    doReturn(rememberMeParam).when(request).getParameter(FrameworkConstants.RequestParams.REMEMBER_ME);
    AuthenticationContext context = spy(new AuthenticationContext());
    SequenceConfig sequenceConfig = spy(new SequenceConfig());
    when(sequenceConfig.isCompleted()).thenReturn(true);
    ServiceProvider serviceProvider = spy(new ServiceProvider());
    LocalAndOutboundAuthenticationConfig localAndOutboundAuthenticationConfig = spy(new LocalAndOutboundAuthenticationConfig());
    when(localAndOutboundAuthenticationConfig.getAuthenticationType()).thenReturn(ApplicationConstants.AUTH_TYPE_LOCAL);
    serviceProvider.setLocalAndOutBoundAuthenticationConfig(localAndOutboundAuthenticationConfig);
    ApplicationConfig applicationConfig = spy(new ApplicationConfig(serviceProvider));
    sequenceConfig.setApplicationConfig(applicationConfig);
    context.setSequenceConfig(sequenceConfig);
    // mock the context to show that flow is returning back from login page
    when(context.isReturning()).thenReturn(true);
    when(context.getCurrentStep()).thenReturn(0);
    DefaultAuthenticationRequestHandler authenticationRequestHandler = spy(new DefaultAuthenticationRequestHandler());
    // mock session nonce cookie validation
    mockStatic(SessionNonceCookieUtil.class);
    when(SessionNonceCookieUtil.validateNonceCookie(any(), any())).thenReturn(true);
    // Mock conclude flow and post authentication flows to isolate remember me option
    doNothing().when(authenticationRequestHandler).concludeFlow(request, response, context);
    authenticationRequestHandler.handle(request, response, context);
    assertEquals(context.isRememberMe(), expectedResult);
}
Also used : AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) LocalAndOutboundAuthenticationConfig(org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig) ApplicationConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.ApplicationConfig) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) SequenceConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig) Test(org.testng.annotations.Test) PostAuthenticationMgtServiceTest(org.wso2.carbon.identity.application.authentication.framework.services.PostAuthenticationMgtServiceTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 Test (org.testng.annotations.Test)1 ApplicationConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.ApplicationConfig)1 SequenceConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig)1 AuthenticationContext (org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext)1 PostAuthenticationMgtServiceTest (org.wso2.carbon.identity.application.authentication.framework.services.PostAuthenticationMgtServiceTest)1 LocalAndOutboundAuthenticationConfig (org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig)1 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)1