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);
}
Aggregations