mirror of
https://github.com/google/nomulus.git
synced 2025-06-22 12:20:46 +02:00
Update the initial value for lastExpiringCertNotificationSentDate to START_OF_TIME (#1321)
* Update the initial value for lastExpiringCertNotificationSentDate to START_OF_TIME
This commit is contained in:
parent
d5a91e7218
commit
1d14e96c9b
2 changed files with 14 additions and 12 deletions
|
@ -33,7 +33,6 @@ import java.security.interfaces.ECPublicKey;
|
|||
import java.security.interfaces.RSAPublicKey;
|
||||
import java.util.Date;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
import org.bouncycastle.jcajce.provider.asymmetric.util.EC5Util;
|
||||
import org.bouncycastle.jce.ECNamedCurveTable;
|
||||
|
@ -228,7 +227,7 @@ public class CertificateChecker {
|
|||
|
||||
/** Returns whether the client should receive a notification email. */
|
||||
public boolean shouldReceiveExpiringNotification(
|
||||
@Nullable DateTime lastExpiringNotificationSentDate, String certificateStr) {
|
||||
DateTime lastExpiringNotificationSentDate, String certificateStr) {
|
||||
X509Certificate certificate = getCertificate(certificateStr);
|
||||
DateTime now = clock.nowUtc();
|
||||
// expiration date is one day after lastValidDate
|
||||
|
@ -238,13 +237,13 @@ public class CertificateChecker {
|
|||
}
|
||||
/*
|
||||
* Client should receive a notification if :
|
||||
* 1) client has never received notification and the certificate has entered
|
||||
* the expiring period, OR
|
||||
* 1) client has never received notification (lastExpiringNotificationSentDate is initially
|
||||
* set to START_OF_TIME) and the certificate has entered the expiring period, OR
|
||||
* 2) client has received notification but the interval between now and
|
||||
* lastExpiringNotificationSentDate is greater than expirationWarningIntervalDays.
|
||||
*/
|
||||
return !lastValidDate.after(now.plusDays(expirationWarningDays).toDate())
|
||||
&& (lastExpiringNotificationSentDate == null
|
||||
&& (lastExpiringNotificationSentDate == START_OF_TIME
|
||||
|| !lastExpiringNotificationSentDate
|
||||
.plusDays(expirationWarningIntervalDays)
|
||||
.toDate()
|
||||
|
|
|
@ -262,7 +262,7 @@ class CertificateCheckerTest {
|
|||
DateTime.parse("2021-10-01T00:00:00Z"))
|
||||
.cert();
|
||||
String certificateStr = certificateChecker.serializeCertificate(certificate);
|
||||
assertThat(certificateChecker.shouldReceiveExpiringNotification(null, certificateStr))
|
||||
assertThat(certificateChecker.shouldReceiveExpiringNotification(START_OF_TIME, certificateStr))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
|
@ -276,7 +276,7 @@ class CertificateCheckerTest {
|
|||
DateTime.parse("2021-10-01T00:00:00Z"))
|
||||
.cert();
|
||||
String certificateStr = certificateChecker.serializeCertificate(certificate);
|
||||
assertThat(certificateChecker.shouldReceiveExpiringNotification(null, certificateStr))
|
||||
assertThat(certificateChecker.shouldReceiveExpiringNotification(START_OF_TIME, certificateStr))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
|
@ -307,12 +307,14 @@ class CertificateCheckerTest {
|
|||
DateTime.parse("2021-01-30T00:00:00Z"))
|
||||
.cert();
|
||||
String certificateStr = certificateChecker.serializeCertificate(certificate);
|
||||
assertThat(certificateChecker.shouldReceiveExpiringNotification(null, certificateStr)).isTrue();
|
||||
assertThat(certificateChecker.shouldReceiveExpiringNotification(START_OF_TIME, certificateStr))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_shouldReceiveExpiringNotification_returnsFalse_between30and15_lastSentDateIsNotNull()
|
||||
throws Exception {
|
||||
void
|
||||
test_shouldReceiveExpiringNotification_returnsFalse_between30and15_lastSentDateIsNotStartOfTime()
|
||||
throws Exception {
|
||||
fakeClock.setTo(DateTime.parse("2021-07-05T00:00:00Z"));
|
||||
X509Certificate certificate =
|
||||
SelfSignedCaCertificate.create(
|
||||
|
@ -329,7 +331,7 @@ class CertificateCheckerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
void test_shouldReceiveExpiringNotification_returnsTrue_between30and15_lastSentDateIsNull()
|
||||
void test_shouldReceiveExpiringNotification_returnsTrue_between30and15_lastSentDateIsStartOfTime()
|
||||
throws Exception {
|
||||
fakeClock.setTo(DateTime.parse("2021-07-05T00:00:00Z"));
|
||||
X509Certificate certificate =
|
||||
|
@ -339,7 +341,8 @@ class CertificateCheckerTest {
|
|||
DateTime.parse("2021-07-25T00:00:00Z"))
|
||||
.cert();
|
||||
String certificateStr = certificateChecker.serializeCertificate(certificate);
|
||||
assertThat(certificateChecker.shouldReceiveExpiringNotification(null, certificateStr)).isTrue();
|
||||
assertThat(certificateChecker.shouldReceiveExpiringNotification(START_OF_TIME, certificateStr))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue