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
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);
}
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);
}
public static String getServerName() {
- return url;
+ return url.replaceFirst(":443$", "");
+ }
+
+ public static String getSecureServerName() {
+ return getServerName().replaceAll("^www\\.", "secure.");
}
static {
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;