/** * Test that invalid paths return a 404 Not Found. * * @throws Exception */ @Test public void testInvalidPath() throws Exception { HttpURLConnection urlConn = openConnection(getURL("invalid")); try { Optional.ofNullable(getAuthRequestHeader()).ifPresent(m -> m.forEach(urlConn::addRequestProperty)); Assert.assertEquals(404, urlConn.getResponseCode()); } finally { urlConn.disconnect(); } }
private HttpsURLConnection openConnection(URL url, String keyStoreResource) throws Exception { HttpsURLConnection urlConn = (HttpsURLConnection) super.openConnection(url); URL clientKeystoreURL = ExternalMTLSAuthenticationServerTest.class.getClassLoader().getResource(keyStoreResource); Assert.assertNotNull(clientKeystoreURL); KeyStore ks = KeyStore.getInstance("JKS"); try (InputStream is = clientKeystoreURL.openConnection().getInputStream()) { ks.load(is, "secret".toCharArray()); } return new HttpsEnabler().setKeyStore(ks, () -> configuration.get("security.auth.server.ssl.keystore.password", "secret").toCharArray()) .setTrustAll(true) .enable(urlConn); }
/** * Test an unauthorized status request to server. * * @throws Exception */ @Test public void testStatusResponse() throws Exception { HttpURLConnection urlConn = openConnection(getURL(Constants.EndPoints.STATUS)); try { // Status request is authorized without any extra headers Assert.assertEquals(200, urlConn.getResponseCode()); } finally { urlConn.disconnect(); } }
/** * Test an unauthorized request to server. * * @throws Exception */ @Test public void testInvalidAuthentication() throws Exception { HttpURLConnection urlConn = openConnection(getURL(GrantAccessToken.Paths.GET_TOKEN)); try { Optional.ofNullable(getAuthRequestHeader()) .ifPresent(m -> m.forEach((k, v) -> urlConn.addRequestProperty(k, "xxxxx"))); // Request is Unauthorized Assert.assertEquals(401, urlConn.getResponseCode()); verify(TEST_AUDIT_LOGGER, timeout(10000).atLeastOnce()).trace(contains("401")); } finally { urlConn.disconnect(); } }
HttpURLConnection urlConn = openConnection(getURL(GrantAccessToken.Paths.GET_EXTENDED_TOKEN)); try { Optional.ofNullable(getAuthRequestHeader()).ifPresent(m -> m.forEach(urlConn::addRequestProperty));
HttpURLConnection urlConn = openConnection(getURL(GrantAccessToken.Paths.GET_TOKEN)); try { Optional.ofNullable(getAuthRequestHeader()).ifPresent(m -> m.forEach(urlConn::addRequestProperty));