Search in sources :

Example 1 with MockRequestControlContext

use of org.springframework.webflow.test.MockRequestControlContext in project cas by apereo.

the class AccountManagementWebflowConfigurerTests method verifyOperation.

@Test
public void verifyOperation() {
    assertFalse(casWebflowExecutionPlan.getWebflowConfigurers().isEmpty());
    val flow = (Flow) this.loginFlowDefinitionRegistry.getFlowDefinition(CasWebflowConfigurer.FLOW_ID_LOGIN);
    assertNotNull(flow);
    assertTrue(flow.containsState(CasWebflowConstants.STATE_ID_VIEW_ACCOUNT_SIGNUP));
    assertTrue(flow.containsState(CasWebflowConstants.STATE_ID_SUBMIT_ACCOUNT_REGISTRATION));
    assertTrue(flow.containsState(CasWebflowConstants.STATE_ID_SENT_ACCOUNT_SIGNUP_INFO));
    assertTrue(flow.containsState(CasWebflowConstants.STATE_ID_ACCOUNT_REGISTRATION_SUBFLOW));
    val subflow = (SubflowState) flow.getState(CasWebflowConstants.STATE_ID_ACCOUNT_REGISTRATION_SUBFLOW);
    assertNotNull(subflow);
    val regFlow = (Flow) loginFlowDefinitionRegistry.getFlowDefinition(AccountManagementWebflowConfigurer.FLOW_ID_ACCOUNT_REGISTRATION);
    val context = new MockRequestControlContext(regFlow);
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    RequestContextHolder.setRequestContext(context);
    ExternalContextHolder.setExternalContext(context.getExternalContext());
    val completeState = (ViewState) regFlow.getState(CasWebflowConstants.STATE_ID_COMPLETE_ACCOUNT_REGISTRATION);
    completeState.enter(context);
    assertNotNull(WebUtils.getPasswordPolicyPattern(context));
    assertEquals(2, AccountRegistrationUtils.getAccountRegistrationSecurityQuestionsCount(context));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) SubflowState(org.springframework.webflow.engine.SubflowState) ViewState(org.springframework.webflow.engine.ViewState) MockRequestControlContext(org.springframework.webflow.test.MockRequestControlContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Flow(org.springframework.webflow.engine.Flow) Test(org.junit.jupiter.api.Test)

Example 2 with MockRequestControlContext

use of org.springframework.webflow.test.MockRequestControlContext in project cas by apereo.

the class DefaultLoginWebflowConfigurerTests method verifyWebflowConfigError.

@Test
public void verifyWebflowConfigError() {
    val flow = (Flow) this.loginFlowDefinitionRegistry.getFlowDefinition(CasWebflowConfigurer.FLOW_ID_LOGIN);
    val stopState = (EndState) flow.getState(CasWebflowConstants.STATE_ID_VIEW_WEBFLOW_CONFIG_ERROR);
    val context = new MockRequestControlContext(flow);
    val request = new MockHttpServletRequest();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    context.getFlashScope().put(CasWebflowConstants.ATTRIBUTE_ERROR_ROOT_CAUSE_EXCEPTION, new RuntimeException());
    assertDoesNotThrow(new Executable() {

        @Override
        public void execute() throws Throwable {
            stopState.enter(context);
        }
    });
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) Executable(org.junit.jupiter.api.function.Executable) EndState(org.springframework.webflow.engine.EndState) MockRequestControlContext(org.springframework.webflow.test.MockRequestControlContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Flow(org.springframework.webflow.engine.Flow) Test(org.junit.jupiter.api.Test)

Example 3 with MockRequestControlContext

use of org.springframework.webflow.test.MockRequestControlContext in project cas by apereo.

the class WebAuthnMultifactorWebflowConfigurerTests method verifyCsrfOperation.

@Test
public void verifyCsrfOperation() {
    val webAuthnFlow = (Flow) loginFlowDefinitionRegistry.getFlowDefinition(WebAuthnMultifactorWebflowConfigurer.FLOW_ID_MFA_WEBAUTHN);
    val context = new MockRequestControlContext(webAuthnFlow);
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    RequestContextHolder.setRequestContext(context);
    ExternalContextHolder.setExternalContext(context.getExternalContext());
    WebUtils.putAuthentication(RegisteredServiceTestUtils.getAuthentication(), context);
    WebUtils.putMultifactorAuthenticationProviderIdIntoFlowScope(context, webAuthnMultifactorAuthenticationProvider);
    val registration = (ViewState) webAuthnFlow.getState(CasWebflowConstants.STATE_ID_WEBAUTHN_VIEW_REGISTRATION);
    registration.enter(context);
    assertNotNull(context.getFlowScope().get("_csrf"));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) ViewState(org.springframework.webflow.engine.ViewState) MockRequestControlContext(org.springframework.webflow.test.MockRequestControlContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Flow(org.springframework.webflow.engine.Flow) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with MockRequestControlContext

use of org.springframework.webflow.test.MockRequestControlContext in project cas by apereo.

the class DelegatedAuthenticationWebflowConfigurerTests method verifyOperation.

@Test
public void verifyOperation() {
    assertFalse(casWebflowExecutionPlan.getWebflowConfigurers().isEmpty());
    val flow = (Flow) this.loginFlowDefinitionRegistry.getFlowDefinition(CasWebflowConfigurer.FLOW_ID_LOGIN);
    assertNotNull(flow);
    assertTrue(flow.containsState(CasWebflowConstants.STATE_ID_DELEGATED_AUTHENTICATION_CLIENT_RETRY));
    assertTrue(flow.containsState(CasWebflowConstants.STATE_ID_DELEGATED_AUTHENTICATION));
    val stopState = (ViewState) flow.getState(CasWebflowConstants.STATE_ID_STOP_WEBFLOW);
    val context = new MockRequestControlContext(flow);
    val request = new MockHttpServletRequest();
    request.addParameter("error_description", "fail");
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    context.getFlowScope().put(CasWebflowConstants.ATTRIBUTE_ERROR_ROOT_CAUSE_EXCEPTION, new RuntimeException());
    stopState.enter(context);
    assertTrue(context.getFlowScope().contains("code"));
    assertTrue(context.getFlowScope().contains("description"));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) ViewState(org.springframework.webflow.engine.ViewState) MockRequestControlContext(org.springframework.webflow.test.MockRequestControlContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Flow(org.springframework.webflow.engine.Flow) Test(org.junit.jupiter.api.Test)

Aggregations

lombok.val (lombok.val)4 Test (org.junit.jupiter.api.Test)4 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)4 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)4 MockServletContext (org.springframework.mock.web.MockServletContext)4 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)4 Flow (org.springframework.webflow.engine.Flow)4 MockRequestControlContext (org.springframework.webflow.test.MockRequestControlContext)4 ViewState (org.springframework.webflow.engine.ViewState)3 Executable (org.junit.jupiter.api.function.Executable)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 EndState (org.springframework.webflow.engine.EndState)1 SubflowState (org.springframework.webflow.engine.SubflowState)1