Search in sources :

Example 16 with MockParameterMap

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

the class YubiKeyAuthenticationWebflowEventResolverTests method verifyOperationFails.

@Test
public void verifyOperationFails() {
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    val context = mock(RequestContext.class);
    when(context.getRequestScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getConversationScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getFlowScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getMessageContext()).thenReturn(mock(MessageContext.class));
    when(context.getRequestParameters()).thenReturn(new MockParameterMap());
    when(context.getExternalContext()).thenReturn(new ServletExternalContext(new MockServletContext(), request, response));
    RequestContextHolder.setRequestContext(context);
    ExternalContextHolder.setExternalContext(context.getExternalContext());
    WebUtils.putCredential(context, RegisteredServiceTestUtils.getCredentialsWithDifferentUsernameAndPassword("casuser", "123456"));
    val event = yubikeyAuthenticationWebflowEventResolver.resolveSingle(context);
    assertEquals(CasWebflowConstants.TRANSITION_ID_ERROR, event.getId());
    assertEquals(HttpStatus.UNAUTHORIZED.value(), response.getStatus());
    val support = new EventFactorySupport();
    assertTrue(event.getAttributes().contains(support.getExceptionAttributeName()));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockParameterMap(org.springframework.webflow.test.MockParameterMap) MessageContext(org.springframework.binding.message.MessageContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 17 with MockParameterMap

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

the class YubiKeyAccountSaveRegistrationActionTests method verifyActionFails.

@Test
public void verifyActionFails() throws Exception {
    val context = mock(RequestContext.class);
    when(context.getMessageContext()).thenReturn(mock(MessageContext.class));
    when(context.getFlowScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getRequestParameters()).thenReturn(new MockParameterMap());
    when(context.getConversationScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getRequestParameters()).thenReturn(new MockParameterMap());
    val request = new MockHttpServletRequest();
    when(context.getExternalContext()).thenReturn(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    WebUtils.putMultifactorAuthenticationProviderIdIntoFlowScope(context, new YubiKeyMultifactorAuthenticationProvider());
    WebUtils.putAuthentication(CoreAuthenticationTestUtils.getAuthentication(), context);
    val action = new YubiKeyAccountSaveRegistrationAction(new OpenYubiKeyAccountRegistry(new AcceptAllYubiKeyAccountValidator()));
    assertEquals(CasWebflowConstants.TRANSITION_ID_ERROR, action.execute(context).getId());
}
Also used : lombok.val(lombok.val) OpenYubiKeyAccountRegistry(org.apereo.cas.adaptors.yubikey.registry.OpenYubiKeyAccountRegistry) YubiKeyMultifactorAuthenticationProvider(org.apereo.cas.adaptors.yubikey.YubiKeyMultifactorAuthenticationProvider) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockParameterMap(org.springframework.webflow.test.MockParameterMap) MessageContext(org.springframework.binding.message.MessageContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) AcceptAllYubiKeyAccountValidator(org.apereo.cas.adaptors.yubikey.AcceptAllYubiKeyAccountValidator) Test(org.junit.jupiter.api.Test)

Example 18 with MockParameterMap

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

the class VerifyPasswordlessAccountAuthenticationActionTests method getRequestContext.

private static RequestContext getRequestContext(final String username) {
    val request = new MockHttpServletRequest();
    val exec = new MockFlowExecutionContext(new MockFlowSession(new Flow(CasWebflowConfigurer.FLOW_ID_LOGIN)));
    val context = mock(RequestContext.class);
    when(context.getRequestParameters()).thenReturn(new MockParameterMap().put("username", username));
    when(context.getMessageContext()).thenReturn(mock(MessageContext.class));
    when(context.getFlowScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getConversationScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getFlowExecutionContext()).thenReturn(exec);
    when(context.getExternalContext()).thenReturn(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    return context;
}
Also used : lombok.val(lombok.val) MockFlowExecutionContext(org.springframework.webflow.test.MockFlowExecutionContext) MockFlowSession(org.springframework.webflow.test.MockFlowSession) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockParameterMap(org.springframework.webflow.test.MockParameterMap) MessageContext(org.springframework.binding.message.MessageContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Flow(org.springframework.webflow.engine.Flow)

Example 19 with MockParameterMap

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

the class SwivelAuthenticationWebflowActionTests method verifyAction.

@Test
public void verifyAction() throws Exception {
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    val context = mock(RequestContext.class);
    when(context.getMessageContext()).thenReturn(mock(MessageContext.class));
    when(context.getRequestParameters()).thenReturn(new MockParameterMap());
    when(context.getFlowScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getConversationScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getRequestScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getFlashScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getExternalContext()).thenReturn(new ServletExternalContext(new MockServletContext(), request, response));
    RequestContextHolder.setRequestContext(context);
    ExternalContextHolder.setExternalContext(context.getExternalContext());
    val authn = RegisteredServiceTestUtils.getAuthentication("casuser");
    val builder = mock(AuthenticationResultBuilder.class);
    when(builder.getInitialAuthentication()).thenReturn(Optional.of(authn));
    when(builder.collect(any(Authentication.class))).thenReturn(builder);
    WebUtils.putAuthenticationResultBuilder(builder, context);
    WebUtils.putAuthentication(authn, context);
    WebUtils.putCredential(context, new SwivelTokenCredential("token"));
    assertEquals(CasWebflowConstants.TRANSITION_ID_ERROR, swivelAuthenticationWebflowAction.execute(context).getId());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) Authentication(org.apereo.cas.authentication.Authentication) SwivelTokenCredential(org.apereo.cas.adaptors.swivel.SwivelTokenCredential) MockParameterMap(org.springframework.webflow.test.MockParameterMap) MessageContext(org.springframework.binding.message.MessageContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 20 with MockParameterMap

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

the class SwivelAuthenticationWebflowEventResolverTests method verifyResolver.

@Test
public void verifyResolver() {
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    val context = mock(RequestContext.class);
    when(context.getMessageContext()).thenReturn(mock(MessageContext.class));
    when(context.getFlowScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getRequestParameters()).thenReturn(new MockParameterMap());
    when(context.getConversationScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getRequestScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getFlashScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getExternalContext()).thenReturn(new ServletExternalContext(new MockServletContext(), request, response));
    RequestContextHolder.setRequestContext(context);
    ExternalContextHolder.setExternalContext(context.getExternalContext());
    val authn = RegisteredServiceTestUtils.getAuthentication("casuser");
    val builder = mock(AuthenticationResultBuilder.class);
    when(builder.getInitialAuthentication()).thenReturn(Optional.of(authn));
    when(builder.collect(any(Authentication.class))).thenReturn(builder);
    WebUtils.putAuthenticationResultBuilder(builder, context);
    WebUtils.putAuthentication(authn, context);
    WebUtils.putCredential(context, new SwivelTokenCredential("token"));
    val event = resolver.resolveSingle(context);
    assertEquals(CasWebflowConstants.TRANSITION_ID_ERROR, event.getId());
    val support = new EventFactorySupport();
    assertTrue(event.getAttributes().contains(support.getExceptionAttributeName()));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) Authentication(org.apereo.cas.authentication.Authentication) SwivelTokenCredential(org.apereo.cas.adaptors.swivel.SwivelTokenCredential) MockParameterMap(org.springframework.webflow.test.MockParameterMap) MessageContext(org.springframework.binding.message.MessageContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

MockParameterMap (org.springframework.webflow.test.MockParameterMap)20 MessageContext (org.springframework.binding.message.MessageContext)16 lombok.val (lombok.val)15 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)15 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)15 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)15 MockServletContext (org.springframework.mock.web.MockServletContext)14 Test (org.junit.jupiter.api.Test)9 BeforeEach (org.junit.jupiter.api.BeforeEach)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 Test (org.junit.Test)4 RequestContext (org.springframework.webflow.execution.RequestContext)4 MockExternalContext (org.springframework.webflow.test.MockExternalContext)4 LinkedHashSet (java.util.LinkedHashSet)3 Authentication (org.apereo.cas.authentication.Authentication)3 EventFactorySupport (org.springframework.webflow.action.EventFactorySupport)3 SwivelTokenCredential (org.apereo.cas.adaptors.swivel.SwivelTokenCredential)2 Flow (org.springframework.webflow.engine.Flow)2 MockFlowExecutionContext (org.springframework.webflow.test.MockFlowExecutionContext)2 MockFlowSession (org.springframework.webflow.test.MockFlowSession)2