use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class RestfulDelegatedClientFactoryTests method verifyWrongStatusCode.
@Test
public void verifyWrongStatusCode() {
val props = new CasConfigurationProperties();
props.getAuthn().getPac4j().getRest().setUrl("http://localhost:9212");
val factory = new RestfulDelegatedClientFactory(props);
try (val webServer = new MockWebServer(9212, HttpStatus.EXPECTATION_FAILED)) {
webServer.start();
val clientsFound = factory.build();
assertNotNull(clientsFound);
assertTrue(clientsFound.isEmpty());
}
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class UrlResourceMetadataResolverTests method verifyResolverResolvesFailsAccess.
@Test
public void verifyResolverResolvesFailsAccess() throws Exception {
try (val webServer = new MockWebServer(9155, new ClassPathResource("sample-metadata.xml"), HttpStatus.OK)) {
webServer.start();
val props = new SamlIdPProperties();
props.getMetadata().getFileSystem().setLocation(new FileSystemResource(FileUtils.getTempDirectory()).getFile().getCanonicalPath());
val service = new SamlRegisteredService();
service.setAccessStrategy(new DefaultRegisteredServiceAccessStrategy(false, false));
val resolver = new UrlResourceMetadataResolver(props, openSamlConfigBean);
service.setName("TestShib");
service.setId(1000);
service.setMetadataLocation("http://localhost:9155");
assertThrows(SamlException.class, () -> resolver.resolve(service));
}
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class UrlResourceMetadataResolverTests method verifyResolverResolves.
@Test
public void verifyResolverResolves() throws Exception {
try (val webServer = new MockWebServer(9155, new ClassPathResource("sample-metadata.xml"), HttpStatus.OK)) {
webServer.start();
val props = new SamlIdPProperties();
props.getMetadata().getFileSystem().setLocation(new FileSystemResource(FileUtils.getTempDirectory()).getFile().getCanonicalPath());
val service = new SamlRegisteredService();
val resolver = new UrlResourceMetadataResolver(props, openSamlConfigBean);
service.setName("TestShib");
service.setId(1000);
service.setMetadataLocation("http://localhost:9155");
val results = resolver.resolve(service);
assertFalse(results.isEmpty());
assertTrue(resolver.isAvailable(service));
assertFalse(resolver.supports(null));
}
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class UrlResourceMetadataResolverTests method verifyResolverSupports.
@Test
public void verifyResolverSupports() throws Exception {
try (val webServer = new MockWebServer(9155, new ClassPathResource("sample-metadata.xml"), HttpStatus.OK)) {
webServer.start();
val props = new SamlIdPProperties();
props.getMetadata().getFileSystem().setLocation(new FileSystemResource(FileUtils.getTempDirectory()).getFile().getCanonicalPath());
val resolver = new UrlResourceMetadataResolver(props, openSamlConfigBean);
val service = new SamlRegisteredService();
service.setMetadataLocation("http://localhost:9155");
assertTrue(resolver.supports(service));
service.setMetadataLocation("classpath:sample-sp.xml");
assertFalse(resolver.supports(service));
service.setMetadataLocation(MDQ_URL);
assertFalse(resolver.supports(service));
}
}
use of org.apereo.cas.util.MockWebServer in project cas by apereo.
the class RestMultifactorAuthenticationTrustStorageTests method verifyRemovalByDate.
@Test
public void verifyRemovalByDate() {
try (val webServer = new MockWebServer(9297, new ByteArrayResource(StringUtils.EMPTY.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
webServer.start();
assertDoesNotThrow(new Executable() {
@Override
public void execute() {
mfaTrustEngine.remove(ZonedDateTime.now(ZoneOffset.UTC));
}
});
}
}
Aggregations