You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2017/09/05 11:49:23 UTC
svn commit: r1807341 -
/sling/trunk/testing/junit/teleporter/src/test/java/org/apache/sling/testing/teleporter/client/TeleporterHttpClientTest.java
Author: bdelacretaz
Date: Tue Sep 5 11:49:23 2017
New Revision: 1807341
URL: http://svn.apache.org/viewvc?rev=1807341&view=rev
Log:
SLING-7101 - add missing credentials test
Modified:
sling/trunk/testing/junit/teleporter/src/test/java/org/apache/sling/testing/teleporter/client/TeleporterHttpClientTest.java
Modified: sling/trunk/testing/junit/teleporter/src/test/java/org/apache/sling/testing/teleporter/client/TeleporterHttpClientTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/teleporter/src/test/java/org/apache/sling/testing/teleporter/client/TeleporterHttpClientTest.java?rev=1807341&r1=1807340&r2=1807341&view=diff
==============================================================================
--- sling/trunk/testing/junit/teleporter/src/test/java/org/apache/sling/testing/teleporter/client/TeleporterHttpClientTest.java (original)
+++ sling/trunk/testing/junit/teleporter/src/test/java/org/apache/sling/testing/teleporter/client/TeleporterHttpClientTest.java Tue Sep 5 11:49:23 2017
@@ -41,6 +41,8 @@ public class TeleporterHttpClientTest {
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 @@ public class TeleporterHttpClientTest {
client.verifyCorrectBundleState(bundleSymbolicName, 1);
}
- @Test
- public void testRequiredCredentials() throws IOException {
+ private void testWithCredentials(String path, String credentials, int expectedStatus) 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)));
+ 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(200, client.getHttpGetStatus(baseUrl + protectedPath).getStatus());
+ assertEquals(expectedStatus, client.getHttpGetStatus(baseUrl + path).getStatus());
+ }
+
+ @Test
+ public void testRequiredCredentials() throws IOException {
+ testWithCredentials("/protected", username + ":" + password, 302);
+ }
+
+ @Test
+ public void testMissingCredentials() throws IOException {
+ testWithCredentials("/protected", null, 418);
}
}
\ No newline at end of file