use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class RestfulSamlIdPMetadataGeneratorWithArtifactsTests method setup.
@BeforeAll
public static void setup() throws Exception {
val document = new SamlIdPMetadataDocument(1000, "CAS", IOUtils.toString(new ClassPathResource("metadata/idp-metadata.xml").getInputStream(), StandardCharsets.UTF_8), IOUtils.toString(new ClassPathResource("metadata/idp-signing.crt").getInputStream(), StandardCharsets.UTF_8), IOUtils.toString(new ClassPathResource("metadata/idp-signing.key").getInputStream(), StandardCharsets.UTF_8), IOUtils.toString(new ClassPathResource("metadata/idp-encryption.crt").getInputStream(), StandardCharsets.UTF_8), IOUtils.toString(new ClassPathResource("metadata/idp-encryption.key").getInputStream(), StandardCharsets.UTF_8));
val entity = MAPPER.writeValueAsString(document);
val resource = new ByteArrayResource(entity.getBytes(StandardCharsets.UTF_8), "Output");
SERVER = new MockWebServer(9443, resource, HttpStatus.OK);
SERVER.start();
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class RestfulSamlRegisteredServiceMetadataResolverTests method verifyRestEndpointProducesMetadata.
@Test
public void verifyRestEndpointProducesMetadata() throws Exception {
val service = new SamlRegisteredService();
service.setName("SAML Wiki Service");
service.setServiceId("https://carmenwiki.osu.edu/shibboleth");
service.setDescription("Testing");
service.setMetadataLocation("rest://");
assertTrue(resolver.supports(service));
assertFalse(resolver.supports(null));
assertFalse(resolver.isAvailable(service));
assertFalse(resolver.isAvailable(null));
val doc = new SamlMetadataDocument();
doc.setId(1);
doc.setName("SAML Document");
doc.setSignature(null);
doc.setValue(IOUtils.toString(new ClassPathResource("sp-metadata.xml").getInputStream(), StandardCharsets.UTF_8));
val entity = MAPPER.writeValueAsString(doc);
try (val webServer = new MockWebServer(8078, new ByteArrayResource(entity.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
webServer.start();
assertTrue(resolver.isAvailable(service));
val resolvers = resolver.resolve(service);
assertEquals(1, resolvers.size());
}
try (val webServer = new MockWebServer(8078, new ByteArrayResource("@$@".getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
webServer.start();
val resolvers = resolver.resolve(service);
assertEquals(0, resolvers.size());
}
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class RestfulSamlIdPMetadataGeneratorTests method verifyOperation.
@Test
public void verifyOperation() throws Exception {
var document = new SamlIdPMetadataDocument();
var entity = MAPPER.writeValueAsString(document);
try (val webServer = new MockWebServer(9453, new ByteArrayResource(entity.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
webServer.start();
assertNotNull(samlIdPMetadataGenerator.generate(Optional.empty()));
}
document.setEncryptionCertificate(UUID.randomUUID().toString());
document.setSigningKey(UUID.randomUUID().toString());
document.setSigningCertificate(UUID.randomUUID().toString());
document.setEncryptionKey(UUID.randomUUID().toString());
document.setMetadata(UUID.randomUUID().toString());
entity = MAPPER.writeValueAsString(document);
try (val webServer = new MockWebServer(9453, new ByteArrayResource(entity.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
webServer.start();
val service = new SamlRegisteredService();
service.setName("TestShib");
service.setId(1000);
assertNotNull(samlIdPMetadataGenerator.generate(Optional.of(service)));
}
try (val webServer = new MockWebServer(9453, new ByteArrayResource("___".getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
webServer.start();
assertNotNull(samlIdPMetadataGenerator.generate(Optional.empty()));
}
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class RestfulSamlIdPMetadataLocatorTests method setup.
@BeforeAll
public static void setup() throws Exception {
val document = new SamlIdPMetadataDocument(1000, "CAS", IOUtils.toString(new ClassPathResource("metadata/idp-metadata.xml").getInputStream(), StandardCharsets.UTF_8), IOUtils.toString(new ClassPathResource("metadata/idp-signing.crt").getInputStream(), StandardCharsets.UTF_8), IOUtils.toString(new ClassPathResource("metadata/idp-signing.key").getInputStream(), StandardCharsets.UTF_8), IOUtils.toString(new ClassPathResource("metadata/idp-encryption.crt").getInputStream(), StandardCharsets.UTF_8), IOUtils.toString(new ClassPathResource("metadata/idp-encryption.key").getInputStream(), StandardCharsets.UTF_8));
val entity = MAPPER.writeValueAsString(document);
val resource = new ByteArrayResource(entity.getBytes(StandardCharsets.UTF_8), "Output");
SERVER = new MockWebServer(9433, resource, HttpStatus.OK);
SERVER.start();
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class PrincipalScimV2ProvisionerActionTests method verifyAction.
@Test
public void verifyAction() throws Exception {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
WebUtils.putAuthentication(CoreAuthenticationTestUtils.getAuthentication(), context);
WebUtils.putCredential(context, CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword());
val user = new UserResource();
user.setActive(true);
user.setDisplayName("CASUser");
user.setId("casuser");
val name = new Name();
name.setGivenName("casuser");
user.setName(name);
val meta = new Meta();
meta.setResourceType("User");
meta.setCreated(Calendar.getInstance());
meta.setLocation(new URI("http://localhost:8218"));
user.setMeta(meta);
val data = MAPPER.writeValueAsString(user);
try (val webServer = new MockWebServer(8218, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
webServer.start();
assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, principalScimProvisionerAction.execute(context).getId());
}
}
Aggregations