Add BCC capabilities to the Spec11 reports (#418)

* Add BCC capabilities to the Spec11 reports
This commit is contained in:
gbrodman 2019-12-18 17:08:06 -05:00 committed by GitHub
parent bfd61ef867
commit 25d43511f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 75 additions and 31 deletions

View file

@ -917,6 +917,20 @@ public final class RegistryConfig {
return parseEmailAddress(config.misc.spec11OutgoingEmailAddress);
}
/**
* Returns the email addresses to which we will BCC Spec11 emails.
*
* @see google.registry.reporting.spec11.Spec11EmailUtils
*/
@Provides
@Config("spec11BccEmailAddresses")
public static ImmutableList<InternetAddress> provideSpec11BccEmailAddresses(
RegistryConfigSettings config) {
return config.misc.spec11BccEmailAddresses.stream()
.map(RegistryConfig::parseEmailAddress)
.collect(toImmutableList());
}
/**
* Returns the name of the registry, for use in spec 11 emails.
*

View file

@ -193,6 +193,7 @@ public class RegistryConfigSettings {
public String sheetExportId;
public String alertRecipientEmailAddress;
public String spec11OutgoingEmailAddress;
public List<String> spec11BccEmailAddresses;
public int asyncDeleteDelaySeconds;
public int transientFailureRetries;
}

View file

@ -389,6 +389,11 @@ misc:
# to be a deliverable email address to handle replies from registrars as well.
spec11OutgoingEmailAddress: abuse@example.com
# Addresses to which we will BCC all Spec11 email reports, in case one
# wishes to examine the output.
spec11BccEmailAddresses:
- abuse@example.com
# How long to delay processing of asynchronous deletions. This should always
# be longer than eppResourceCachingSeconds, to prevent deleted contacts or
# hosts from being used on domains.

View file

@ -58,6 +58,7 @@ public class Spec11EmailUtils {
private final SendEmailService emailService;
private final InternetAddress outgoingEmailAddress;
private final ImmutableList<InternetAddress> spec11BccEmailAddresses;
private final InternetAddress alertRecipientAddress;
private final ImmutableList<String> spec11WebResources;
private final String registryName;
@ -67,10 +68,12 @@ public class Spec11EmailUtils {
SendEmailService emailService,
@Config("alertRecipientEmailAddress") InternetAddress alertRecipientAddress,
@Config("spec11OutgoingEmailAddress") InternetAddress spec11OutgoingEmailAddress,
@Config("spec11BccEmailAddresses") ImmutableList<InternetAddress> spec11BccEmailAddresses,
@Config("spec11WebResources") ImmutableList<String> spec11WebResources,
@Config("registryName") String registryName) {
this.emailService = emailService;
this.outgoingEmailAddress = spec11OutgoingEmailAddress;
this.spec11BccEmailAddresses = spec11BccEmailAddresses;
this.alertRecipientAddress = alertRecipientAddress;
this.spec11WebResources = spec11WebResources;
this.registryName = registryName;
@ -125,11 +128,18 @@ public class Spec11EmailUtils {
private RegistrarThreatMatches filterOutNonPublishedMatches(
RegistrarThreatMatches registrarThreatMatches) {
ImmutableList<ThreatMatch> filteredMatches = registrarThreatMatches.threatMatches().stream()
.filter(threatMatch ->
ofy().load().type(DomainBase.class).filter("fullyQualifiedDomainName",
threatMatch.fullyQualifiedDomainName()).first().now().shouldPublishToDns()
).collect(toImmutableList());
ImmutableList<ThreatMatch> filteredMatches =
registrarThreatMatches.threatMatches().stream()
.filter(
threatMatch ->
ofy()
.load()
.type(DomainBase.class)
.filter("fullyQualifiedDomainName", threatMatch.fullyQualifiedDomainName())
.first()
.now()
.shouldPublishToDns())
.collect(toImmutableList());
return RegistrarThreatMatches.create(registrarThreatMatches.clientId(), filteredMatches);
}
@ -146,7 +156,7 @@ public class Spec11EmailUtils {
.setContentType(MediaType.HTML_UTF_8)
.setFrom(outgoingEmailAddress)
.addRecipient(getEmailAddressForRegistrar(registrarThreatMatches.clientId()))
.setBcc(outgoingEmailAddress)
.setBccs(spec11BccEmailAddresses)
.build());
}

View file

@ -118,6 +118,8 @@ public class Spec11EmailUtilsTest {
emailService,
new InternetAddress("my-receiver@test.com"),
new InternetAddress("abuse@test.com"),
ImmutableList.of(
new InternetAddress("abuse@test.com"), new InternetAddress("bcc@test.com")),
FAKE_RESOURCES,
"Super Cool Registry");
@ -142,7 +144,7 @@ public class Spec11EmailUtilsTest {
capturedContents.get(0),
"abuse@test.com",
"the.registrar@example.com",
Optional.of("abuse@test.com"),
ImmutableList.of("abuse@test.com", "bcc@test.com"),
"Super Cool Registry Monthly Threat Detector [2018-07-15]",
String.format(MONTHLY_EMAIL_FORMAT, "<tr><td>a.com</td><td>MALWARE</td></tr>"),
Optional.of(MediaType.HTML_UTF_8));
@ -150,7 +152,7 @@ public class Spec11EmailUtilsTest {
capturedContents.get(1),
"abuse@test.com",
"new.registrar@example.com",
Optional.of("abuse@test.com"),
ImmutableList.of("abuse@test.com", "bcc@test.com"),
"Super Cool Registry Monthly Threat Detector [2018-07-15]",
String.format(
MONTHLY_EMAIL_FORMAT,
@ -160,7 +162,7 @@ public class Spec11EmailUtilsTest {
capturedContents.get(2),
"abuse@test.com",
"my-receiver@test.com",
Optional.empty(),
ImmutableList.of(),
"Spec11 Pipeline Success 2018-07-15",
"Spec11 reporting completed successfully.",
Optional.empty());
@ -180,7 +182,7 @@ public class Spec11EmailUtilsTest {
capturedMessages.get(0),
"abuse@test.com",
"the.registrar@example.com",
Optional.of("abuse@test.com"),
ImmutableList.of("abuse@test.com", "bcc@test.com"),
"Super Cool Registry Daily Threat Detector [2018-07-15]",
String.format(DAILY_EMAIL_FORMAT, "<tr><td>a.com</td><td>MALWARE</td></tr>"),
Optional.of(MediaType.HTML_UTF_8));
@ -188,7 +190,7 @@ public class Spec11EmailUtilsTest {
capturedMessages.get(1),
"abuse@test.com",
"new.registrar@example.com",
Optional.of("abuse@test.com"),
ImmutableList.of("abuse@test.com", "bcc@test.com"),
"Super Cool Registry Daily Threat Detector [2018-07-15]",
String.format(
DAILY_EMAIL_FORMAT,
@ -198,7 +200,7 @@ public class Spec11EmailUtilsTest {
capturedMessages.get(2),
"abuse@test.com",
"my-receiver@test.com",
Optional.empty(),
ImmutableList.of(),
"Spec11 Pipeline Success 2018-07-15",
"Spec11 reporting completed successfully.",
Optional.empty());
@ -225,7 +227,7 @@ public class Spec11EmailUtilsTest {
capturedContents.get(0),
"abuse@test.com",
"new.registrar@example.com",
Optional.of("abuse@test.com"),
ImmutableList.of("abuse@test.com", "bcc@test.com"),
"Super Cool Registry Monthly Threat Detector [2018-07-15]",
String.format(MONTHLY_EMAIL_FORMAT, "<tr><td>c.com</td><td>MALWARE</td></tr>"),
Optional.of(MediaType.HTML_UTF_8));
@ -233,7 +235,7 @@ public class Spec11EmailUtilsTest {
capturedContents.get(1),
"abuse@test.com",
"my-receiver@test.com",
Optional.empty(),
ImmutableList.of(),
"Spec11 Pipeline Success 2018-07-15",
"Spec11 reporting completed successfully.",
Optional.empty());
@ -270,7 +272,7 @@ public class Spec11EmailUtilsTest {
capturedMessages.get(0),
"abuse@test.com",
"the.registrar@example.com",
Optional.of("abuse@test.com"),
ImmutableList.of("abuse@test.com", "bcc@test.com"),
"Super Cool Registry Monthly Threat Detector [2018-07-15]",
String.format(MONTHLY_EMAIL_FORMAT, "<tr><td>a.com</td><td>MALWARE</td></tr>"),
Optional.of(MediaType.HTML_UTF_8));
@ -278,7 +280,7 @@ public class Spec11EmailUtilsTest {
capturedMessages.get(1),
"abuse@test.com",
"new.registrar@example.com",
Optional.of("abuse@test.com"),
ImmutableList.of("abuse@test.com", "bcc@test.com"),
"Super Cool Registry Monthly Threat Detector [2018-07-15]",
String.format(
MONTHLY_EMAIL_FORMAT,
@ -288,7 +290,7 @@ public class Spec11EmailUtilsTest {
capturedMessages.get(2),
"abuse@test.com",
"my-receiver@test.com",
Optional.empty(),
ImmutableList.of(),
"Spec11 Emailing Failure 2018-07-15",
"Emailing Spec11 reports failed due to expected",
Optional.empty());
@ -302,7 +304,7 @@ public class Spec11EmailUtilsTest {
contentCaptor.getValue(),
"abuse@test.com",
"my-receiver@test.com",
Optional.empty(),
ImmutableList.of(),
"Spec11 Pipeline Alert: 2018-07",
"Alert!",
Optional.empty());
@ -351,7 +353,7 @@ public class Spec11EmailUtilsTest {
EmailMessage message,
String from,
String recipient,
Optional<String> replyTo,
ImmutableList<String> bccs,
String subject,
String body,
Optional<MediaType> contentType)
@ -363,8 +365,8 @@ public class Spec11EmailUtilsTest {
.setSubject(subject)
.setBody(body);
if (replyTo.isPresent()) {
expectedContentBuilder.setBcc(new InternetAddress(replyTo.get()));
for (String bcc : bccs) {
expectedContentBuilder.addBcc(new InternetAddress(bcc));
}
contentType.ifPresent(expectedContentBuilder::setContentType);
assertThat(message).isEqualTo(expectedContentBuilder.build());