use of org.apereo.cas.adaptors.swivel.SwivelTokenCredential 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.apereo.cas.adaptors.swivel.SwivelTokenCredential 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