diff --git a/core/src/main/java/google/registry/reporting/spec11/Spec11EmailUtils.java b/core/src/main/java/google/registry/reporting/spec11/Spec11EmailUtils.java index 47ce0cfec..d4aa88c34 100644 --- a/core/src/main/java/google/registry/reporting/spec11/Spec11EmailUtils.java +++ b/core/src/main/java/google/registry/reporting/spec11/Spec11EmailUtils.java @@ -136,13 +136,14 @@ public class Spec11EmailUtils { return registrarThreatMatches.threatMatches().stream() .filter( threatMatch -> - tm().createQueryComposer(DomainBase.class) + tm() + .createQueryComposer(DomainBase.class) .where( "fullyQualifiedDomainName", Comparator.EQ, threatMatch.fullyQualifiedDomainName()) - .getSingleResult() - .shouldPublishToDns()) + .stream() + .anyMatch(DomainBase::shouldPublishToDns)) .collect(toImmutableList()); }); return RegistrarThreatMatches.create(registrarThreatMatches.clientId(), filteredMatches); diff --git a/core/src/test/java/google/registry/reporting/spec11/Spec11EmailUtilsTest.java b/core/src/test/java/google/registry/reporting/spec11/Spec11EmailUtilsTest.java index 28014304a..843ff86cd 100644 --- a/core/src/test/java/google/registry/reporting/spec11/Spec11EmailUtilsTest.java +++ b/core/src/test/java/google/registry/reporting/spec11/Spec11EmailUtilsTest.java @@ -237,6 +237,49 @@ class Spec11EmailUtilsTest { Optional.empty()); } + @TestOfyAndSql + void testSuccess_dealsWithDeletedDomains() throws Exception { + // Create an inactive domain and an active domain with the same name. + persistResource(loadByEntity(aDomain).asBuilder().addStatusValue(SERVER_HOLD).build()); + HostResource host = persistActiveHost("ns1.example.com"); + aDomain = persistDomainWithHost("a.com", host); + + emailUtils.emailSpec11Reports( + date, + Spec11EmailSoyInfo.MONTHLY_SPEC_11_EMAIL, + "Super Cool Registry Monthly Threat Detector [2018-07-15]", + sampleThreatMatches()); + // We inspect individual parameters because Message doesn't implement equals(). + verify(emailService, times(3)).sendEmail(contentCaptor.capture()); + List capturedContents = contentCaptor.getAllValues(); + validateMessage( + capturedContents.get(0), + "abuse@test.com", + "the.registrar@example.com", + ImmutableList.of("abuse@test.com", "bcc@test.com"), + "Super Cool Registry Monthly Threat Detector [2018-07-15]", + String.format(MONTHLY_EMAIL_FORMAT, "a.comMALWARE"), + Optional.of(MediaType.HTML_UTF_8)); + validateMessage( + capturedContents.get(1), + "abuse@test.com", + "new.registrar@example.com", + ImmutableList.of("abuse@test.com", "bcc@test.com"), + "Super Cool Registry Monthly Threat Detector [2018-07-15]", + String.format( + MONTHLY_EMAIL_FORMAT, + "b.comMALWAREc.comMALWARE"), + Optional.of(MediaType.HTML_UTF_8)); + validateMessage( + capturedContents.get(2), + "abuse@test.com", + "my-receiver@test.com", + ImmutableList.of(), + "Spec11 Pipeline Success 2018-07-15", + "Spec11 reporting completed successfully.", + Optional.empty()); + } + @TestOfyAndSql void testOneFailure_sendsAlert() throws Exception { // If there is one failure, we should still send the other message and then an alert email