SLING-7101 - add missing credentials test
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1807341 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/test/java/org/apache/sling/testing/teleporter/client/TeleporterHttpClientTest.java b/src/test/java/org/apache/sling/testing/teleporter/client/TeleporterHttpClientTest.java
index d2634a1..0204622 100644
--- a/src/test/java/org/apache/sling/testing/teleporter/client/TeleporterHttpClientTest.java
+++ b/src/test/java/org/apache/sling/testing/teleporter/client/TeleporterHttpClientTest.java
@@ -41,6 +41,8 @@
private static final int PORT = Integer.getInteger("http.port", 1234);
private static final String baseUrl = "http://127.0.0.1:" + PORT;
private static final String TEST_PATH = "/foo";
+ private static final String username = UUID.randomUUID().toString();
+ private static final String password = UUID.randomUUID().toString();
@Rule
public WireMockRule http = new WireMockRule(PORT);
@@ -128,16 +130,21 @@
client.verifyCorrectBundleState(bundleSymbolicName, 1);
}
+ private void testWithCredentials(String path, String credentials, int expectedStatus) throws IOException {
+ final TeleporterHttpClient client = new TeleporterHttpClient(baseUrl, "invalid");
+ http.givenThat(get(urlEqualTo(path)).willReturn(aResponse().withStatus(418)));
+ http.givenThat(get(urlEqualTo(path)).withBasicAuth(username, password).willReturn(aResponse().withStatus(302)));
+ client.setCredentials(credentials);
+ assertEquals(expectedStatus, client.getHttpGetStatus(baseUrl + path).getStatus());
+ }
+
@Test
public void testRequiredCredentials() throws IOException {
- final TeleporterHttpClient client = new TeleporterHttpClient(baseUrl, "invalid");
- final String protectedPath = "/protected";
- final String user = UUID.randomUUID().toString();
- final String pwd = UUID.randomUUID().toString();
- final String credentials = user + ":" + pwd;
-
- http.givenThat(get(urlEqualTo(protectedPath)).withBasicAuth(user, pwd).willReturn(aResponse().withStatus(200)));
- client.setCredentials(credentials);
- assertEquals(200, client.getHttpGetStatus(baseUrl + protectedPath).getStatus());
+ testWithCredentials("/protected", username + ":" + password, 302);
+ }
+
+ @Test
+ public void testMissingCredentials() throws IOException {
+ testWithCredentials("/protected", null, 418);
}
}
\ No newline at end of file