X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=tests%2Forg%2Fcacert%2Fgigi%2FTestCertificate.java;h=6ec26d424bc25e610039f67ffe0e638e6ece52c0;hb=1c7e27416fbfffcacf7b6f9a8765e9dd9671c2b7;hp=d8553e1f6c17340da38c2bbbe35602615ec1bad8;hpb=141d084ab4d1165c6ad172519de0a329b440f7f6;p=gigi.git diff --git a/tests/org/cacert/gigi/TestCertificate.java b/tests/org/cacert/gigi/TestCertificate.java index d8553e1f..6ec26d42 100644 --- a/tests/org/cacert/gigi/TestCertificate.java +++ b/tests/org/cacert/gigi/TestCertificate.java @@ -17,7 +17,10 @@ import org.cacert.gigi.dbObjects.Certificate.CertificateStatus; import org.cacert.gigi.dbObjects.Certificate.SANType; import org.cacert.gigi.dbObjects.Certificate.SubjectAlternateName; import org.cacert.gigi.dbObjects.CertificateProfile; +import org.cacert.gigi.dbObjects.Digest; import org.cacert.gigi.dbObjects.User; +import org.cacert.gigi.pages.account.certs.Certificates; +import org.cacert.gigi.testUtils.IOUtils; import org.cacert.gigi.testUtils.ManagedTest; import org.junit.Test; @@ -31,9 +34,9 @@ public class TestCertificate extends ManagedTest { public void testClientCertLoginStates() throws IOException, GeneralSecurityException, SQLException, InterruptedException, GigiApiException { KeyPair kp = generateKeypair(); String key1 = generatePEMCSR(kp, "CN=testmail@example.com"); - Certificate c = new Certificate(u, Certificate.buildDN("CN", "testmail@example.com"), "sha256", key1, CSRType.CSR, CertificateProfile.getById(1)); + Certificate c = new Certificate(u, u, Certificate.buildDN("CN", "testmail@example.com"), Digest.SHA256, key1, CSRType.CSR, CertificateProfile.getById(1)); final PrivateKey pk = kp.getPrivate(); - c.issue(null, "2y").waitFor(60000); + c.issue(null, "2y", u).waitFor(60000); final X509Certificate ce = c.cert(); assertNotNull(login(pk, ce)); } @@ -42,11 +45,11 @@ public class TestCertificate extends ManagedTest { public void testSANs() throws IOException, GeneralSecurityException, SQLException, InterruptedException, GigiApiException { KeyPair kp = generateKeypair(); String key = generatePEMCSR(kp, "CN=testmail@example.com"); - Certificate c = new Certificate(u, Certificate.buildDN("CN", "testmail@example.com"), "sha256", key, CSRType.CSR, CertificateProfile.getById(1),// + Certificate c = new Certificate(u, u, Certificate.buildDN("CN", "testmail@example.com"), Digest.SHA256, key, CSRType.CSR, CertificateProfile.getById(1),// new SubjectAlternateName(SANType.EMAIL, "testmail@example.com"), new SubjectAlternateName(SANType.DNS, "testmail.example.com")); testFails(CertificateStatus.DRAFT, c); - c.issue(null, "2y").waitFor(60000); + c.issue(null, "2y", u).waitFor(60000); X509Certificate cert = c.cert(); Collection> sans = cert.getSubjectAlternativeNames(); assertEquals(2, sans.size()); @@ -75,6 +78,7 @@ public class TestCertificate extends ManagedTest { testFails(CertificateStatus.ISSUED, c); Certificate c2 = Certificate.getBySerial(c.getSerial()); + assertNotNull(c2); assertEquals(2, c2.getSANs().size()); assertEquals(c.getSANs().get(0).getName(), c2.getSANs().get(0).getName()); assertEquals(c.getSANs().get(0).getType(), c2.getSANs().get(0).getType()); @@ -93,20 +97,25 @@ public class TestCertificate extends ManagedTest { public void testCertLifeCycle() throws IOException, GeneralSecurityException, SQLException, InterruptedException, GigiApiException { KeyPair kp = generateKeypair(); String key = generatePEMCSR(kp, "CN=testmail@example.com"); - Certificate c = new Certificate(u, Certificate.buildDN("CN", "testmail@example.com"), "sha256", key, CSRType.CSR, CertificateProfile.getById(1)); + Certificate c = new Certificate(u, u, Certificate.buildDN("CN", "testmail@example.com"), Digest.SHA256, key, CSRType.CSR, CertificateProfile.getById(1)); final PrivateKey pk = kp.getPrivate(); testFails(CertificateStatus.DRAFT, c); - c.issue(null, "2y").waitFor(60000); + c.issue(null, "2y", u).waitFor(60000); + String cookie = login(u.getEmail(), TEST_PASSWORD); testFails(CertificateStatus.ISSUED, c); X509Certificate cert = c.cert(); assertNotNull(login(pk, cert)); + assertEquals(1, countRegex(IOUtils.readURL(get(cookie, Certificates.PATH)), "(?:revoked|issued)")); + assertEquals(1, countRegex(IOUtils.readURL(get(cookie, Certificates.PATH + "?withRevoked")), "(?:revoked|issued)")); c.revoke().waitFor(60000); testFails(CertificateStatus.REVOKED, c); assertNull(login(pk, cert)); + assertEquals(0, countRegex(IOUtils.readURL(get(cookie, Certificates.PATH)), "(?:revoked|issued)")); + assertEquals(1, countRegex(IOUtils.readURL(get(cookie, Certificates.PATH + "?withRevoked")), "(?:revoked|issued)")); } private void testFails(CertificateStatus status, Certificate c) throws IOException, GeneralSecurityException, SQLException, GigiApiException { @@ -121,7 +130,7 @@ public class TestCertificate extends ManagedTest { } if (status != CertificateStatus.DRAFT) { try { - c.issue(null, "2y"); + c.issue(null, "2y", u); fail(status + " is in invalid state"); } catch (IllegalStateException ise) {