]> WPIA git - gigi.git/commitdiff
add: constant for "secure." server name
authorFelix Dörre <felix@dogcraft.de>
Fri, 16 Sep 2016 11:05:18 +0000 (13:05 +0200)
committerFelix Dörre <felix@dogcraft.de>
Tue, 20 Sep 2016 07:14:06 +0000 (09:14 +0200)
Change-Id: I7cfac77e65cf965d9d7f04622e6c6322880b506e

tests/org/cacert/gigi/LoginTest.java
tests/org/cacert/gigi/TestSeparateSessionScope.java
tests/org/cacert/gigi/testUtils/ManagedTest.java

index 86e3d7b7e53314a10e9b51c4513400bc4666a304..4918732cc8a41833b38ed4b5074a658b25877fff 100644 (file)
@@ -53,7 +53,7 @@ public class LoginTest extends ManagedTest {
         headerField = huc.getHeaderField("Set-Cookie");
         assertNotNull(headerField);
         assertEquals(302, huc.getResponseCode());
-        assertEquals("https://" + getServerName().replaceFirst(":443$", "") + SECURE_REFERENCE, huc.getHeaderField("Location"));
+        assertEquals("https://" + getServerName() + SECURE_REFERENCE, huc.getHeaderField("Location"));
     }
 
     @Test
@@ -100,7 +100,7 @@ public class LoginTest extends ManagedTest {
         final X509Certificate ce = c.cert();
         c.setLoginEnabled(true);
         String cookie = login(pk, ce);
-        URL u2 = new URL("https://" + getServerName().replaceFirst("^www.", "secure.") + SECURE_REFERENCE);
+        URL u2 = new URL("https://" + getSecureServerName() + SECURE_REFERENCE);
         HttpURLConnection huc = (HttpURLConnection) u2.openConnection();
         huc.addRequestProperty("Cookie", cookie);
         authenticateClientCert(pk, ce, huc);
index c5979acf3de3e09984ba769e82e6159497049f91..fd09313c14547af9c47aace51cd74a0a898ff8fa 100644 (file)
@@ -70,7 +70,7 @@ public class TestSeparateSessionScope extends ManagedTest {
     }
 
     private void checkCertLogin(Certificate c2, final PrivateKey pk, String scookie, int expected) throws IOException, NoSuchAlgorithmException, KeyManagementException, GeneralSecurityException {
-        URL u = new URL("https://" + getServerName().replaceAll("^www", "secure") + SECURE_REFERENCE);
+        URL u = new URL("https://" + getSecureServerName() + SECURE_REFERENCE);
         HttpURLConnection huc = (HttpURLConnection) u.openConnection();
         authenticateClientCert(pk, c2.cert(), huc);
         huc.setRequestProperty("Cookie", scookie);
index 0c7aced4cae714482f96eb11bca77c4f910bfaf7..da55f6848f450afac81837d00bc4cd2fc95097bc 100644 (file)
@@ -74,7 +74,11 @@ public class ManagedTest extends ConfiguredTest {
     }
 
     public static String getServerName() {
-        return url;
+        return url.replaceFirst(":443$", "");
+    }
+
+    public static String getSecureServerName() {
+        return getServerName().replaceAll("^www\\.", "secure.");
     }
 
     static {
@@ -357,10 +361,10 @@ public class ManagedTest extends ConfiguredTest {
 
     public static String login(final PrivateKey pk, final X509Certificate ce) throws NoSuchAlgorithmException, KeyManagementException, IOException, MalformedURLException {
 
-        HttpURLConnection connection = (HttpURLConnection) new URL("https://" + getServerName().replaceFirst("^www.", "secure.") + "/login").openConnection();
+        HttpURLConnection connection = (HttpURLConnection) new URL("https://" + getSecureServerName() + "/login").openConnection();
         authenticateClientCert(pk, ce, connection);
         if (connection.getResponseCode() == 302) {
-            assertEquals("https://" + getServerName().replaceFirst("^www.", "secure.").replaceFirst(":443$", "") + "/", connection.getHeaderField("Location").replaceFirst(":443$", ""));
+            assertEquals("https://" + getSecureServerName() + "/", connection.getHeaderField("Location").replaceFirst(":443$", ""));
             return stripCookie(connection.getHeaderField("Set-Cookie"));
         } else {
             return null;