mirror of
https://github.com/google/nomulus.git
synced 2025-07-07 11:43:24 +02:00
Set payload in success response after sending notification emails (#1377)
* Set payload in success response after sending expiring certificate notification emails * Modify log message and test cases for run() in sendExpiringCertificateNotificationEmailAction
This commit is contained in:
parent
6c4881fa4c
commit
5803215755
2 changed files with 32 additions and 4 deletions
|
@ -55,6 +55,7 @@ import org.joda.time.format.DateTimeFormatter;
|
||||||
path = SendExpiringCertificateNotificationEmailAction.PATH,
|
path = SendExpiringCertificateNotificationEmailAction.PATH,
|
||||||
auth = Auth.AUTH_INTERNAL_OR_ADMIN)
|
auth = Auth.AUTH_INTERNAL_OR_ADMIN)
|
||||||
public class SendExpiringCertificateNotificationEmailAction implements Runnable {
|
public class SendExpiringCertificateNotificationEmailAction implements Runnable {
|
||||||
|
|
||||||
public static final String PATH = "/_dr/task/sendExpiringCertificateNotificationEmail";
|
public static final String PATH = "/_dr/task/sendExpiringCertificateNotificationEmail";
|
||||||
/**
|
/**
|
||||||
* Used as an offset when storing the last notification email sent date.
|
* Used as an offset when storing the last notification email sent date.
|
||||||
|
@ -96,8 +97,13 @@ public class SendExpiringCertificateNotificationEmailAction implements Runnable
|
||||||
public void run() {
|
public void run() {
|
||||||
response.setContentType(MediaType.PLAIN_TEXT_UTF_8);
|
response.setContentType(MediaType.PLAIN_TEXT_UTF_8);
|
||||||
try {
|
try {
|
||||||
sendNotificationEmails();
|
int numEmailsSent = sendNotificationEmails();
|
||||||
|
String message =
|
||||||
|
String.format(
|
||||||
|
"Done. Sent %d expiring certificate notification emails in total.", numEmailsSent);
|
||||||
|
logger.atInfo().log(message);
|
||||||
response.setStatus(SC_OK);
|
response.setStatus(SC_OK);
|
||||||
|
response.setPayload(message);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.atWarning().withCause(e).log(
|
logger.atWarning().withCause(e).log(
|
||||||
"Exception thrown when sending expiring certificate notification emails.");
|
"Exception thrown when sending expiring certificate notification emails.");
|
||||||
|
@ -263,8 +269,6 @@ public class SendExpiringCertificateNotificationEmailAction implements Runnable
|
||||||
emailsSent++;
|
emailsSent++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger.atInfo().log(
|
|
||||||
"Attempted to send %d expiring certificate notification emails.", emailsSent);
|
|
||||||
return emailsSent;
|
return emailsSent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -327,6 +331,7 @@ public class SendExpiringCertificateNotificationEmailAction implements Runnable
|
||||||
|
|
||||||
@AutoValue
|
@AutoValue
|
||||||
public abstract static class RegistrarInfo {
|
public abstract static class RegistrarInfo {
|
||||||
|
|
||||||
static RegistrarInfo create(
|
static RegistrarInfo create(
|
||||||
Registrar registrar, boolean isCertExpiring, boolean isFailOverCertExpiring) {
|
Registrar registrar, boolean isCertExpiring, boolean isFailOverCertExpiring) {
|
||||||
return new AutoValue_SendExpiringCertificateNotificationEmailAction_RegistrarInfo(
|
return new AutoValue_SendExpiringCertificateNotificationEmailAction_RegistrarInfo(
|
||||||
|
|
|
@ -639,9 +639,32 @@ class SendExpiringCertificateNotificationEmailActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestOfyAndSql
|
@TestOfyAndSql
|
||||||
void run_responseStatusIs200() {
|
void run_sentZeroEmail_responseStatusIs200() {
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(response.getStatus()).isEqualTo(SC_OK);
|
assertThat(response.getStatus()).isEqualTo(SC_OK);
|
||||||
|
assertThat(response.getPayload())
|
||||||
|
.isEqualTo("Done. Sent 0 expiring certificate notification emails in total.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestOfyAndSql
|
||||||
|
void run_sentEmails_responseStatusIs200() throws Exception {
|
||||||
|
for (int i = 1; i <= 5; i++) {
|
||||||
|
persistResource(
|
||||||
|
createRegistrar(
|
||||||
|
"id_" + i,
|
||||||
|
"name" + i,
|
||||||
|
SelfSignedCaCertificate.create(
|
||||||
|
"www.example.tld",
|
||||||
|
DateTime.parse("2020-09-02T00:00:00Z"),
|
||||||
|
DateTime.parse("2021-06-01T00:00:00Z"))
|
||||||
|
.cert(),
|
||||||
|
null)
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
action.run();
|
||||||
|
assertThat(response.getStatus()).isEqualTo(SC_OK);
|
||||||
|
assertThat(response.getPayload())
|
||||||
|
.isEqualTo("Done. Sent 5 expiring certificate notification emails in total.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns a sample registrar with a customized registrar name, client id and certificate* */
|
/** Returns a sample registrar with a customized registrar name, client id and certificate* */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue