]> WPIA git - gigi.git/commitdiff
upd: refactor tests to use convenience get-stuff
authorFelix Dörre <felix@dogcraft.de>
Sat, 7 May 2016 08:24:21 +0000 (10:24 +0200)
committerFelix Dörre <felix@dogcraft.de>
Sat, 7 May 2016 21:24:35 +0000 (23:24 +0200)
15 files changed:
tests/org/cacert/gigi/LoginTest.java
tests/org/cacert/gigi/TestLanguage.java
tests/org/cacert/gigi/TestSecurityHeaders.java
tests/org/cacert/gigi/pages/admin/TestSEAdminPageDetails.java
tests/org/cacert/gigi/pages/admin/TestSEAdminPageUserDomainSearch.java
tests/org/cacert/gigi/pages/admin/TestSEAdminPageUserMailSearch.java
tests/org/cacert/gigi/pages/orga/TestOrgaManagement.java
tests/org/cacert/gigi/pages/wot/TestAssurance.java
tests/org/cacert/gigi/pages/wot/TestTTP.java
tests/org/cacert/gigi/pages/wot/TestTTPAdmin.java
tests/org/cacert/gigi/ping/TestDNS.java
tests/org/cacert/gigi/ping/TestHTTP.java
tests/org/cacert/gigi/ping/TestSSL.java
tests/org/cacert/gigi/testUtils/ManagedTest.java
tests/org/cacert/gigi/testUtils/PingTest.java

index f02f0ad04239a7fd66279c7a23b07f6396fe4ee0..29456c7b2a24a8d20b3580ea0801ec91ae330c79 100644 (file)
@@ -3,7 +3,6 @@ package org.cacert.gigi;
 import static org.junit.Assert.*;
 
 import java.io.IOException;
-import java.net.URL;
 
 import org.cacert.gigi.testUtils.ManagedTest;
 import org.junit.Test;
@@ -43,7 +42,7 @@ public class LoginTest extends ManagedTest {
     }
 
     private void logout(String cookie) throws IOException {
-        cookie(new URL("https://" + getServerName() + "/logout").openConnection(), cookie).getHeaderField("Location");
+        get(cookie, "/logout").getHeaderField("Location");
     }
 
 }
index 1cac14527bc7d2f90a7e9d2e5786dbeff55b1db7..55a3d12684e893645ab57c0c65a4e97c8915a965 100644 (file)
@@ -4,7 +4,6 @@ import static org.hamcrest.CoreMatchers.*;
 import static org.junit.Assert.*;
 
 import java.io.IOException;
-import java.net.URL;
 import java.util.Locale;
 
 import org.cacert.gigi.dbObjects.User;
@@ -51,13 +50,13 @@ public class TestLanguage extends ManagedTest {
 
     @Test
     public void testSelectStandard() throws IOException {
-        String content = IOUtils.readURL(new URL("https://" + getServerName() + "/").openConnection());
+        String content = IOUtils.readURL(get("cook", "/"));
         assertThat(content, containsString("Translations"));
     }
 
     @Test
     public void testSelectGerman() throws IOException {
-        String content = IOUtils.readURL(new URL("https://" + getServerName() + "/?lang=de").openConnection());
+        String content = IOUtils.readURL(get("", "/?lang=de"));
         assertThat(content, containsString(Language.getInstance(Locale.GERMAN).getTranslation("Translations")));
     }
 
@@ -66,7 +65,7 @@ public class TestLanguage extends ManagedTest {
         setAcceptLanguage("de,en");
         User u = User.getById(createVerifiedUser("fname", "lname", createUniqueName() + "@example.org", TEST_PASSWORD));
         String cookie = login(u.getEmail(), TEST_PASSWORD);
-        String content = IOUtils.readURL(cookie(new URL("https://" + getServerName() + "/").openConnection(), cookie));
+        String content = IOUtils.readURL(get(cookie, "/"));
         assertThat(content, containsString(Language.getInstance(Locale.GERMAN).getTranslation("Translations")));
     }
 
@@ -75,7 +74,7 @@ public class TestLanguage extends ManagedTest {
         setAcceptLanguage("fr,de,en");
         User u = User.getById(createVerifiedUser("fname", "lname", createUniqueName() + "@example.org", TEST_PASSWORD));
         String cookie = login(u.getEmail(), TEST_PASSWORD);
-        String content = IOUtils.readURL(cookie(new URL("https://" + getServerName() + "/").openConnection(), cookie));
+        String content = IOUtils.readURL(get(cookie, "/"));
         assertThat(content, containsString(Language.getInstance(Locale.FRENCH).getTranslation("Translations")));
     }
 }
index 16f4f3a08580c4d7f5b50d00038b63b8b2cd0b72..8149d322a22f21d917aeb91749630e701cc072e8 100644 (file)
@@ -4,7 +4,6 @@ import static org.junit.Assert.*;
 
 import java.io.IOException;
 import java.net.HttpURLConnection;
-import java.net.URL;
 
 import org.cacert.gigi.testUtils.ManagedTest;
 import org.junit.Test;
@@ -13,17 +12,17 @@ public class TestSecurityHeaders extends ManagedTest {
 
     @Test
     public void testSTS() throws IOException {
-        HttpURLConnection uc = (HttpURLConnection) new URL("https://" + getServerName()).openConnection();
+        HttpURLConnection uc = get(null, "/");
         assertNotNull(uc.getHeaderField("Strict-Transport-Security"));
     }
 
     public void testCSP() throws IOException {
-        HttpURLConnection uc = (HttpURLConnection) new URL("https://" + getServerName()).openConnection();
+        HttpURLConnection uc = get(null, "/");
         assertNotNull(uc.getHeaderField("Content-Security-Policy"));
     }
 
     public void testAllowOrigin() throws IOException {
-        HttpURLConnection uc = (HttpURLConnection) new URL("https://" + getServerName()).openConnection();
+        HttpURLConnection uc = get(null, "/");
         assertNotNull(uc.getHeaderField("Access-Control-Allow-Origin"));
 
     }
index f27a26a4642af0557cf4be5a7d0f824e29a8277a..1563addadc5476a8157e0818c3c8c62d6bba5a0f 100644 (file)
@@ -5,7 +5,6 @@ import static org.junit.Assert.*;
 
 import java.io.IOException;
 import java.net.MalformedURLException;
-import java.net.URL;
 import java.net.URLConnection;
 import java.util.Locale;
 import java.util.regex.Matcher;
@@ -37,8 +36,7 @@ public class TestSEAdminPageDetails extends ClientTest {
         String fname = "Först";
         String lname = "Secönd";
         int id = createVerifiedUser(fname, lname, email, TEST_PASSWORD);
-        URLConnection uc = new URL("https://" + getServerName() + SupportUserDetailsPage.PATH + id).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
+        URLConnection uc = get(SupportUserDetailsPage.PATH + id);
         uc.setDoOutput(true);
         String res = IOUtils.readURL(uc);
         assertThat(res, containsString("<input type=\"text\" value=\"" + fname + "\" name=\"fname\">"));
index 966adc1729bcd828edd79bc77d4a1fef251d6a83..4337e3324babc19f956991655398639cac941d9b 100644 (file)
@@ -4,10 +4,8 @@ import static org.junit.Assert.*;
 import static org.junit.Assume.*;
 
 import java.io.IOException;
-import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
 import java.net.MalformedURLException;
-import java.net.URL;
 import java.net.URLConnection;
 import java.net.URLEncoder;
 
@@ -37,17 +35,8 @@ public class TestSEAdminPageUserDomainSearch extends ClientTest {
         User user = User.getById(id);
         String domainName = createUniqueName() + ".org";
         new Domain(user, user, domainName);
-        URLConnection uc = new URL("https://" + getServerName() + FindDomainPage.PATH).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
-        String csrf = getCSRF(uc, 0);
+        URLConnection uc = post(FindDomainPage.PATH, "process&domain=" + URLEncoder.encode(domainName, "UTF-8"));
 
-        uc = new URL("https://" + getServerName() + FindDomainPage.PATH).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
-        uc.setDoOutput(true);
-        OutputStream os = uc.getOutputStream();
-        os.write(("csrf=" + URLEncoder.encode(csrf, "UTF-8") + "&" //
-                + "process&domain=" + URLEncoder.encode(domainName, "UTF-8")).getBytes("UTF-8"));
-        os.flush();
         assertEquals("https://" + ServerConstants.getWwwHostNamePortSecure() + SupportUserDetailsPage.PATH + id, uc.getHeaderField("Location"));
     }
 
@@ -58,33 +47,13 @@ public class TestSEAdminPageUserDomainSearch extends ClientTest {
         User user = User.getById(id);
         String domainName = createUniqueName() + ".org";
         Domain d = new Domain(user, user, domainName);
-        URLConnection uc = new URL("https://" + getServerName() + FindDomainPage.PATH).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
-        String csrf = getCSRF(uc, 0);
-
-        uc = new URL("https://" + getServerName() + FindDomainPage.PATH).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
-        uc.setDoOutput(true);
-        OutputStream os = uc.getOutputStream();
-        os.write(("csrf=" + URLEncoder.encode(csrf, "UTF-8") + "&" //
-                + "process&domain=#" + d.getId()).getBytes("UTF-8"));
-        os.flush();
+        URLConnection uc = post(FindDomainPage.PATH, "process&domain=#" + d.getId());
         assertEquals("https://" + ServerConstants.getWwwHostNamePortSecure() + SupportUserDetailsPage.PATH + id, uc.getHeaderField("Location"));
     }
 
     @Test
     public void testDomainSearchNonExist() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException {
-        URLConnection uc = new URL("https://" + getServerName() + FindDomainPage.PATH).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
-        String csrf = getCSRF(uc, 0);
-
-        uc = new URL("https://" + getServerName() + FindDomainPage.PATH).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
-        uc.setDoOutput(true);
-        OutputStream os = uc.getOutputStream();
-        os.write(("csrf=" + URLEncoder.encode(csrf, "UTF-8") + "&" //
-                + "process&domain=" + URLEncoder.encode(createUniqueName() + ".de", "UTF-8")).getBytes("UTF-8"));
-        os.flush();
+        URLConnection uc = post(FindDomainPage.PATH, "process&domain=" + URLEncoder.encode(createUniqueName() + ".de", "UTF-8"));
         assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
     }
 
@@ -102,16 +71,7 @@ public class TestSEAdminPageUserDomainSearch extends ClientTest {
             found = true;
         }
         assumeTrue(found);
-        URLConnection uc = new URL("https://" + getServerName() + FindDomainPage.PATH).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
-        String csrf = getCSRF(uc, 0);
-        uc = new URL("https://" + getServerName() + FindDomainPage.PATH).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
-        uc.setDoOutput(true);
-        OutputStream os = uc.getOutputStream();
-        os.write(("csrf=" + URLEncoder.encode(csrf, "UTF-8") + "&" //
-                + "process&domain=#" + id).getBytes("UTF-8"));
-        os.flush();
+        URLConnection uc = post(FindDomainPage.PATH, "process&domain=#" + id);
         assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
     }
 }
index 95b9ec7468f616eb5c9ccabd7ca3bedc8da0b535..70e5bd4f098464819ed1a9ef8d239ccfce5d632e 100644 (file)
@@ -4,10 +4,8 @@ import static org.hamcrest.CoreMatchers.*;
 import static org.junit.Assert.*;
 
 import java.io.IOException;
-import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
 import java.net.MalformedURLException;
-import java.net.URL;
 import java.net.URLConnection;
 import java.net.URLEncoder;
 
@@ -74,17 +72,7 @@ public class TestSEAdminPageUserMailSearch extends ClientTest {
 
     @Test
     public void testWildcardMailSearchNoRes() throws MalformedURLException, UnsupportedEncodingException, IOException {
-        URLConnection uc = new URL("https://" + getServerName() + FindUserPage.PATH).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
-        String csrf = getCSRF(uc, 0);
-
-        uc = new URL("https://" + getServerName() + FindUserPage.PATH).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
-        uc.setDoOutput(true);
-        OutputStream os = uc.getOutputStream();
-        os.write(("csrf=" + URLEncoder.encode(csrf, "UTF-8") + "&" //
-                + "process&email=" + URLEncoder.encode("%@_humpfelkumpf.org", "UTF-8")).getBytes("UTF-8"));
-        os.flush();
+        URLConnection uc = post(FindUserPage.PATH, "process&email=" + URLEncoder.encode("%@_humpfelkumpf.org", "UTF-8"));
         assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
     }
 
index 3ecc7a21dbb6705525db623b206c21390adba97e..6fe4f1828d57d79b771d3ac2d6b414e0feff00ab 100644 (file)
@@ -5,7 +5,6 @@ import static org.junit.Assert.*;
 
 import java.io.IOException;
 import java.net.HttpURLConnection;
-import java.net.URL;
 import java.net.URLConnection;
 import java.net.URLEncoder;
 import java.sql.SQLException;
@@ -87,28 +86,25 @@ public class TestOrgaManagement extends ClientTest {
         o1.addAdmin(u2, u, false);
         String session2 = login(u2.getEmail(), TEST_PASSWORD);
 
-        URLConnection uc = new URL("https://" + getServerName() + ViewOrgPage.DEFAULT_PATH).openConnection();
-        uc.addRequestProperty("Cookie", session2);
+        URLConnection uc = get(session2, ViewOrgPage.DEFAULT_PATH);
         assertEquals(403, ((HttpURLConnection) uc).getResponseCode());
 
-        uc = new URL("https://" + getServerName() + MyDetails.PATH).openConnection();
-        uc.addRequestProperty("Cookie", session2);
+        uc = get(session2, MyDetails.PATH);
         String content = IOUtils.readURL(uc);
         assertThat(content, containsString("name21"));
         assertThat(content, not(containsString("name12")));
-        uc = cookie(new URL("https://" + getServerName() + ViewOrgPage.DEFAULT_PATH + "/" + o1.getId()).openConnection(), session2);
+        uc = get(session2, ViewOrgPage.DEFAULT_PATH + "/" + o1.getId());
         assertEquals(403, ((HttpURLConnection) uc).getResponseCode());
-        uc = cookie(new URL("https://" + getServerName() + ViewOrgPage.DEFAULT_PATH + "/" + o2.getId()).openConnection(), session2);
+        uc = get(session2, ViewOrgPage.DEFAULT_PATH + "/" + o2.getId());
         assertEquals(403, ((HttpURLConnection) uc).getResponseCode());
 
-        uc = new URL("https://" + getServerName() + ViewOrgPage.DEFAULT_PATH).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
+        uc = get(ViewOrgPage.DEFAULT_PATH);
         content = IOUtils.readURL(uc);
         assertThat(content, containsString("name21"));
         assertThat(content, containsString("name12"));
-        uc = cookie(new URL("https://" + getServerName() + ViewOrgPage.DEFAULT_PATH + "/" + o1.getId()).openConnection(), cookie);
+        uc = get(ViewOrgPage.DEFAULT_PATH + "/" + o1.getId());
         assertEquals(200, ((HttpURLConnection) uc).getResponseCode());
-        uc = cookie(new URL("https://" + getServerName() + ViewOrgPage.DEFAULT_PATH + "/" + o2.getId()).openConnection(), cookie);
+        uc = get(ViewOrgPage.DEFAULT_PATH + "/" + o2.getId());
         assertEquals(200, ((HttpURLConnection) uc).getResponseCode());
         o1.delete();
         o2.delete();
index 58a791f372fcc0066a83b00244ffd44e0b9e3884..ffc9ea5788fc1f83f04b229572fdf88aad79a6ba 100644 (file)
@@ -7,7 +7,6 @@ import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
-import java.net.URL;
 import java.net.URLConnection;
 import java.net.URLEncoder;
 import java.sql.SQLException;
@@ -64,10 +63,8 @@ public class TestAssurance extends ManagedTest {
     }
 
     private String search(String query) throws MalformedURLException, IOException, UnsupportedEncodingException {
-        URL u = new URL("https://" + getServerName() + AssurePage.PATH);
-        URLConnection uc = u.openConnection();
+        URLConnection uc = get(cookie, AssurePage.PATH);
         uc.setDoOutput(true);
-        uc.addRequestProperty("Cookie", cookie);
         uc.getOutputStream().write(("search&" + query).getBytes("UTF-8"));
         uc.getOutputStream().flush();
 
@@ -186,8 +183,7 @@ public class TestAssurance extends ManagedTest {
         String error = getError("date=2000-01-01&location=" + uniqueLoc + "&certify=1&rules=1&CCAAgreed=1&assertion=1&points=10");
         assertNull(error);
         String cookie = login(assureeM, TEST_PASSWORD);
-        URLConnection url = new URL("https://" + getServerName() + MyPoints.PATH).openConnection();
-        url.setRequestProperty("Cookie", cookie);
+        URLConnection url = get(cookie, MyPoints.PATH);
         String resp = IOUtils.readURL(url);
         resp = resp.split(Pattern.quote("</table>"))[0];
         assertThat(resp, containsString(uniqueLoc));
@@ -199,8 +195,7 @@ public class TestAssurance extends ManagedTest {
         String error = getError("date=2000-01-01&location=" + uniqueLoc + "&certify=1&rules=1&CCAAgreed=1&assertion=1&points=10");
         assertNull(error);
         String cookie = login(assurerM, TEST_PASSWORD);
-        URLConnection url = new URL("https://" + getServerName() + MyPoints.PATH).openConnection();
-        url.setRequestProperty("Cookie", cookie);
+        URLConnection url = get(cookie, MyPoints.PATH);
         String resp = IOUtils.readURL(url);
         resp = resp.split(Pattern.quote("</table>"))[1];
         assertThat(resp, containsString(uniqueLoc));
@@ -219,15 +214,12 @@ public class TestAssurance extends ManagedTest {
     }
 
     public static URLConnection buildupAssureFormConnection(String cookie, String email, boolean doCSRF) throws MalformedURLException, IOException {
-        URL u = new URL("https://" + getServerName() + AssurePage.PATH);
-        URLConnection uc = u.openConnection();
-        uc.addRequestProperty("Cookie", cookie);
+        URLConnection uc = get(cookie, AssurePage.PATH);
         uc.setDoOutput(true);
         uc.getOutputStream().write(("email=" + URLEncoder.encode(email, "UTF-8") + "&day=1&month=1&year=1910&search").getBytes("UTF-8"));
 
         String csrf = getCSRF(uc);
-        uc = u.openConnection();
-        uc.addRequestProperty("Cookie", cookie);
+        uc = get(cookie, AssurePage.PATH);
         uc.setDoOutput(true);
         if (doCSRF) {
             uc.getOutputStream().write(("csrf=" + csrf + "&").getBytes("UTF-8"));
index 7c8884ba8c22acb8a6952af95ac0fdabc5119301..34b0ca6dfc78c50d7ffad6d3c6a6a461ef72254d 100644 (file)
@@ -4,7 +4,6 @@ import static org.hamcrest.CoreMatchers.*;
 import static org.junit.Assert.*;
 
 import java.io.IOException;
-import java.net.URL;
 
 import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.dbObjects.Group;
@@ -16,17 +15,15 @@ import org.junit.Test;
 
 public class TestTTP extends ClientTest {
 
-    URL ttpPage = new URL("https://" + getServerName() + RequestTTPPage.PATH);
-
     public TestTTP() throws IOException {}
 
     @Test
     public void testTTPApply() throws IOException {
-        String ttp = IOUtils.readURL(cookie(ttpPage.openConnection(), cookie));
+        String ttp = IOUtils.readURL(get(RequestTTPPage.PATH));
         assertThat(ttp, containsString("<form"));
         executeBasicWebInteraction(cookie, RequestTTPPage.PATH, "country=0");
 
-        ttp = IOUtils.readURL(cookie(new URL("https://" + getServerName() + RequestTTPPage.PATH).openConnection(), cookie));
+        ttp = IOUtils.readURL(get(RequestTTPPage.PATH));
         assertThat(ttp, not(containsString("<form")));
         ObjectCache.clearAllCaches();
         u = User.getById(u.getId());
@@ -38,7 +35,7 @@ public class TestTTP extends ClientTest {
         User u = User.getById(createAssuranceUser("fn", "ln", createUniqueName() + "@example.org", TEST_PASSWORD));
         cookie = login(u.getEmail(), TEST_PASSWORD);
 
-        String ttp = IOUtils.readURL(cookie(new URL("https://" + getServerName() + RequestTTPPage.PATH).openConnection(), cookie));
+        String ttp = IOUtils.readURL(get(RequestTTPPage.PATH));
         assertThat(ttp, not(containsString("<form")));
     }
 }
index 32c4268afc120846f613a5a72d07917b9953e824..31b0e51bd9d5bb3d77483fee2586cecc110a4ff7 100644 (file)
@@ -3,9 +3,7 @@ package org.cacert.gigi.pages.wot;
 import static org.junit.Assert.*;
 
 import java.io.IOException;
-import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
-import java.net.URL;
 
 import org.cacert.gigi.dbObjects.Group;
 import org.cacert.gigi.dbObjects.User;
@@ -38,15 +36,14 @@ public class TestTTPAdmin extends ClientTest {
         grant(u.getEmail(), TTPAdminPage.TTP_APPLICANT);
         cookie = login(u.getEmail(), TEST_PASSWORD);
 
-        assertEquals( !hasRight ? 403 : 200, fetchStatusCode("https://" + getServerName() + TTPAdminPage.PATH));
-        assertEquals( !hasRight ? 403 : 200, fetchStatusCode("https://" + getServerName() + TTPAdminPage.PATH + "/"));
-        assertEquals( !hasRight ? 403 : 200, fetchStatusCode("https://" + getServerName() + TTPAdminPage.PATH + "/" + u.getId()));
-        assertEquals( !hasRight ? 403 : 404, fetchStatusCode("https://" + getServerName() + TTPAdminPage.PATH + "/" + us2.getId()));
-        assertEquals( !hasRight ? 403 : 404, fetchStatusCode("https://" + getServerName() + TTPAdminPage.PATH + "/" + 100));
+        assertEquals( !hasRight ? 403 : 200, fetchStatusCode(TTPAdminPage.PATH));
+        assertEquals( !hasRight ? 403 : 200, fetchStatusCode(TTPAdminPage.PATH + "/"));
+        assertEquals( !hasRight ? 403 : 200, fetchStatusCode(TTPAdminPage.PATH + "/" + u.getId()));
+        assertEquals( !hasRight ? 403 : 404, fetchStatusCode(TTPAdminPage.PATH + "/" + us2.getId()));
+        assertEquals( !hasRight ? 403 : 404, fetchStatusCode(TTPAdminPage.PATH + "/" + 100));
     }
 
     private int fetchStatusCode(String path) throws MalformedURLException, IOException {
-        URL u = new URL(path);
-        return ((HttpURLConnection) cookie(u.openConnection(), cookie)).getResponseCode();
+        return get(path).getResponseCode();
     }
 }
index 187bb382bd1b2a860ff63b77581c56866cb9260c..8bb61461ecc745dddc8219919f445fd8cd2297e6 100644 (file)
@@ -4,7 +4,6 @@ import static org.junit.Assert.*;
 import static org.junit.Assume.*;
 
 import java.io.IOException;
-import java.net.URL;
 import java.net.URLEncoder;
 import java.sql.SQLException;
 import java.util.regex.Matcher;
@@ -12,7 +11,6 @@ import java.util.regex.Pattern;
 
 import javax.naming.NamingException;
 
-import org.cacert.gigi.pages.account.domain.DomainOverview;
 import org.cacert.gigi.testUtils.IOUtils;
 import org.cacert.gigi.testUtils.PingTest;
 import org.cacert.gigi.testUtils.TestEmailReceiver.TestMail;
@@ -63,8 +61,7 @@ public class TestDNS extends PingTest {
         String test = getTestProps().getProperty("domain.dnstest");
         assumeNotNull(test);
 
-        URL u = new URL("https://" + getServerName() + DomainOverview.PATH);
-        Matcher m = initailizeDomainForm(u);
+        Matcher m = initailizeDomainForm();
         updateService(m.group(1) + (dnsVariant == 1 ? "a" : ""), m.group(2) + (dnsVariant == 2 ? "a" : ""), "dns");
 
         String content = "newdomain=" + URLEncoder.encode(test, "UTF-8") + //
@@ -74,7 +71,7 @@ public class TestDNS extends PingTest {
                 "&ssl-type-2=direct&ssl-port-2=" + //
                 "&ssl-type-3=direct&ssl-port-3=" + //
                 "&adddomain&csrf=" + csrf;
-        URL u2 = sendDomainForm(u, content);
+        String p2 = sendDomainForm(content);
 
         TestMail mail = getMailReciever().receive();
         if (emailVariant == 0) {
@@ -83,7 +80,7 @@ public class TestDNS extends PingTest {
 
         waitForPings(2);
 
-        String newcontent = IOUtils.readURL(cookie(u2.openConnection(), cookie));
+        String newcontent = IOUtils.readURL(get(p2));
         Pattern pat = Pattern.compile("<td>dns</td>\\s*<td>success</td>");
         assertTrue(newcontent, !successDNS ^ pat.matcher(newcontent).find());
         pat = Pattern.compile("<td>email</td>\\s*<td>success</td>");
index da9892b41e854cb1735bff4a8d87331ac287e53b..31fecd942bb53e2ba4055aad9a182d77b953cbff 100644 (file)
@@ -18,7 +18,6 @@ import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.dbObjects.Domain;
 import org.cacert.gigi.dbObjects.DomainPingConfiguration;
 import org.cacert.gigi.dbObjects.DomainPingType;
-import org.cacert.gigi.pages.account.domain.DomainOverview;
 import org.cacert.gigi.testUtils.IOUtils;
 import org.cacert.gigi.testUtils.PingTest;
 import org.cacert.gigi.testUtils.TestEmailReceiver.TestMail;
@@ -58,8 +57,7 @@ public class TestHTTP extends PingTest {
         String test = getTestProps().getProperty("domain.http");
         assumeNotNull(test);
 
-        URL u = new URL("https://" + getServerName() + DomainOverview.PATH);
-        Matcher m = initailizeDomainForm(u);
+        Matcher m = initailizeDomainForm();
         updateService(m.group(1) + (httpVariant == 1 ? "a" : ""), m.group(2) + (httpVariant == 2 ? "a" : ""), "http");
 
         String content = "newdomain=" + URLEncoder.encode(test, "UTF-8") + //
@@ -69,7 +67,7 @@ public class TestHTTP extends PingTest {
                 "&ssl-type-2=direct&ssl-port-2=" + //
                 "&ssl-type-3=direct&ssl-port-3=" + //
                 "&adddomain&csrf=" + csrf;
-        URL u2 = sendDomainForm(u, content);
+        String p2 = sendDomainForm(content);
 
         TestMail mail = getMailReciever().receive();
         if (emailVariant == 0) {
@@ -77,14 +75,14 @@ public class TestHTTP extends PingTest {
         }
         waitForPings(2);
 
-        String newcontent = IOUtils.readURL(cookie(u2.openConnection(), cookie));
+        String newcontent = IOUtils.readURL(get(p2));
         Pattern pat = Pattern.compile("<td>http</td>\\s*<td>success</td>");
         assertTrue(newcontent, !successHTTP ^ pat.matcher(newcontent).find());
         pat = Pattern.compile("<td>email</td>\\s*<td>success</td>");
         assertTrue(newcontent, !successMail ^ pat.matcher(newcontent).find());
 
         if (successHTTP) { // give it a second try
-            int id = Integer.parseInt(u2.toString().replaceFirst("^.*/([0-9]+)$", "$1"));
+            int id = Integer.parseInt(p2.replaceFirst("^.*/([0-9]+)$", "$1"));
             Domain d = Domain.getById(id);
             DomainPingConfiguration dpc = null;
             for (DomainPingConfiguration conf : d.getConfiguredPings()) {
@@ -96,7 +94,7 @@ public class TestHTTP extends PingTest {
             if (dpc == null) {
                 fail("Http config not found");
             }
-            String res = executeBasicWebInteraction(cookie, u2.getPath(), "configId=" + dpc.getId());
+            String res = executeBasicWebInteraction(cookie, p2, "configId=" + dpc.getId());
             assertThat(res, containsString("only allowed after"));
         }
     }
index 82d1c820b11eb81cf58e79adcbfb604df4940300..62e652aa06aeb297fff9f51a2273e0da0ddbdca7 100644 (file)
@@ -6,7 +6,6 @@ import static org.junit.Assume.*;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.net.Socket;
-import java.net.URL;
 import java.net.URLEncoder;
 import java.security.GeneralSecurityException;
 import java.security.KeyManagementException;
@@ -42,7 +41,6 @@ import org.cacert.gigi.dbObjects.Certificate.CSRType;
 import org.cacert.gigi.dbObjects.CertificateProfile;
 import org.cacert.gigi.dbObjects.Digest;
 import org.cacert.gigi.dbObjects.User;
-import org.cacert.gigi.pages.account.domain.DomainOverview;
 import org.cacert.gigi.testUtils.IOUtils;
 import org.cacert.gigi.testUtils.PingTest;
 import org.cacert.gigi.testUtils.TestEmailReceiver.TestMail;
@@ -154,9 +152,7 @@ public class TestSSL extends PingTest {
     private void testEmailAndSSL(int sslVariant, int emailVariant, boolean successMail) throws IOException, InterruptedException, SQLException, GeneralSecurityException, GigiApiException {
         String test = getTestProps().getProperty("domain.local");
         assumeNotNull(test);
-        URL u = new URL("https://" + getServerName() + DomainOverview.PATH);
-
-        Matcher m = initailizeDomainForm(u);
+        Matcher m = initailizeDomainForm();
         String value = m.group(2);
 
         if (self) {
@@ -182,7 +178,7 @@ public class TestSSL extends PingTest {
                 "&ssl-type-2=direct&ssl-port-2=" + //
                 "&ssl-type-3=direct&ssl-port-3=" + //
                 "&adddomain&csrf=" + csrf;
-        URL u2 = sendDomainForm(u, content);
+        String p2 = sendDomainForm(content);
         boolean firstSucceeds = sslVariant != 0 && sslVariant != 2;
         AsyncTask<Boolean> ass = new AsyncTask<Boolean>() {
 
@@ -206,7 +202,7 @@ public class TestSSL extends PingTest {
         }
         waitForPings(3);
 
-        String newcontent = IOUtils.readURL(cookie(u2.openConnection(), cookie));
+        String newcontent = IOUtils.readURL(get(p2));
         Pattern pat = Pattern.compile("<td>ssl</td>\\s*<td>success</td>");
         Matcher matcher = pat.matcher(newcontent);
         assertTrue(newcontent, firstSucceeds ^ matcher.find());
index 96b4e61b06886d689ebf3d0b6d867f80005ae2b1..098c257f9adb7e6202bdfb72d1eed4a2f834a0b4 100644 (file)
@@ -474,7 +474,7 @@ public class ManagedTest extends ConfiguredTest {
         return (HttpURLConnection) uc;
     }
 
-    public HttpURLConnection get(String cookie, String path) throws IOException {
+    public static HttpURLConnection get(String cookie, String path) throws IOException {
         URLConnection uc = new URL("https://" + getServerName() + path).openConnection();
         uc.addRequestProperty("Cookie", cookie);
         return (HttpURLConnection) uc;
index 31f45c99b8143c3e0d40e66ffccc70568a186d0e..0d15f2e86c3cf5807c3a969d647b83e061103c89 100644 (file)
@@ -46,9 +46,8 @@ public abstract class PingTest extends ClientTest {
         }
     }
 
-    protected URL sendDomainForm(URL u, String content) throws IOException, MalformedURLException {
-        URLConnection openConnection = u.openConnection();
-        openConnection.setRequestProperty("Cookie", cookie);
+    protected String sendDomainForm(String content) throws IOException, MalformedURLException {
+        URLConnection openConnection = get(DomainOverview.PATH);
         openConnection.setDoOutput(true);
         openConnection.getOutputStream().write(content.getBytes("UTF-8"));
         openConnection.getHeaderField("Location");
@@ -56,20 +55,17 @@ public abstract class PingTest extends ClientTest {
             throw new Error(IOUtils.readURL(openConnection));
         }
 
-        String newcontent = IOUtils.readURL(cookie(u.openConnection(), cookie));
+        String newcontent = IOUtils.readURL(get(DomainOverview.PATH));
         Pattern dlink = Pattern.compile(DomainOverview.PATH + "([0-9]+)'>");
         Matcher m1 = dlink.matcher(newcontent);
         if ( !m1.find()) {
             throw new Error(newcontent);
         }
-        URL u2 = new URL(u.toString() + m1.group(1));
-        return u2;
+        return DomainOverview.PATH + m1.group(1);
     }
 
-    protected Matcher initailizeDomainForm(URL u) throws IOException, Error {
-        URLConnection openConnection = u.openConnection();
-        openConnection.setRequestProperty("Cookie", cookie);
-        String content1 = IOUtils.readURL(openConnection);
+    protected Matcher initailizeDomainForm() throws IOException, Error {
+        String content1 = IOUtils.readURL(get(DomainOverview.PATH));
         csrf = getCSRF(1, content1);
 
         Pattern p = Pattern.compile("([A-Za-z0-9]+)._cacert._auth IN TXT ([A-Za-z0-9]+)");