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