use of org.springframework.webflow.test.MockRequestContext in project cas by apereo.
the class OneTimeTokenAuthenticationWebflowEventResolverTests method verifyResolver.
@Test
public void verifyResolver() {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(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);
assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, resolver.resolveSingle(context).getId());
}
use of org.springframework.webflow.test.MockRequestContext in project cas by apereo.
the class SwivelAuthenticationHandlerTests method verifyAuthnFails.
@Test
public void verifyAuthnFails() throws Exception {
val data = "<?xml version=\"1.0\" ?>" + "<SASResponse secret=\"MyAdminAgent\" version=\"3.4\">" + "<Version>3.6</Version>\n" + "<Result>FAIL</Result>\n" + "<SessionID>c7379ef1b41f90a4900548a75e13f62a</SessionID>" + "</SASResponse>";
try (val webServer = new MockWebServer(9191, new ByteArrayResource(data.getBytes(UTF_8), "Output"), HttpStatus.OK)) {
webServer.start();
val c = new SwivelTokenCredential("123456");
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
setRequestContext(context);
ExternalContextHolder.setExternalContext(context.getExternalContext());
WebUtils.putAuthentication(CoreAuthenticationTestUtils.getAuthentication(), context);
setRequestContext(context);
assertThrows(FailedLoginException.class, () -> swivelAuthenticationHandler.authenticate(c));
}
}
use of org.springframework.webflow.test.MockRequestContext in project cas by apereo.
the class SwivelAuthenticationHandlerTests method verifyAuthn.
@Test
public void verifyAuthn() throws Exception {
val data = "<?xml version=\"1.0\" ?>" + "<SASResponse secret=\"MyAdminAgent\" version=\"3.4\">" + "<Version>3.6</Version>\n" + "<Result>PASS</Result>\n" + "<SessionID>c7379ef1b41f90a4900548a75e13f62a</SessionID>" + "</SASResponse>";
try (val webServer = new MockWebServer(9191, new ByteArrayResource(data.getBytes(UTF_8), "Output"), HttpStatus.OK)) {
webServer.start();
val c = new SwivelTokenCredential("123456");
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
setRequestContext(context);
ExternalContextHolder.setExternalContext(context.getExternalContext());
WebUtils.putAuthentication(CoreAuthenticationTestUtils.getAuthentication(), context);
setRequestContext(context);
assertNotNull(swivelAuthenticationHandler.authenticate(c));
}
}
use of org.springframework.webflow.test.MockRequestContext in project cas by apereo.
the class LoadSurrogatesListActionTests method verifyGetListView.
@Test
public void verifyGetListView() throws Exception {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
WebUtils.putSurrogateAuthenticationRequest(context, true);
WebUtils.putCredential(context, CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword("casuser"));
assertEquals(CasWebflowConstants.TRANSITION_ID_SURROGATE_VIEW, loadSurrogatesListAction.execute(context).getId());
assertNotNull(WebUtils.getSurrogateAuthenticationAccounts(context));
}
use of org.springframework.webflow.test.MockRequestContext in project cas by apereo.
the class LoadSurrogatesListActionTests method verifySkipAuthenticate.
@Test
public void verifySkipAuthenticate() throws Exception {
val context = new MockRequestContext();
WebUtils.putServiceIntoFlowScope(context, CoreAuthenticationTestUtils.getWebApplicationService());
WebUtils.putSurrogateAuthenticationRequest(context, Boolean.TRUE);
val attributes = new LinkedHashMap<String, List<Object>>();
attributes.put(SurrogateAuthenticationService.AUTHENTICATION_ATTR_SURROGATE_ENABLED, List.of(true));
attributes.putAll(CoreAuthenticationTestUtils.getAttributeRepository().getBackingMap());
val p = CoreAuthenticationTestUtils.getPrincipal("someuser", attributes);
WebUtils.putAuthentication(CoreAuthenticationTestUtils.getAuthentication(p), context);
val request = new MockHttpServletRequest();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
val creds = new SurrogateUsernamePasswordCredential();
creds.setPassword("Mellon");
creds.setUsername("someuser");
creds.setSurrogateUsername("others");
WebUtils.putCredential(context, creds);
val builder = mock(AuthenticationResultBuilder.class);
when(builder.getInitialAuthentication()).thenReturn(Optional.of(CoreAuthenticationTestUtils.getAuthentication("casuser")));
when(builder.collect(any(Authentication.class))).thenReturn(builder);
WebUtils.putAuthenticationResultBuilder(builder, context);
assertEquals(CasWebflowConstants.TRANSITION_ID_SKIP_SURROGATE, loadSurrogatesListAction.execute(context).getId());
}
Aggregations