X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=tests%2Fclub%2Fwpia%2Fgigi%2Fpages%2Fadmin%2FTestSEAdminPageCertSearch.java;h=cf9b403b253aa6438b7c38f0483e39832b0120ae;hp=e61f559ee8dfed4918679434a107ec9d74165a46;hb=7c9a443cdc81dfc8129f898d510e13bccc558ee0;hpb=8822b2ffdda7eb4109415a7867388a321ea6b56f diff --git a/tests/club/wpia/gigi/pages/admin/TestSEAdminPageCertSearch.java b/tests/club/wpia/gigi/pages/admin/TestSEAdminPageCertSearch.java index e61f559e..cf9b403b 100644 --- a/tests/club/wpia/gigi/pages/admin/TestSEAdminPageCertSearch.java +++ b/tests/club/wpia/gigi/pages/admin/TestSEAdminPageCertSearch.java @@ -7,6 +7,7 @@ import java.net.URLConnection; import java.net.URLEncoder; import java.security.GeneralSecurityException; import java.security.KeyPair; +import java.text.SimpleDateFormat; import org.hamcrest.CoreMatchers; import org.junit.Test; @@ -15,49 +16,43 @@ import club.wpia.gigi.GigiApiException; import club.wpia.gigi.dbObjects.Certificate; import club.wpia.gigi.dbObjects.Certificate.CSRType; import club.wpia.gigi.dbObjects.Certificate.CertificateStatus; +import club.wpia.gigi.dbObjects.Certificate.RevocationType; import club.wpia.gigi.dbObjects.Certificate.SANType; import club.wpia.gigi.dbObjects.Digest; -import club.wpia.gigi.dbObjects.Group; import club.wpia.gigi.dbObjects.User; +import club.wpia.gigi.output.template.Template; import club.wpia.gigi.pages.account.certs.Certificates; import club.wpia.gigi.pages.admin.support.FindCertPage; -import club.wpia.gigi.pages.admin.support.SupportEnterTicketPage; -import club.wpia.gigi.testUtils.ClientTest; import club.wpia.gigi.testUtils.IOUtils; +import club.wpia.gigi.testUtils.SEClientTest; import club.wpia.gigi.testUtils.TestEmailReceiver.TestMail; import club.wpia.gigi.util.ServerConstants; import club.wpia.gigi.util.ServerConstants.Host; -public class TestSEAdminPageCertSearch extends ClientTest { +public class TestSEAdminPageCertSearch extends SEClientTest { private Certificate c; private String certMail; - public TestSEAdminPageCertSearch() throws IOException, GigiApiException, GeneralSecurityException, InterruptedException { - grant(u, Group.SUPPORTER); - cookie = login(email, TEST_PASSWORD); - assertEquals(302, post(cookie, SupportEnterTicketPage.PATH, "ticketno=a20140808.8&setTicket=action", 0).getResponseCode()); + private int id; + public TestSEAdminPageCertSearch() throws IOException, GigiApiException, GeneralSecurityException, InterruptedException { certMail = uniq + "_certowner@example.com"; - int id = createVerifiedUser("fn", "ln", certMail, TEST_PASSWORD); - User u1 = User.getById(id); - KeyPair kp = generateKeypair(); - String key = generatePEMCSR(kp, "CN=" + certMail); - c = new Certificate(u1, u1, Certificate.buildDN("CN", certMail), Digest.SHA512, key, CSRType.CSR, getClientProfile(), new Certificate.SubjectAlternateName(SANType.EMAIL, certMail)); - await(c.issue(null, "2y", u)); + id = createVerifiedUser("fn", "ln", certMail, TEST_PASSWORD); + c = createCertificate(); } @Test public void testSerialSearch() throws IOException { URLConnection uc = post(cookie, FindCertPage.PATH, "certType=serial&process=Next&cert=" + c.getSerial(), 0); - assertEquals("https://" + ServerConstants.getHostNamePortSecure(Host.WWW) + Certificates.SUPPORT_PATH + "/" + c.getSerial(), uc.getHeaderField("Location")); + assertEquals("https://" + ServerConstants.getHostNamePortSecure(Host.SECURE) + Certificates.SUPPORT_PATH + "/" + c.getSerial(), uc.getHeaderField("Location")); } @Test public void testEmailSearch() throws IOException { URLConnection uc = post(cookie, FindCertPage.PATH, "certType=email&process=Next&cert=" + URLEncoder.encode(certMail, "UTF-8"), 0); - assertEquals("https://" + ServerConstants.getHostNamePortSecure(Host.WWW) + Certificates.SUPPORT_PATH + "/" + c.getSerial(), uc.getHeaderField("Location")); + assertEquals("https://" + ServerConstants.getHostNamePortSecure(Host.SECURE) + Certificates.SUPPORT_PATH + "/" + c.getSerial(), uc.getHeaderField("Location")); } @Test @@ -72,13 +67,34 @@ public class TestSEAdminPageCertSearch extends ClientTest { @Test public void testRevoke() throws IOException { URLConnection conn = post(Certificates.SUPPORT_PATH + "/" + c.getSerial(), "action=revoke"); - assertEquals("https://" + ServerConstants.getHostNamePortSecure(Host.WWW) + Certificates.SUPPORT_PATH + "/" + c.getSerial(), conn.getHeaderField("Location")); + assertEquals("https://" + ServerConstants.getHostNamePortSecure(Host.SECURE) + Certificates.SUPPORT_PATH + "/" + c.getSerial(), conn.getHeaderField("Location")); for (int i = 0; i < 2; i++) { TestMail tm = getMailReceiver().receive(i == 0 ? ServerConstants.getSupportMailAddress() : certMail); assertThat(tm.getMessage(), CoreMatchers.containsString(certMail)); assertThat(tm.getMessage(), CoreMatchers.containsString(c.getSerial())); } assertEquals(CertificateStatus.REVOKED, c.getStatus()); + + } + + @Test + public void testShowRevocation() throws GeneralSecurityException, IOException, GigiApiException, InterruptedException { + Certificate c1 = createCertificate(); + await(c1.revoke(RevocationType.SUPPORT)); + URLConnection uc = post(cookie, FindCertPage.PATH, "certType=email&process=Next&cert=" + URLEncoder.encode(certMail, "UTF-8"), 0); + SimpleDateFormat sdf = new SimpleDateFormat(Template.UTC_TIMESTAMP_FORMAT); + String revokeDate = sdf.format(c1.getRevocationDate()); + String result = IOUtils.readURL(uc); + assertThat(result, CoreMatchers.containsString(revokeDate)); + assertThat(result, CoreMatchers.containsString("N/A")); } + private Certificate createCertificate() throws GeneralSecurityException, IOException, GigiApiException, InterruptedException { + User u1 = User.getById(id); + KeyPair kp = generateKeypair(); + String key = generatePEMCSR(kp, "CN=" + certMail); + Certificate c1 = new Certificate(u1, u1, Certificate.buildDN("CN", certMail), Digest.SHA512, key, CSRType.CSR, getClientProfile(), new Certificate.SubjectAlternateName(SANType.EMAIL, certMail)); + await(c1.issue(null, "2y", u)); + return c1; + } }