X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=tests%2Forg%2Fcacert%2Fgigi%2Fping%2FTestHTTP.java;h=4daa0d7e9421e5a4b672c0b966e1a1fb534d0601;hp=d6718241f33479b1a3d8b1de414d3f50a2029ebd;hb=28675b61ff01735e091fb37fd0d150574f2f61b6;hpb=0b77293697a8a0fabf120c7b820a71ec94831c82 diff --git a/tests/org/cacert/gigi/ping/TestHTTP.java b/tests/org/cacert/gigi/ping/TestHTTP.java index d6718241..4daa0d7e 100644 --- a/tests/org/cacert/gigi/ping/TestHTTP.java +++ b/tests/org/cacert/gigi/ping/TestHTTP.java @@ -1,6 +1,8 @@ package org.cacert.gigi.ping; +import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; +import static org.junit.Assume.*; import java.io.IOException; import java.io.InputStreamReader; @@ -12,11 +14,16 @@ import java.util.regex.Pattern; import javax.naming.NamingException; -import org.cacert.gigi.pages.account.DomainOverview; +import org.cacert.gigi.GigiApiException; +import org.cacert.gigi.dbObjects.Domain; +import org.cacert.gigi.dbObjects.DomainPingConfiguration; +import org.cacert.gigi.dbObjects.DomainPingConfiguration.PingType; +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.TestEmailReciever.TestMail; import org.cacert.gigi.util.RandomToken; +import org.junit.Assert; import org.junit.Test; public class TestHTTP extends PingTest { @@ -33,23 +40,24 @@ public class TestHTTP extends PingTest { } @Test - public void httpAndMailSuccess() throws IOException, InterruptedException, SQLException { + public void httpAndMailSuccess() throws Exception { testEmailAndHTTP(0, 0, true, true); } @Test - public void httpFailKeyAndMailSuccess() throws IOException, InterruptedException, SQLException { + public void httpFailKeyAndMailSuccess() throws Exception { testEmailAndHTTP(1, 0, false, true); } @Test - public void httpFailValAndMailFail() throws IOException, InterruptedException, SQLException { + public void httpFailValAndMailFail() throws Exception { testEmailAndHTTP(2, 1, false, false); } - public void testEmailAndHTTP(int httpVariant, int emailVariant, boolean successHTTP, boolean successMail) throws IOException, InterruptedException, SQLException { + public void testEmailAndHTTP(int httpVariant, int emailVariant, boolean successHTTP, boolean successMail) throws IOException, InterruptedException, SQLException, GigiApiException { String test = getTestProps().getProperty("domain.http"); + assumeNotNull(test); URL u = new URL("https://" + getServerName() + DomainOverview.PATH); Matcher m = initailizeDomainForm(u); @@ -66,8 +74,8 @@ public class TestHTTP extends PingTest { TestMail mail = getMailReciever().recieve(); if (emailVariant == 0) { - String link = mail.extractLink(); - new URL(link).openConnection().getHeaderField(""); + Assert.assertNotNull(mail); + mail.verify(); } waitForPings(2); @@ -76,11 +84,30 @@ public class TestHTTP extends PingTest { assertTrue(newcontent, !successHTTP ^ pat.matcher(newcontent).find()); pat = Pattern.compile("email\\s*success"); assertTrue(newcontent, !successMail ^ pat.matcher(newcontent).find()); + + if (successHTTP) { // give it a second try + int id = Integer.parseInt(u2.toString().replaceFirst("^.*/([0-9]+)$", "$1")); + Domain d = Domain.getById(id); + DomainPingConfiguration dpc = null; + for (DomainPingConfiguration conf : d.getConfiguredPings()) { + if (conf.getType() == PingType.HTTP) { + dpc = conf; + break; + } + } + if (dpc == null) { + fail("Http config not found"); + } + String res = executeBasicWebInteraction(cookie, u2.getPath(), "configId=" + dpc.getId()); + assertThat(res, containsString("only allowed after")); + } } private String readHTTP(String token) throws IOException { - URL u = new URL("http://" + getTestProps().getProperty("domain.http") + "/cacert-" + token + ".txt"); - return IOUtils.readURL(new InputStreamReader(u.openStream())).trim(); + String httpDom = getTestProps().getProperty("domain.http"); + assumeNotNull(httpDom); + URL u = new URL("http://" + httpDom + "/cacert-" + token + ".txt"); + return IOUtils.readURL(new InputStreamReader(u.openStream(), "UTF-8")).trim(); } }