use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class RestfulPersonAttributeDaoTests method setup.
@Before
public void setup() {
final String data = "{" + " \"name\" :\"casuser\"," + "\"age\" : 29," + "\"messages\": [\"msg 1\", \"msg 2\", \"msg 3\"] " + "}";
this.webServer = new MockWebServer(8085, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE);
this.webServer.start();
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class AccepttoMultifactorDetermineUserAccountStatusActionTests method verifyEmpty.
@Test
public void verifyEmpty(@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());
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)));
try (val webServer = new MockWebServer(5013, 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_DENY);
}
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class AccepttoMultifactorDetermineUserAccountStatusActionTests method verifyOperationFail.
@Test
public void verifyOperationFail(@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", "false", "status", "FAIL", "eguardian_user_id", "cas-user", "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:5014");
try (val webServer = new MockWebServer(5014, 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_DENY);
}
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class AccepttoMultifactorFetchChannelActionTests method verifyGetChannelFails.
@Test
public void verifyGetChannelFails() throws Exception {
val httpRequest = new MockHttpServletRequest();
httpRequest.setRemoteAddr("185.86.151.11");
httpRequest.setLocalAddr("185.88.151.11");
ClientInfoHolder.setClientInfo(new ClientInfo(httpRequest));
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", "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)));
try (val webServer = new MockWebServer(5012, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
webServer.start();
val action = new AccepttoMultifactorFetchChannelAction(casProperties, mfaAccepttoDistributedSessionStore, pub);
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
WebUtils.putAuthentication(CoreAuthenticationTestUtils.getAuthentication("casuser"), context);
RequestContextHolder.setRequestContext(context);
assertThrows(AuthenticationException.class, () -> action.doExecute(context));
}
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class AccepttoMultifactorFetchChannelActionTests method verifyBadChannelStatus.
@Test
public void verifyBadChannelStatus() throws Exception {
val httpRequest = new MockHttpServletRequest();
httpRequest.setRemoteAddr("185.86.151.11");
httpRequest.setLocalAddr("185.88.151.11");
ClientInfoHolder.setClientInfo(new ClientInfo(httpRequest));
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", "rejected", "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)));
try (val webServer = new MockWebServer(5012, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
webServer.start();
val action = new AccepttoMultifactorFetchChannelAction(casProperties, mfaAccepttoDistributedSessionStore, pub);
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
WebUtils.putAuthentication(CoreAuthenticationTestUtils.getAuthentication("casuser"), context);
RequestContextHolder.setRequestContext(context);
assertThrows(AuthenticationException.class, () -> action.doExecute(context));
}
}
Aggregations