diff --git a/java/google/registry/reporting/spec11/BUILD b/java/google/registry/reporting/spec11/BUILD index 96d18495e..bcc899193 100644 --- a/java/google/registry/reporting/spec11/BUILD +++ b/java/google/registry/reporting/spec11/BUILD @@ -12,6 +12,7 @@ java_library( "//java/google/registry/config", "//java/google/registry/gcs", "//java/google/registry/keyring/api", + "//java/google/registry/model", "//java/google/registry/reporting", "//java/google/registry/reporting/spec11/soy:soy_java_wrappers", "//java/google/registry/request", diff --git a/java/google/registry/reporting/spec11/PublishSpec11ReportAction.java b/java/google/registry/reporting/spec11/PublishSpec11ReportAction.java index a6e2e380e..89ee7ebf1 100644 --- a/java/google/registry/reporting/spec11/PublishSpec11ReportAction.java +++ b/java/google/registry/reporting/spec11/PublishSpec11ReportAction.java @@ -52,8 +52,8 @@ import org.json.JSONException; * Retries until a {@code Dataflow} job with a given {@code jobId} completes, continuing the Spec11 * pipeline accordingly. * - *
This calls {@link Spec11EmailUtils#emailSpec11Reports(SoyTemplateInfo, String, Set)} on - * success or {@link Spec11EmailUtils#sendAlertEmail(String, String)} on failure. + *
This calls {@link Spec11EmailUtils#emailSpec11Reports(LocalDate, SoyTemplateInfo, String,
+ * Set)} on success or {@link Spec11EmailUtils#sendAlertEmail(String, String)} on failure.
*/
@Action(
service = Action.Service.BACKEND,
@@ -193,7 +193,7 @@ public class PublishSpec11ReportAction implements Runnable {
// Group by email address then flat-map all of the ThreatMatch objects together
return ImmutableMap.copyOf(
Maps.transformValues(
- Multimaps.index(registrarThreatMatches, RegistrarThreatMatches::registrarEmailAddress)
+ Multimaps.index(registrarThreatMatches, RegistrarThreatMatches::clientId)
.asMap(),
registrarThreatMatchesCollection ->
registrarThreatMatchesCollection.stream()
diff --git a/java/google/registry/reporting/spec11/RegistrarThreatMatches.java b/java/google/registry/reporting/spec11/RegistrarThreatMatches.java
index 04e32615e..64259cfcc 100644
--- a/java/google/registry/reporting/spec11/RegistrarThreatMatches.java
+++ b/java/google/registry/reporting/spec11/RegistrarThreatMatches.java
@@ -23,13 +23,11 @@ import java.util.List;
@AutoValue
public abstract class RegistrarThreatMatches {
- public abstract String registrarEmailAddress();
+ public abstract String clientId();
public abstract ImmutableList If you have any questions regarding this notice, please contact "
+ "my-reply-to@test.com. "),
@@ -149,7 +155,7 @@ public class Spec11EmailUtilsTest {
validateMessage(
capturedContents.get(1),
"my-sender@test.com",
- "b@fake.com",
+ "new.registrar@example.com",
Optional.of("my-reply-to@test.com"),
"Super Cool Registry Monthly Threat Detector [2018-07-15]",
String.format(
@@ -179,7 +185,7 @@ public class Spec11EmailUtilsTest {
validateMessage(
capturedMessages.get(0),
"my-sender@test.com",
- "a@fake.com",
+ "the.registrar@example.com",
Optional.of("my-reply-to@test.com"),
"Super Cool Registry Daily Threat Detector [2018-07-15]",
String.format(DAILY_EMAIL_FORMAT, "a.com MALWARE "),
@@ -187,7 +193,7 @@ public class Spec11EmailUtilsTest {
validateMessage(
capturedMessages.get(1),
"my-sender@test.com",
- "b@fake.com",
+ "new.registrar@example.com",
Optional.of("my-reply-to@test.com"),
"Super Cool Registry Daily Threat Detector [2018-07-15]",
String.format(
@@ -234,7 +240,7 @@ public class Spec11EmailUtilsTest {
validateMessage(
capturedMessages.get(0),
"my-sender@test.com",
- "a@fake.com",
+ "the.registrar@example.com",
Optional.of("my-reply-to@test.com"),
"Super Cool Registry Monthly Threat Detector [2018-07-15]",
String.format(MONTHLY_EMAIL_FORMAT, "a.com MALWARE "),
@@ -242,7 +248,7 @@ public class Spec11EmailUtilsTest {
validateMessage(
capturedMessages.get(1),
"my-sender@test.com",
- "b@fake.com",
+ "new.registrar@example.com",
Optional.of("my-reply-to@test.com"),
"Super Cool Registry Monthly Threat Detector [2018-07-15]",
String.format(
@@ -260,7 +266,7 @@ public class Spec11EmailUtilsTest {
}
@Test
- public void testSuccess_sendAlertEmail() throws MessagingException {
+ public void testSuccess_sendAlertEmail() throws Exception {
emailUtils.sendAlertEmail("Spec11 Pipeline Alert: 2018-07", "Alert!");
verify(emailService).sendEmail(contentCaptor.capture());
validateMessage(
@@ -273,6 +279,45 @@ public class Spec11EmailUtilsTest {
Optional.empty());
}
+ @Test
+ public void testSuccess_useWhoisAbuseEmailIfAvailable() throws Exception {
+ // if John Doe is the whois abuse contact, email them instead of the regular email
+ persistResource(
+ AppEngineRule.makeRegistrarContact2()
+ .asBuilder()
+ .setEmailAddress("johndoe@theregistrar.com")
+ .setVisibleInDomainWhoisAsAbuse(true)
+ .build());
+ emailUtils.emailSpec11Reports(
+ date,
+ Spec11EmailSoyInfo.MONTHLY_SPEC_11_EMAIL,
+ "Super Cool Registry Monthly Threat Detector [2018-07-15]",
+ sampleThreatMatches());
+ verify(emailService, times(3)).sendEmail(contentCaptor.capture());
+ assertThat(contentCaptor.getAllValues().get(0).recipients())
+ .containsExactly(new InternetAddress("johndoe@theregistrar.com"));
+ }
+
+ @Test
+ public void testFailure_badClientId() {
+ RuntimeException thrown =
+ assertThrows(
+ RuntimeException.class,
+ () ->
+ emailUtils.emailSpec11Reports(
+ date,
+ Spec11EmailSoyInfo.MONTHLY_SPEC_11_EMAIL,
+ "Super Cool Registry Monthly Threat Detector [2018-07-15]",
+ ImmutableSet.of(
+ RegistrarThreatMatches.create(
+ "badClientId", getMatchA().threatMatches()))));
+ assertThat(thrown)
+ .hasCauseThat()
+ .hasMessageThat()
+ .isEqualTo("Could not find registrar badClientId");
+ assertThat(thrown).hasCauseThat().isInstanceOf(IllegalArgumentException.class);
+ }
+
private void validateMessage(
EmailMessage message,
String from,
diff --git a/javatests/google/registry/reporting/spec11/Spec11RegistrarThreatMatchesParserTest.java b/javatests/google/registry/reporting/spec11/Spec11RegistrarThreatMatchesParserTest.java
index dc8712102..4849f4d69 100644
--- a/javatests/google/registry/reporting/spec11/Spec11RegistrarThreatMatchesParserTest.java
+++ b/javatests/google/registry/reporting/spec11/Spec11RegistrarThreatMatchesParserTest.java
@@ -84,7 +84,7 @@ public class Spec11RegistrarThreatMatchesParserTest {
static RegistrarThreatMatches getMatchA() throws Exception {
return RegistrarThreatMatches.create(
- "a@fake.com",
+ "TheRegistrar",
ImmutableList.of(
ThreatMatch.fromJSON(
new JSONObject(
@@ -97,7 +97,7 @@ public class Spec11RegistrarThreatMatchesParserTest {
static RegistrarThreatMatches getMatchB() throws Exception {
return RegistrarThreatMatches.create(
- "b@fake.com",
+ "NewRegistrar",
ImmutableList.of(
ThreatMatch.fromJSON(
new JSONObject(
diff --git a/javatests/google/registry/reporting/spec11/testdata/spec11_fake_report b/javatests/google/registry/reporting/spec11/testdata/spec11_fake_report
index ce9ae9cfe..d08c14455 100644
--- a/javatests/google/registry/reporting/spec11/testdata/spec11_fake_report
+++ b/javatests/google/registry/reporting/spec11/testdata/spec11_fake_report
@@ -1,3 +1,3 @@
-Map from registrar email to detected subdomain threats:
-{"threatMatches":[{"threatEntryMetadata":"NONE","threatType":"MALWARE","fullyQualifiedDomainName":"a.com","platformType":"ANY_PLATFORM"}],"registrarEmailAddress":"a@fake.com"}
-{"threatMatches":[{"threatEntryMetadata":"NONE","threatType":"MALWARE","fullyQualifiedDomainName":"b.com","platformType":"ANY_PLATFORM"},{"threatEntryMetadata":"NONE","threatType":"MALWARE","fullyQualifiedDomainName":"c.com","platformType":"ANY_PLATFORM"}],"registrarEmailAddress":"b@fake.com"}
+Map from registrar email / name to detected subdomain threats:
+{"threatMatches":[{"threatEntryMetadata":"NONE","threatType":"MALWARE","fullyQualifiedDomainName":"a.com","platformType":"ANY_PLATFORM"}],"registrarClientId":"TheRegistrar","registrarEmailAddress":"the.registrar@example.com"}
+{"threatMatches":[{"threatEntryMetadata":"NONE","threatType":"MALWARE","fullyQualifiedDomainName":"b.com","platformType":"ANY_PLATFORM"},{"threatEntryMetadata":"NONE","threatType":"MALWARE","fullyQualifiedDomainName":"c.com","platformType":"ANY_PLATFORM"}],"registrarClientId":"NewRegistrar","registrarEmailAddress":"new.registrar@example.com"}
a.com MALWARE