use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class RestSamlRegisteredServiceMetadataResolverTests method setup.
@Before
@SneakyThrows
public void setup() {
final SamlMetadataDocument 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));
final String data = MAPPER.writeValueAsString(doc);
this.webServer = new MockWebServer(8078, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_XML_VALUE);
this.webServer.start();
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class RestfulPrincipalFactoryTests method verifyBadResponse.
@Test
public void verifyBadResponse() {
try (val webServer = new MockWebServer(9157, new ByteArrayResource("abcde123456".getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
webServer.start();
val props = new RestEndpointProperties();
props.setUrl("http://localhost:9157");
val factory = PrincipalFactoryUtils.newRestfulPrincipalFactory(props);
assertThrows(IllegalArgumentException.class, () -> factory.createPrincipal("casuser", CollectionUtils.wrap("name", List.of("CAS"))));
}
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class RestfulPrincipalFactoryTests method verifyAction.
@Test
public void verifyAction() throws Exception {
val entity = MAPPER.writeValueAsString(CoreAuthenticationTestUtils.getPrincipal("casuser"));
try (val webServer = new MockWebServer(9155, new ByteArrayResource(entity.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
webServer.start();
val props = new RestEndpointProperties();
props.setUrl("http://localhost:9155");
val factory = PrincipalFactoryUtils.newRestfulPrincipalFactory(props);
val p = factory.createPrincipal("casuser", CollectionUtils.wrap("name", List.of("CAS")));
assertEquals("casuser", p.getId());
assertEquals(5, p.getAttributes().size());
}
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class RestfulIPAddressIntelligenceServiceTests method verifyBannedOperation.
@Test
public void verifyBannedOperation() {
try (val webServer = new MockWebServer(9304, new ByteArrayResource(StringUtils.EMPTY.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.FORBIDDEN)) {
webServer.start();
val props = new AdaptiveAuthenticationProperties();
props.getIpIntel().getRest().setUrl("http://localhost:9304");
val service = new RestfulIPAddressIntelligenceService(props);
val result = service.examine(new MockRequestContext(), "1.2.3.4");
assertNotNull(result);
assertTrue(result.isBanned());
}
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class RestfulIPAddressIntelligenceServiceTests method verifyRankedOperation.
@Test
public void verifyRankedOperation() {
try (val webServer = new MockWebServer(9306, new ByteArrayResource("12.435".getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.PRECONDITION_REQUIRED)) {
webServer.start();
val props = new AdaptiveAuthenticationProperties();
props.getIpIntel().getRest().setUrl("http://localhost:9306");
var service = new RestfulIPAddressIntelligenceService(props);
var result = service.examine(new MockRequestContext(), "1.2.3.4");
assertNotNull(result);
assertTrue(result.isRanked());
props.getPolicy().setRejectIpAddresses("123\\..*");
service = new RestfulIPAddressIntelligenceService(props);
result = service.examine(new MockRequestContext(), "123.1.2.3");
assertNotNull(result);
assertTrue(result.isBanned());
}
}
Aggregations