X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=tests%2Fclub%2Fwpia%2Fgigi%2Fpages%2Faccount%2FTestCertificateRequest.java;h=da580ccf48cae58a5d4aac3db449dc5cb553266b;hp=79edd9327ad207e4ea981d362a3e131248190e0a;hb=753ce950283248b931ee9da5158c88156c21e17d;hpb=15f6a8ada052ca217dc9203b32f9d1fdb2f27e17 diff --git a/tests/club/wpia/gigi/pages/account/TestCertificateRequest.java b/tests/club/wpia/gigi/pages/account/TestCertificateRequest.java index 79edd932..da580ccf 100644 --- a/tests/club/wpia/gigi/pages/account/TestCertificateRequest.java +++ b/tests/club/wpia/gigi/pages/account/TestCertificateRequest.java @@ -6,14 +6,19 @@ import static org.junit.Assert.*; import java.io.IOException; import java.security.GeneralSecurityException; import java.security.KeyPair; +import java.util.Locale; import org.junit.Test; import club.wpia.gigi.GigiApiException; +import club.wpia.gigi.database.GigiPreparedStatement; +import club.wpia.gigi.dbObjects.EmailAddress; import club.wpia.gigi.dbObjects.Group; import club.wpia.gigi.pages.account.certs.CertificateRequest; import club.wpia.gigi.testUtils.ClientTest; +import club.wpia.gigi.testUtils.TestEmailReceiver.TestMail; import club.wpia.gigi.util.AuthorizationContext; +import club.wpia.gigi.util.TimeConditions; public class TestCertificateRequest extends ClientTest { @@ -85,4 +90,50 @@ public class TestCertificateRequest extends ClientTest { } } + + @Test + public void testPingPeriodOneAddress() throws IOException, GeneralSecurityException, GigiApiException { + // get new email address with last ping in past + String furtherEmail = createUniqueName() + "@example.org"; + EmailAddress ea = new EmailAddress(u, furtherEmail, Locale.ENGLISH); + TestMail mail = getMailReceiver().receive(furtherEmail); + try (GigiPreparedStatement stmt = new GigiPreparedStatement("UPDATE `emailPinglog` SET `status`='success'::`pingState`, `when` = (now() - interval '1 months' * ?::INTEGER) WHERE `email`=? ")) { + stmt.setInt(1, TimeConditions.getInstance().getEmailPingMonths()); + stmt.setString(2, furtherEmail); + stmt.executeUpdate(); + } + + try { + CertificateRequest cr = new CertificateRequest(ac, generatePEMCSR(kp, "CN=a ab")); + cr.update("name", "SHA512", "mail", null, null, "email:" + furtherEmail); + cr.draft(); + fail(); + } catch (GigiApiException e) { + assertThat(e.getMessage(), containsString("needs an email ping within the past")); + } + + } + + @Test + public void testPingPeriodTwoAddresses() throws IOException, GeneralSecurityException, GigiApiException { + // get new email address with last ping in past + String furtherEmail = createUniqueName() + "@example.org"; + EmailAddress ea = new EmailAddress(u, furtherEmail, Locale.ENGLISH); + TestMail mail = getMailReceiver().receive(furtherEmail); + try (GigiPreparedStatement stmt = new GigiPreparedStatement("UPDATE `emailPinglog` SET `status`='success'::`pingState`, `when` = (now() - interval '1 months' * ?::INTEGER) WHERE `email`=? ")) { + stmt.setInt(1, TimeConditions.getInstance().getEmailPingMonths()); + stmt.setString(2, furtherEmail); + stmt.executeUpdate(); + } + + try { + CertificateRequest cr = new CertificateRequest(ac, generatePEMCSR(kp, "CN=a ab")); + cr.update("name", "SHA512", "mail", null, null, "email:" + furtherEmail + ",email:" + email); + cr.draft(); + fail(); + } catch (GigiApiException e) { + assertThat(e.getMessage(), containsString("needs an email ping within the past")); + } + + } }