use of org.apereo.inspektr.common.web.ClientInfo in project cas by apereo.
the class AccepttoMultifactorFetchChannelActionTests method verifyOperation.
@Test
public void verifyOperation() throws Exception {
val httpRequest = new MockHttpServletRequest();
httpRequest.setRemoteAddr("185.86.151.11");
httpRequest.setLocalAddr("185.88.151.11");
ClientInfoHolder.setClientInfo(new ClientInfo(httpRequest));
val data = MAPPER.writeValueAsString(CollectionUtils.wrap("channel", "test-channel", "status", "success"));
try (val webServer = new MockWebServer(5011, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
webServer.start();
val action = new AccepttoMultifactorFetchChannelAction(casProperties, mfaAccepttoDistributedSessionStore, mfaAccepttoApiPublicKey);
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);
AccepttoWebflowUtils.setChannel(context, "test-channel");
val result = action.doExecute(context);
assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, result.getId());
assertTrue(context.getRequestScope().contains("accepttoRedirectUrl"));
}
}
use of org.apereo.inspektr.common.web.ClientInfo in project cas by apereo.
the class AccepttoMultifactorFetchChannelActionTests method verifyGetChannel.
@Test
public void verifyGetChannel() 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", "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);
assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, action.doExecute(context).getId());
}
}
use of org.apereo.inspektr.common.web.ClientInfo in project cas by apereo.
the class AccepttoQRCodeValidateWebSocketChannelActionTests method verifyBadPayload.
@Test
public void verifyBadPayload() throws Exception {
val httpRequest = new MockHttpServletRequest();
httpRequest.setRemoteAddr("185.86.151.11");
httpRequest.setLocalAddr("185.88.151.11");
httpRequest.addParameter("channel", "test-channel");
ClientInfoHolder.setClientInfo(new ClientInfo(httpRequest));
try (val webServer = new MockWebServer(5012, new ByteArrayResource(StringUtils.EMPTY.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
webServer.start();
val action = new AccepttoQRCodeValidateWebSocketChannelAction(casProperties, mfaAccepttoDistributedSessionStore);
val context = new MockRequestContext();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), httpRequest, response));
WebUtils.putAuthentication(CoreAuthenticationTestUtils.getAuthentication("casuser"), context);
RequestContextHolder.setRequestContext(context);
AccepttoWebflowUtils.setChannel(context, "test-channel");
val result = action.doExecute(context);
assertEquals(CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE, result.getId());
}
}
use of org.apereo.inspektr.common.web.ClientInfo in project cas by apereo.
the class AccepttoQRCodeValidateWebSocketChannelActionTests method verifyNoSuccess.
@Test
public void verifyNoSuccess() throws Exception {
val httpRequest = new MockHttpServletRequest();
httpRequest.setRemoteAddr("185.86.151.11");
httpRequest.setLocalAddr("185.88.151.11");
httpRequest.addParameter("channel", "test-channel");
ClientInfoHolder.setClientInfo(new ClientInfo(httpRequest));
val data = MAPPER.writeValueAsString(CollectionUtils.wrap("success", "false", "message", "error"));
try (val webServer = new MockWebServer(5012, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
webServer.start();
val action = new AccepttoQRCodeValidateWebSocketChannelAction(casProperties, mfaAccepttoDistributedSessionStore);
val context = new MockRequestContext();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), httpRequest, response));
WebUtils.putAuthentication(CoreAuthenticationTestUtils.getAuthentication("casuser"), context);
RequestContextHolder.setRequestContext(context);
AccepttoWebflowUtils.setChannel(context, "test-channel");
val result = action.doExecute(context);
assertEquals(CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE, result.getId());
}
}
use of org.apereo.inspektr.common.web.ClientInfo in project cas by apereo.
the class SubmitAccountRegistrationActionTests method verifySuccessOperation.
@Test
public void verifySuccessOperation() throws Exception {
val request = new MockHttpServletRequest();
request.setRemoteAddr("127.0.0.1");
request.setLocalAddr("127.0.0.1");
ClientInfoHolder.setClientInfo(new ClientInfo(request));
val context = new MockRequestContext();
request.addParameter("username", "casuser");
request.addParameter("email", "cas@example.org");
request.addParameter("phone", "3477465432");
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
RequestContextHolder.setRequestContext(context);
ExternalContextHolder.setExternalContext(context.getExternalContext());
val results = submitAccountRegistrationAction.execute(context);
assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, results.getId());
}
Aggregations