mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 08:27:14 +02:00
Refactor threat emails for daily+monthly usage
Eventually the Publish action will control daily/monthly sending and provide the correct threats to email. The goal of this PR is to entirely separate the "sending email" functionality from the "parsing threat matches" functionality. The PublishAction will figure out if the monthly emails should be sent out, then will ask the Spec11ThreatMatchesParser for the monthly threats (if appropriate) and the new threat matches for today. It will then pass those matches and the appropriate email subject+body to the email utils class, whose only job is to format and send the emails. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=224869643
This commit is contained in:
parent
4dad0a8a73
commit
ea154a8378
4 changed files with 77 additions and 42 deletions
|
@ -22,6 +22,7 @@ import static javax.servlet.http.HttpServletResponse.SC_OK;
|
||||||
|
|
||||||
import com.google.api.services.dataflow.Dataflow;
|
import com.google.api.services.dataflow.Dataflow;
|
||||||
import com.google.api.services.dataflow.model.Job;
|
import com.google.api.services.dataflow.model.Job;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.flogger.FluentLogger;
|
import com.google.common.flogger.FluentLogger;
|
||||||
import com.google.common.net.MediaType;
|
import com.google.common.net.MediaType;
|
||||||
import google.registry.config.RegistryConfig.Config;
|
import google.registry.config.RegistryConfig.Config;
|
||||||
|
@ -31,15 +32,17 @@ import google.registry.request.Parameter;
|
||||||
import google.registry.request.Response;
|
import google.registry.request.Response;
|
||||||
import google.registry.request.auth.Auth;
|
import google.registry.request.auth.Auth;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
|
import org.json.JSONException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retries until a {@code Dataflow} job with a given {@code jobId} completes, continuing the Spec11
|
* Retries until a {@code Dataflow} job with a given {@code jobId} completes, continuing the Spec11
|
||||||
* pipeline accordingly.
|
* pipeline accordingly.
|
||||||
*
|
*
|
||||||
* <p>This calls {@link Spec11EmailUtils#emailSpec11Reports()} on success or {@link
|
* <p>This calls {@link Spec11EmailUtils#emailSpec11Reports(String, String, List)} ()} on success or
|
||||||
* Spec11EmailUtils#sendAlertEmail(String, String)} on failure.
|
* {@link Spec11EmailUtils#sendAlertEmail(String, String)} on failure.
|
||||||
*/
|
*/
|
||||||
@Action(path = PublishSpec11ReportAction.PATH, method = POST, auth = Auth.AUTH_INTERNAL_OR_ADMIN)
|
@Action(path = PublishSpec11ReportAction.PATH, method = POST, auth = Auth.AUTH_INTERNAL_OR_ADMIN)
|
||||||
public class PublishSpec11ReportAction implements Runnable {
|
public class PublishSpec11ReportAction implements Runnable {
|
||||||
|
@ -51,8 +54,10 @@ public class PublishSpec11ReportAction implements Runnable {
|
||||||
private static final String JOB_FAILED = "JOB_STATE_FAILED";
|
private static final String JOB_FAILED = "JOB_STATE_FAILED";
|
||||||
|
|
||||||
private final String projectId;
|
private final String projectId;
|
||||||
|
private final String spec11EmailBodyTemplate;
|
||||||
private final String jobId;
|
private final String jobId;
|
||||||
private final Spec11EmailUtils emailUtils;
|
private final Spec11EmailUtils emailUtils;
|
||||||
|
private final Spec11RegistrarThreatMatchesParser spec11RegistrarThreatMatchesParser;
|
||||||
private final Dataflow dataflow;
|
private final Dataflow dataflow;
|
||||||
private final Response response;
|
private final Response response;
|
||||||
private final LocalDate date;
|
private final LocalDate date;
|
||||||
|
@ -60,14 +65,18 @@ public class PublishSpec11ReportAction implements Runnable {
|
||||||
@Inject
|
@Inject
|
||||||
PublishSpec11ReportAction(
|
PublishSpec11ReportAction(
|
||||||
@Config("projectId") String projectId,
|
@Config("projectId") String projectId,
|
||||||
|
@Config("spec11EmailBodyTemplate") String spec11EmailBodyTemplate,
|
||||||
@Parameter(ReportingModule.PARAM_JOB_ID) String jobId,
|
@Parameter(ReportingModule.PARAM_JOB_ID) String jobId,
|
||||||
Spec11EmailUtils emailUtils,
|
Spec11EmailUtils emailUtils,
|
||||||
|
Spec11RegistrarThreatMatchesParser spec11RegistrarThreatMatchesParser,
|
||||||
Dataflow dataflow,
|
Dataflow dataflow,
|
||||||
Response response,
|
Response response,
|
||||||
LocalDate date) {
|
LocalDate date) {
|
||||||
this.projectId = projectId;
|
this.projectId = projectId;
|
||||||
|
this.spec11EmailBodyTemplate = spec11EmailBodyTemplate;
|
||||||
this.jobId = jobId;
|
this.jobId = jobId;
|
||||||
this.emailUtils = emailUtils;
|
this.emailUtils = emailUtils;
|
||||||
|
this.spec11RegistrarThreatMatchesParser = spec11RegistrarThreatMatchesParser;
|
||||||
this.dataflow = dataflow;
|
this.dataflow = dataflow;
|
||||||
this.response = response;
|
this.response = response;
|
||||||
this.date = date;
|
this.date = date;
|
||||||
|
@ -85,7 +94,10 @@ public class PublishSpec11ReportAction implements Runnable {
|
||||||
"Dataflow job %s finished successfully, publishing results if appropriate.", jobId);
|
"Dataflow job %s finished successfully, publishing results if appropriate.", jobId);
|
||||||
response.setStatus(SC_OK);
|
response.setStatus(SC_OK);
|
||||||
if (shouldSendSpec11Email()) {
|
if (shouldSendSpec11Email()) {
|
||||||
emailUtils.emailSpec11Reports();
|
ImmutableList<RegistrarThreatMatches> matchesList =
|
||||||
|
spec11RegistrarThreatMatchesParser.getRegistrarThreatMatches();
|
||||||
|
String subject = String.format("Google Registry Monthly Threat Detector [%s]", date);
|
||||||
|
emailUtils.emailSpec11Reports(spec11EmailBodyTemplate, subject, matchesList);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case JOB_FAILED:
|
case JOB_FAILED:
|
||||||
|
@ -100,7 +112,7 @@ public class PublishSpec11ReportAction implements Runnable {
|
||||||
response.setStatus(SC_NOT_MODIFIED);
|
response.setStatus(SC_NOT_MODIFIED);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException | JSONException e) {
|
||||||
logger.atSevere().withCause(e).log("Failed to publish Spec11 reports.");
|
logger.atSevere().withCause(e).log("Failed to publish Spec11 reports.");
|
||||||
emailUtils.sendAlertEmail(
|
emailUtils.sendAlertEmail(
|
||||||
String.format("Spec11 Publish Failure %s", date),
|
String.format("Spec11 Publish Failure %s", date),
|
||||||
|
|
|
@ -16,63 +16,58 @@ package google.registry.reporting.spec11;
|
||||||
|
|
||||||
import static com.google.common.base.Throwables.getRootCause;
|
import static com.google.common.base.Throwables.getRootCause;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import google.registry.beam.spec11.ThreatMatch;
|
import google.registry.beam.spec11.ThreatMatch;
|
||||||
import google.registry.config.RegistryConfig.Config;
|
import google.registry.config.RegistryConfig.Config;
|
||||||
import google.registry.util.Retrier;
|
import google.registry.util.Retrier;
|
||||||
import google.registry.util.SendEmailService;
|
import google.registry.util.SendEmailService;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.mail.Message;
|
import javax.mail.Message;
|
||||||
import javax.mail.Message.RecipientType;
|
import javax.mail.Message.RecipientType;
|
||||||
import javax.mail.MessagingException;
|
import javax.mail.MessagingException;
|
||||||
import javax.mail.internet.InternetAddress;
|
import javax.mail.internet.InternetAddress;
|
||||||
import org.joda.time.YearMonth;
|
import org.joda.time.LocalDate;
|
||||||
|
|
||||||
/** Provides e-mail functionality for Spec11 tasks, such as sending Spec11 reports to registrars. */
|
/** Provides e-mail functionality for Spec11 tasks, such as sending Spec11 reports to registrars. */
|
||||||
public class Spec11EmailUtils {
|
public class Spec11EmailUtils {
|
||||||
|
|
||||||
private final SendEmailService emailService;
|
private final SendEmailService emailService;
|
||||||
private final YearMonth yearMonth;
|
private final LocalDate date;
|
||||||
private final String outgoingEmailAddress;
|
private final String outgoingEmailAddress;
|
||||||
private final String alertRecipientAddress;
|
private final String alertRecipientAddress;
|
||||||
private final String spec11ReplyToAddress;
|
private final String spec11ReplyToAddress;
|
||||||
private final String spec11EmailBodyTemplate;
|
|
||||||
private final Spec11RegistrarThreatMatchesParser spec11RegistrarThreatMatchesParser;
|
|
||||||
private final Retrier retrier;
|
private final Retrier retrier;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
Spec11EmailUtils(
|
Spec11EmailUtils(
|
||||||
SendEmailService emailService,
|
SendEmailService emailService,
|
||||||
YearMonth yearMonth,
|
LocalDate date,
|
||||||
@Config("gSuiteOutgoingEmailAddress") String outgoingEmailAddress,
|
@Config("gSuiteOutgoingEmailAddress") String outgoingEmailAddress,
|
||||||
@Config("alertRecipientEmailAddress") String alertRecipientAddress,
|
@Config("alertRecipientEmailAddress") String alertRecipientAddress,
|
||||||
@Config("spec11ReplyToEmailAddress") String spec11ReplyToAddress,
|
@Config("spec11ReplyToEmailAddress") String spec11ReplyToAddress,
|
||||||
@Config("spec11EmailBodyTemplate") String spec11EmailBodyTemplate,
|
|
||||||
Spec11RegistrarThreatMatchesParser spec11RegistrarThreatMatchesParser,
|
|
||||||
Retrier retrier) {
|
Retrier retrier) {
|
||||||
this.emailService = emailService;
|
this.emailService = emailService;
|
||||||
this.yearMonth = yearMonth;
|
this.date = date;
|
||||||
this.outgoingEmailAddress = outgoingEmailAddress;
|
this.outgoingEmailAddress = outgoingEmailAddress;
|
||||||
this.alertRecipientAddress = alertRecipientAddress;
|
this.alertRecipientAddress = alertRecipientAddress;
|
||||||
this.spec11ReplyToAddress = spec11ReplyToAddress;
|
this.spec11ReplyToAddress = spec11ReplyToAddress;
|
||||||
this.spec11RegistrarThreatMatchesParser = spec11RegistrarThreatMatchesParser;
|
|
||||||
this.spec11EmailBodyTemplate = spec11EmailBodyTemplate;
|
|
||||||
this.retrier = retrier;
|
this.retrier = retrier;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes a Spec11 report on GCS for a given month and e-mails registrars based on the
|
* Processes a list of registrar/list-of-threat pairings and sends a notification email to the
|
||||||
* contents.
|
* appropriate address.
|
||||||
*/
|
*/
|
||||||
void emailSpec11Reports() {
|
void emailSpec11Reports(
|
||||||
|
String spec11EmailBodyTemplate,
|
||||||
|
String subject,
|
||||||
|
List<RegistrarThreatMatches> registrarThreatMatchesList) {
|
||||||
try {
|
try {
|
||||||
retrier.callWithRetry(
|
retrier.callWithRetry(
|
||||||
() -> {
|
() -> {
|
||||||
ImmutableList<RegistrarThreatMatches> registrarThreatMatchesList =
|
|
||||||
spec11RegistrarThreatMatchesParser.getRegistrarThreatMatches();
|
|
||||||
for (RegistrarThreatMatches registrarThreatMatches : registrarThreatMatchesList) {
|
for (RegistrarThreatMatches registrarThreatMatches : registrarThreatMatchesList) {
|
||||||
emailRegistrar(registrarThreatMatches);
|
emailRegistrar(spec11EmailBodyTemplate, subject, registrarThreatMatches);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
IOException.class,
|
IOException.class,
|
||||||
|
@ -80,16 +75,17 @@ public class Spec11EmailUtils {
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
// Send an alert with the root cause, unwrapping the retrier's RuntimeException
|
// Send an alert with the root cause, unwrapping the retrier's RuntimeException
|
||||||
sendAlertEmail(
|
sendAlertEmail(
|
||||||
String.format("Spec11 Emailing Failure %s", yearMonth.toString()),
|
String.format("Spec11 Emailing Failure %s", date),
|
||||||
String.format("Emailing spec11 reports failed due to %s", getRootCause(e).getMessage()));
|
String.format("Emailing spec11 reports failed due to %s", getRootCause(e).getMessage()));
|
||||||
throw new RuntimeException("Emailing spec11 report failed", e);
|
throw new RuntimeException("Emailing spec11 report failed", e);
|
||||||
}
|
}
|
||||||
sendAlertEmail(
|
sendAlertEmail(
|
||||||
String.format("Spec11 Pipeline Success %s", yearMonth.toString()),
|
String.format("Spec11 Pipeline Success %s", date),
|
||||||
"Spec11 reporting completed successfully.");
|
"Spec11 reporting completed successfully.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void emailRegistrar(RegistrarThreatMatches registrarThreatMatches)
|
private void emailRegistrar(
|
||||||
|
String spec11EmailBodyTemplate, String subject, RegistrarThreatMatches registrarThreatMatches)
|
||||||
throws MessagingException {
|
throws MessagingException {
|
||||||
String registrarEmail = registrarThreatMatches.registrarEmailAddress();
|
String registrarEmail = registrarThreatMatches.registrarEmailAddress();
|
||||||
StringBuilder threatList = new StringBuilder();
|
StringBuilder threatList = new StringBuilder();
|
||||||
|
@ -103,8 +99,7 @@ public class Spec11EmailUtils {
|
||||||
.replace("{REPLY_TO_EMAIL}", spec11ReplyToAddress)
|
.replace("{REPLY_TO_EMAIL}", spec11ReplyToAddress)
|
||||||
.replace("{LIST_OF_THREATS}", threatList.toString());
|
.replace("{LIST_OF_THREATS}", threatList.toString());
|
||||||
Message msg = emailService.createMessage();
|
Message msg = emailService.createMessage();
|
||||||
msg.setSubject(
|
msg.setSubject(subject);
|
||||||
String.format("Google Registry Monthly Threat Detector [%s]", yearMonth.toString()));
|
|
||||||
msg.setText(body);
|
msg.setText(body);
|
||||||
msg.setFrom(new InternetAddress(outgoingEmailAddress));
|
msg.setFrom(new InternetAddress(outgoingEmailAddress));
|
||||||
msg.addRecipient(RecipientType.TO, new InternetAddress(registrarEmail));
|
msg.addRecipient(RecipientType.TO, new InternetAddress(registrarEmail));
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
package google.registry.reporting.spec11;
|
package google.registry.reporting.spec11;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static google.registry.reporting.spec11.Spec11RegistrarThreatMatchesParserTest.sampleThreatMatches;
|
||||||
import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
|
import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
|
||||||
import static javax.servlet.http.HttpServletResponse.SC_NOT_MODIFIED;
|
import static javax.servlet.http.HttpServletResponse.SC_NOT_MODIFIED;
|
||||||
import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT;
|
import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT;
|
||||||
|
@ -42,18 +43,22 @@ import org.junit.runners.JUnit4;
|
||||||
@RunWith(JUnit4.class)
|
@RunWith(JUnit4.class)
|
||||||
public class PublishSpec11ReportActionTest {
|
public class PublishSpec11ReportActionTest {
|
||||||
|
|
||||||
|
private final String spec11BodyTemplate = "{LIST_OF_THREATS}\n{REPLY_TO_EMAIL}";
|
||||||
|
private final LocalDate date = new LocalDate(2018, 6, 5);
|
||||||
|
|
||||||
private Dataflow dataflow;
|
private Dataflow dataflow;
|
||||||
private Projects projects;
|
private Projects projects;
|
||||||
private Jobs jobs;
|
private Jobs jobs;
|
||||||
private Get get;
|
private Get get;
|
||||||
private Spec11EmailUtils emailUtils;
|
private Spec11EmailUtils emailUtils;
|
||||||
|
private Spec11RegistrarThreatMatchesParser parser;
|
||||||
|
|
||||||
private Job expectedJob;
|
private Job expectedJob;
|
||||||
private FakeResponse response;
|
private FakeResponse response;
|
||||||
private PublishSpec11ReportAction publishAction;
|
private PublishSpec11ReportAction publishAction;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws IOException {
|
public void setUp() throws Exception {
|
||||||
dataflow = mock(Dataflow.class);
|
dataflow = mock(Dataflow.class);
|
||||||
projects = mock(Projects.class);
|
projects = mock(Projects.class);
|
||||||
jobs = mock(Jobs.class);
|
jobs = mock(Jobs.class);
|
||||||
|
@ -65,20 +70,40 @@ public class PublishSpec11ReportActionTest {
|
||||||
when(get.execute()).thenReturn(expectedJob);
|
when(get.execute()).thenReturn(expectedJob);
|
||||||
emailUtils = mock(Spec11EmailUtils.class);
|
emailUtils = mock(Spec11EmailUtils.class);
|
||||||
response = new FakeResponse();
|
response = new FakeResponse();
|
||||||
|
parser = mock(Spec11RegistrarThreatMatchesParser.class);
|
||||||
|
when(parser.getRegistrarThreatMatches()).thenReturn(sampleThreatMatches());
|
||||||
publishAction =
|
publishAction =
|
||||||
new PublishSpec11ReportAction(
|
new PublishSpec11ReportAction(
|
||||||
"test-project", "12345", emailUtils, dataflow, response, new LocalDate(2018, 6, 5));
|
"test-project",
|
||||||
|
spec11BodyTemplate,
|
||||||
|
"12345",
|
||||||
|
emailUtils,
|
||||||
|
mock(Spec11RegistrarThreatMatchesParser.class),
|
||||||
|
dataflow,
|
||||||
|
response,
|
||||||
|
date);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJobDone_emailsResultsOnSecondOfMonth() {
|
public void testJobDone_emailsResultsOnSecondOfMonth() throws Exception {
|
||||||
expectedJob.setCurrentState("JOB_STATE_DONE");
|
expectedJob.setCurrentState("JOB_STATE_DONE");
|
||||||
publishAction =
|
publishAction =
|
||||||
new PublishSpec11ReportAction(
|
new PublishSpec11ReportAction(
|
||||||
"test-project", "12345", emailUtils, dataflow, response, new LocalDate(2018, 6, 2));
|
"test-project",
|
||||||
|
spec11BodyTemplate,
|
||||||
|
"12345",
|
||||||
|
emailUtils,
|
||||||
|
parser,
|
||||||
|
dataflow,
|
||||||
|
response,
|
||||||
|
date.withDayOfMonth(2));
|
||||||
publishAction.run();
|
publishAction.run();
|
||||||
assertThat(response.getStatus()).isEqualTo(SC_OK);
|
assertThat(response.getStatus()).isEqualTo(SC_OK);
|
||||||
verify(emailUtils).emailSpec11Reports();
|
verify(emailUtils)
|
||||||
|
.emailSpec11Reports(
|
||||||
|
spec11BodyTemplate,
|
||||||
|
"Google Registry Monthly Threat Detector [2018-06-02]",
|
||||||
|
sampleThreatMatches());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -39,7 +39,7 @@ import javax.mail.MessagingException;
|
||||||
import javax.mail.Session;
|
import javax.mail.Session;
|
||||||
import javax.mail.internet.InternetAddress;
|
import javax.mail.internet.InternetAddress;
|
||||||
import javax.mail.internet.MimeMessage;
|
import javax.mail.internet.MimeMessage;
|
||||||
import org.joda.time.YearMonth;
|
import org.joda.time.LocalDate;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
@ -73,18 +73,19 @@ public class Spec11EmailUtilsTest {
|
||||||
emailUtils =
|
emailUtils =
|
||||||
new Spec11EmailUtils(
|
new Spec11EmailUtils(
|
||||||
emailService,
|
emailService,
|
||||||
new YearMonth(2018, 7),
|
new LocalDate(2018, 7, 15),
|
||||||
"my-sender@test.com",
|
"my-sender@test.com",
|
||||||
"my-receiver@test.com",
|
"my-receiver@test.com",
|
||||||
"my-reply-to@test.com",
|
"my-reply-to@test.com",
|
||||||
"{LIST_OF_THREATS}\n{REPLY_TO_EMAIL}",
|
|
||||||
parser,
|
|
||||||
new Retrier(new FakeSleeper(new FakeClock()), RETRY_COUNT));
|
new Retrier(new FakeSleeper(new FakeClock()), RETRY_COUNT));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_emailSpec11Reports() throws MessagingException, IOException {
|
public void testSuccess_emailSpec11Reports() throws Exception {
|
||||||
emailUtils.emailSpec11Reports();
|
emailUtils.emailSpec11Reports(
|
||||||
|
"{LIST_OF_THREATS}\n{REPLY_TO_EMAIL}",
|
||||||
|
"Google Registry Monthly Threat Detector [2018-07-15]",
|
||||||
|
sampleThreatMatches());
|
||||||
// We inspect individual parameters because Message doesn't implement equals().
|
// We inspect individual parameters because Message doesn't implement equals().
|
||||||
verify(emailService, times(3)).sendMessage(gotMessage.capture());
|
verify(emailService, times(3)).sendMessage(gotMessage.capture());
|
||||||
List<Message> capturedMessages = gotMessage.getAllValues();
|
List<Message> capturedMessages = gotMessage.getAllValues();
|
||||||
|
@ -93,21 +94,21 @@ public class Spec11EmailUtilsTest {
|
||||||
"my-sender@test.com",
|
"my-sender@test.com",
|
||||||
"a@fake.com",
|
"a@fake.com",
|
||||||
"my-reply-to@test.com",
|
"my-reply-to@test.com",
|
||||||
"Google Registry Monthly Threat Detector [2018-07]",
|
"Google Registry Monthly Threat Detector [2018-07-15]",
|
||||||
"a.com - MALWARE\n\nmy-reply-to@test.com");
|
"a.com - MALWARE\n\nmy-reply-to@test.com");
|
||||||
validateMessage(
|
validateMessage(
|
||||||
capturedMessages.get(1),
|
capturedMessages.get(1),
|
||||||
"my-sender@test.com",
|
"my-sender@test.com",
|
||||||
"b@fake.com",
|
"b@fake.com",
|
||||||
"my-reply-to@test.com",
|
"my-reply-to@test.com",
|
||||||
"Google Registry Monthly Threat Detector [2018-07]",
|
"Google Registry Monthly Threat Detector [2018-07-15]",
|
||||||
"b.com - MALWARE\nc.com - MALWARE\n\nmy-reply-to@test.com");
|
"b.com - MALWARE\nc.com - MALWARE\n\nmy-reply-to@test.com");
|
||||||
validateMessage(
|
validateMessage(
|
||||||
capturedMessages.get(2),
|
capturedMessages.get(2),
|
||||||
"my-sender@test.com",
|
"my-sender@test.com",
|
||||||
"my-receiver@test.com",
|
"my-receiver@test.com",
|
||||||
null,
|
null,
|
||||||
"Spec11 Pipeline Success 2018-07",
|
"Spec11 Pipeline Success 2018-07-15",
|
||||||
"Spec11 reporting completed successfully.");
|
"Spec11 reporting completed successfully.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +137,9 @@ public class Spec11EmailUtilsTest {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
RuntimeException thrown =
|
RuntimeException thrown =
|
||||||
assertThrows(RuntimeException.class, () -> emailUtils.emailSpec11Reports());
|
assertThrows(
|
||||||
|
RuntimeException.class,
|
||||||
|
() -> emailUtils.emailSpec11Reports("foo", "bar", sampleThreatMatches()));
|
||||||
assertThat(thrown).hasMessageThat().isEqualTo("Emailing spec11 report failed");
|
assertThat(thrown).hasMessageThat().isEqualTo("Emailing spec11 report failed");
|
||||||
assertThat(thrown)
|
assertThat(thrown)
|
||||||
.hasCauseThat()
|
.hasCauseThat()
|
||||||
|
@ -151,7 +154,7 @@ public class Spec11EmailUtilsTest {
|
||||||
"my-sender@test.com",
|
"my-sender@test.com",
|
||||||
"my-receiver@test.com",
|
"my-receiver@test.com",
|
||||||
null,
|
null,
|
||||||
"Spec11 Emailing Failure 2018-07",
|
"Spec11 Emailing Failure 2018-07-15",
|
||||||
"Emailing spec11 reports failed due to expected");
|
"Emailing spec11 reports failed due to expected");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue