From 9c89643367af57d06e604d3085ce7f334f3925f4 Mon Sep 17 00:00:00 2001 From: Michael Muller Date: Fri, 23 Apr 2021 14:20:31 -0400 Subject: [PATCH] Fix Spec11 domain check (#1105) * Fix Spec11 domain check We should be checking to see if there are _any_ active domains for a given reported domain, not to see if _the_ domain for the name is active. The last change caused an exception for domains with soft-deleted past domains of the same name. The original code only checked the first domain returned from the query, which may have been soft-deleted. This version checks all domain records to see if any are active. * filter().count() -> anyMatch() --- .../reporting/spec11/Spec11EmailUtils.java | 7 +-- .../spec11/Spec11EmailUtilsTest.java | 43 +++++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) 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