X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=tests%2Forg%2Fcacert%2Fgigi%2Fping%2FTestSSL.java;h=fe2db568fe09b6f4b97bd2684e225516d3600134;hp=04b5a6468020dc983ed5b90973df29020036f386;hb=e9bc2a58c7f2cefa106c3570bc8f4824c75b4679;hpb=e409ba881965634f63f0b67824bc93dda4ec4327 diff --git a/tests/org/cacert/gigi/ping/TestSSL.java b/tests/org/cacert/gigi/ping/TestSSL.java index 04b5a646..fe2db568 100644 --- a/tests/org/cacert/gigi/ping/TestSSL.java +++ b/tests/org/cacert/gigi/ping/TestSSL.java @@ -1,6 +1,7 @@ package org.cacert.gigi.ping; import static org.junit.Assert.*; +import static org.junit.Assume.*; import java.io.IOException; import java.net.Socket; @@ -29,12 +30,13 @@ import javax.net.ssl.X509TrustManager; import org.cacert.gigi.GigiApiException; import org.cacert.gigi.dbObjects.Certificate; -import org.cacert.gigi.dbObjects.CertificateProfile; import org.cacert.gigi.dbObjects.Certificate.CSRType; -import org.cacert.gigi.pages.account.DomainOverview; +import org.cacert.gigi.dbObjects.CertificateProfile; +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.TestEmailReciever.TestMail; +import org.cacert.gigi.testUtils.TestEmailReceiver.TestMail; import org.junit.Test; public class TestSSL extends PingTest { @@ -43,27 +45,27 @@ public class TestSSL extends PingTest { private Certificate c; - @Test + @Test(timeout = 70000) public void sslAndMailSuccess() throws IOException, InterruptedException, SQLException, GeneralSecurityException, GigiApiException { testEmailAndSSL(0, 0, true); } - @Test + @Test(timeout = 70000) public void sslWongTypeAndMailSuccess() throws IOException, InterruptedException, SQLException, GeneralSecurityException, GigiApiException { testEmailAndSSL(1, 0, true); } - @Test + @Test(timeout = 70000) public void sslOneMissingAndMailSuccess() throws IOException, InterruptedException, SQLException, GeneralSecurityException, GigiApiException { testEmailAndSSL(2, 0, true); } - @Test + @Test(timeout = 70000) public void sslBothMissingAndMailSuccess() throws IOException, InterruptedException, SQLException, GeneralSecurityException, GigiApiException { testEmailAndSSL(3, 0, true); } - @Test + @Test(timeout = 70000) public void sslWrongTypeAndMailFail() throws IOException, InterruptedException, SQLException, GeneralSecurityException, GigiApiException { testEmailAndSSL(1, 1, false); } @@ -88,7 +90,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); initailizeDomainForm(u); @@ -104,7 +106,7 @@ public class TestSSL extends PingTest { sss.close(); } } - String content = "newdomain=" + URLEncoder.encode(test, "UTF-8") + // + String content = "adddomain&newdomain=" + URLEncoder.encode(test, "UTF-8") + // "&emailType=y&email=2&SSLType=y" + // "&ssl-type-0=direct&ssl-port-0=" + port + // "&ssl-type-1=direct&ssl-port-1=" + port2 + // @@ -117,10 +119,9 @@ public class TestSSL extends PingTest { boolean secondsSucceeds = sslVariant != 0; assertTrue(secondsSucceeds ^ acceptSSLServer(sss2)); - TestMail mail = getMailReciever().recieve(); + TestMail mail = getMailReciever().receive(); if (emailVariant == 0) { - String link = mail.extractLink(); - new URL(link).openConnection().getHeaderField(""); + mail.verify(); } waitForPings(3); @@ -137,13 +138,12 @@ public class TestSSL extends PingTest { private void createCertificate(String test, CertificateProfile profile) throws GeneralSecurityException, IOException, SQLException, InterruptedException, GigiApiException { kp = generateKeypair(); String csr = generatePEMCSR(kp, "CN=" + test); - c = new Certificate(userid, "/CN=" + test, "sha256", csr, CSRType.CSR, profile); + c = new Certificate(User.getById(id), Certificate.buildDN("CN", test), "sha256", csr, CSRType.CSR, profile); c.issue(null, "2y").waitFor(60000); } private boolean acceptSSLServer(SSLServerSocket sss) throws IOException { - try { - Socket s = sss.accept(); + try (Socket s = sss.accept()) { s.getOutputStream().write('b'); s.getOutputStream().close(); return true;