use of org.apereo.cas.util.MockServletContext in project cas by apereo.
the class AccepttoMultifactorDetermineUserAccountStatusActionTests method prepareRequestContext.
private static MockRequestContext prepareRequestContext() {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
request.setRemoteAddr("185.86.151.11");
request.setLocalAddr("185.88.151.11");
request.setCookies(new Cookie("jwt", UUID.randomUUID().toString()));
ClientInfoHolder.setClientInfo(new ClientInfo(request));
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
AccepttoWebflowUtils.setEGuardianUserId(context, "eguardian-userid");
WebUtils.putCredential(context, new AccepttoEmailCredential("cas@example.org"));
return context;
}
use of org.apereo.cas.util.MockServletContext in project cas by apereo.
the class AccepttoApiUtilsTests method verifyAuthenticate.
@Test
public void verifyAuthenticate() throws Exception {
val properties = new AccepttoMultifactorAuthenticationProperties();
properties.setGroupAttribute("group");
properties.setEmailAttribute("email");
properties.setApplicationId("appid");
properties.setSecret("p@$$w0rd");
properties.setRegistrationApiUrl("http://localhost:9285");
properties.setOrganizationId("org-id");
properties.setOrganizationSecret("255724611137f7eb0280dd76b0546eea4bca1c7ba1");
val principal = CoreAuthenticationTestUtils.getPrincipal(Map.of("email", List.of("cas@example.org"), "group", List.of("staff")));
val authentication = CoreAuthenticationTestUtils.getAuthentication(principal);
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
request.setRemoteAddr("185.86.151.11");
request.setLocalAddr("185.88.151.11");
request.setCookies(new Cookie("jwt", UUID.randomUUID().toString()));
ClientInfoHolder.setClientInfo(new ClientInfo(request));
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
AccepttoWebflowUtils.setEGuardianUserId(context, "eguardian-userid");
WebUtils.putCredential(context, new AccepttoEmailCredential("cas@example.org"));
val keyGen = KeyPairGenerator.getInstance("RSA");
val pair = keyGen.generateKeyPair();
val priv = pair.getPrivate();
val pub = pair.getPublic();
val payload = MAPPER.writeValueAsString(Map.of("uid", "casuser"));
val jwt = EncodingUtils.signJwsRSASha512(priv, payload.getBytes(StandardCharsets.UTF_8), Map.of());
var data = MAPPER.writeValueAsString(Map.of("content", new String(jwt, StandardCharsets.UTF_8)));
try (val webServer = new MockWebServer(9285, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
webServer.start();
val results = AccepttoApiUtils.authenticate(authentication, properties, context, pub);
assertNotNull(results);
}
try (val webServer = new MockWebServer(9285, new ByteArrayResource(StringUtils.EMPTY.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
webServer.start();
val results = AccepttoApiUtils.authenticate(authentication, properties, context, pub);
assertTrue(results.isEmpty());
}
}
use of org.apereo.cas.util.MockServletContext in project cas by apereo.
the class U2FAccountSaveRegistrationActionTests method verifyOperation.
@Test
public void verifyOperation() throws Exception {
val id = UUID.randomUUID().toString();
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
WebUtils.putAuthentication(CoreAuthenticationTestUtils.getAuthentication(id), context);
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
WebUtils.putMultifactorAuthenticationProviderIdIntoFlowScope(context, u2fMultifactorAuthenticationProvider);
RequestContextHolder.setRequestContext(context);
ExternalContextHolder.setExternalContext(context.getExternalContext());
assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, u2fStartRegistrationAction.execute(context).getId());
val u2fReg = context.getFlowScope().get("u2fReg", U2FRegistration.class);
deviceRepository.requestDeviceRegistration("fb36YebRZyTcR_p4SWrSI7UIJvB6FP82tkcg5AGHhJM", id, u2fReg.getJsonData());
val tokenResponse = "{\"registrationData\":\"BQQkG0HfMv4hzlfHpaWySCKdvio0-w1zi6s" + "uSu0_QJiL4vE-DwggXFWxuWn7rkae1ZAasYl_YnQny7ldxYoGA9riQL2ast4dMon" + "mEtZ80VYKltXyWevhxR11OwF07GLZUcETjPlNGE8WFuanXXQo6-6cujXTZ6yltF8iME66jb8I3" + "hEwggEbMIHCoAMCAQICCjgtyGkJIYxviTAwCgYIKoZIzj0EAwIwFTETMBEGA1" + "UEAxMKVTJGIElzc3VlcjAaFwswMDAxMDEwMDAwWhcLMDAwMTAxMDAwMFowFTETMBEGA1UEAxMKV" + "TJGIERldmljZTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABE0eSLFD2Bg3YsE--2pDCrvhQ7_5Liwn" + "ssiRSdzgHQHo2RLtnhVJ_EDZkuuzxCeQoSkZBGJkARxjO_bcCitAjDwwCgYIKoZ" + "Izj0EAwIDSAAwRQIhAMGjpo4vFqchRicFf2K7coyeA-ehumLQRlJORW0sLz9zAiALX3jlEaoYEp9vI2" + "2SEyJ9krTmft9T6BbfsF2dyLkP3jBEAiB9VOA7XifeRUNKa9TefQog57-ojDsdWcDrjKTb5GQf0" + "QIgJzxbUiQam_olH10kq3y2FIosS8PTc2LhcotPH7_3uHU\",\"version\":\"U2F_V2\"," + "\"challenge\":\"fb36YebRZyTcR_p4SWrSI7UIJvB6FP82tkcg5AGHhJM\",\"" + "clientData\":\"eyJjaGFsbGVuZ2UiOiJmYjM2WWViUlp5VGNSX3A0U1dyU0k" + "3VUlKdkI2RlA4MnRrY2c1QUdIaEpNIiwib3J" + "pZ2luIjoiaHR0cHM6Ly9tbW9heXllZC51bmljb24ubmV0Ojg0NDMiLCJ0eXAiO" + "iJuYXZpZ2F0b3IuaWQuZmluaXNoRW5yb2xsbWVudCJ9\"}";
request.addParameter("tokenResponse", tokenResponse);
assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, u2fSaveAccountRegistrationAction.execute(context).getId());
assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, u2fCheckAccountRegistrationAction.execute(context).getId());
}
use of org.apereo.cas.util.MockServletContext in project cas by apereo.
the class U2FAccountCheckRegistrationActionTests method verifyOperation.
@Test
public void verifyOperation() throws Exception {
val id = UUID.randomUUID().toString();
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
WebUtils.putAuthentication(CoreAuthenticationTestUtils.getAuthentication(id), context);
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
WebUtils.putMultifactorAuthenticationProviderIdIntoFlowScope(context, u2fMultifactorAuthenticationProvider);
RequestContextHolder.setRequestContext(context);
ExternalContextHolder.setExternalContext(context.getExternalContext());
assertEquals(CasWebflowConstants.TRANSITION_ID_REGISTER, u2fCheckAccountRegistrationAction.execute(context).getId());
}
use of org.apereo.cas.util.MockServletContext in project cas by apereo.
the class U2FStartRegistrationActionTests method verifyOperation.
@Test
public void verifyOperation() throws Exception {
val id = UUID.randomUUID().toString();
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
WebUtils.putAuthentication(CoreAuthenticationTestUtils.getAuthentication(id), context);
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
WebUtils.putMultifactorAuthenticationProviderIdIntoFlowScope(context, u2fMultifactorAuthenticationProvider);
RequestContextHolder.setRequestContext(context);
ExternalContextHolder.setExternalContext(context.getExternalContext());
assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, u2fStartRegistrationAction.execute(context).getId());
assertNotNull(context.getFlowScope().get("u2fReg"));
}
Aggregations