X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;ds=sidebyside;f=tests%2Forg%2Fcacert%2Fgigi%2FtestUtils%2FPingTest.java;h=a432cb2af61b91a2dd9b4ce1b63e2dec7765dd03;hb=67bdb3b1fd3ff821d00715bf2a7ed90ca7a7a664;hp=4fb49595c316e84a5e9452f14bd6ebb7e82fd991;hpb=a1a980dd0cc65f33a6189eb81a164fe79abb647c;p=gigi.git diff --git a/tests/org/cacert/gigi/testUtils/PingTest.java b/tests/org/cacert/gigi/testUtils/PingTest.java index 4fb49595..a432cb2a 100644 --- a/tests/org/cacert/gigi/testUtils/PingTest.java +++ b/tests/org/cacert/gigi/testUtils/PingTest.java @@ -12,10 +12,10 @@ import java.sql.SQLException; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.cacert.gigi.database.DatabaseConnection; import org.cacert.gigi.database.GigiPreparedStatement; import org.cacert.gigi.database.GigiResultSet; import org.cacert.gigi.pages.account.domain.DomainOverview; +import org.cacert.gigi.util.SystemKeywords; import org.junit.After; /** @@ -34,42 +34,43 @@ public abstract class PingTest extends ClientTest { } protected void waitForPings(int count) throws SQLException, InterruptedException { - GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT COUNT(*) FROM domainPinglog"); - long start = System.currentTimeMillis(); - while (System.currentTimeMillis() - start < 10000) { - GigiResultSet rs = ps.executeQuery(); - rs.next(); - if (rs.getInt(1) >= count) { - break; + try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT COUNT(*) FROM `domainPinglog`")) { + long start = System.currentTimeMillis(); + while (System.currentTimeMillis() - start < 10000) { + GigiResultSet rs = ps.executeQuery(); + rs.next(); + if (rs.getInt(1) >= count) { + break; + } + Thread.sleep(200); } - Thread.sleep(200); } } - 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()); + openConnection.getOutputStream().write(content.getBytes("UTF-8")); openConnection.getHeaderField("Location"); + int code = ((HttpURLConnection) openConnection).getResponseCode(); + if (code != 302) { + throw new Error("Code was: " + code + "\ncontent was: " + fetchStartErrorMessage(IOUtils.readURL(openConnection))); + } - String newcontent = IOUtils.readURL(cookie(u.openConnection(), cookie)); - Pattern dlink = Pattern.compile(DomainOverview.PATH + "([0-9]+)'>"); + 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]+)"); + Pattern p = Pattern.compile("([A-Za-z0-9]+)." + SystemKeywords.DNS_PREFIX + "._auth IN TXT ([A-Za-z0-9]+)"); Matcher m = p.matcher(content1); m.find(); return m;