use of org.apereo.cas.util.MockWebServer 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.apereo.cas.util.MockWebServer 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.apereo.cas.util.MockWebServer in project cas by apereo.
the class CRLDistributionPointRevocationCheckerTests method checkCertificate.
@ParameterizedTest
@MethodSource("getTestParameters")
public void checkCertificate(final CRLDistributionPointRevocationChecker checker, final String[] certFiles, final String crlFile, final GeneralSecurityException expected) throws IOException, InterruptedException {
val file = new File(FileUtils.getTempDirectory(), "ca.crl");
val out = new FileOutputStream(file);
IOUtils.copy(new ClassPathResource(crlFile).getInputStream(), out);
this.webServer = new MockWebServer(8085, new FileSystemResource(file), "text/plain");
this.webServer.start();
LOGGER.debug("Web server listening on port 8085 serving file [{}]", crlFile);
Thread.sleep(500);
BaseCRLRevocationCheckerTests.checkCertificate(checker, certFiles, expected);
checker.close();
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class AccepttoMultifactorDetermineUserAccountStatusActionTests method verifyOperationApprove.
@Test
public void verifyOperationApprove(@Autowired final CasConfigurationProperties casProperties) throws Exception {
val context = prepareRequestContext();
val keyGen = KeyPairGenerator.getInstance("RSA");
val pair = keyGen.generateKeyPair();
val priv = pair.getPrivate();
val pub = pair.getPublic();
val payload = MAPPER.writeValueAsString(Map.of("success", "true", "status", "OK", "eguardian_user_id", "cas-user", "channel", UUID.randomUUID().toString(), "response_code", "approved"));
val jwt = EncodingUtils.signJwsRSASha512(priv, payload.getBytes(StandardCharsets.UTF_8), Map.of());
val data = MAPPER.writeValueAsString(Map.of("content", new String(jwt, StandardCharsets.UTF_8)));
casProperties.getAuthn().getMfa().getAcceptto().setRegistrationApiUrl("http://localhost:5015");
try (val webServer = new MockWebServer(5015, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
webServer.start();
val action = new AccepttoMultifactorDetermineUserAccountStatusAction(casProperties, pub);
val principal = CoreAuthenticationTestUtils.getPrincipal(Map.of("email", List.of("cas@example.org"), "group", List.of("staff")));
val authentication = CoreAuthenticationTestUtils.getAuthentication(principal);
WebUtils.putAuthentication(authentication, context);
RequestContextHolder.setRequestContext(context);
val result = action.doExecute(context);
assertEquals(result.getId(), CasWebflowConstants.TRANSITION_ID_APPROVE);
}
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class AccepttoMultifactorDetermineUserAccountStatusActionTests method verifyOperationSuccess.
@Test
public void verifyOperationSuccess(@Autowired final CasConfigurationProperties casProperties) throws Exception {
val context = prepareRequestContext();
val keyGen = KeyPairGenerator.getInstance("RSA");
val pair = keyGen.generateKeyPair();
val priv = pair.getPrivate();
val pub = pair.getPublic();
val payload = MAPPER.writeValueAsString(Map.of("success", "true", "status", "OK", "eguardian_user_id", "cas-user", "response_code", "success", "channel", UUID.randomUUID().toString()));
val jwt = EncodingUtils.signJwsRSASha512(priv, payload.getBytes(StandardCharsets.UTF_8), Map.of());
val data = MAPPER.writeValueAsString(Map.of("content", new String(jwt, StandardCharsets.UTF_8)));
casProperties.getAuthn().getMfa().getAcceptto().setRegistrationApiUrl("http://localhost:5017");
try (val webServer = new MockWebServer(5017, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
webServer.start();
val action = new AccepttoMultifactorDetermineUserAccountStatusAction(casProperties, pub);
val principal = CoreAuthenticationTestUtils.getPrincipal(Map.of("email", List.of("cas@example.org"), "group", List.of("staff")));
val authentication = CoreAuthenticationTestUtils.getAuthentication(principal);
WebUtils.putAuthentication(authentication, context);
RequestContextHolder.setRequestContext(context);
val result = action.doExecute(context);
assertEquals(result.getId(), CasWebflowConstants.TRANSITION_ID_SUCCESS);
}
}
Aggregations