mirror of
https://github.com/google/nomulus.git
synced 2025-07-07 11:43:24 +02:00
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()
This commit is contained in:
parent
9f69a0bf2e
commit
9c89643367
2 changed files with 47 additions and 3 deletions
|
@ -136,13 +136,14 @@ public class Spec11EmailUtils {
|
||||||
return registrarThreatMatches.threatMatches().stream()
|
return registrarThreatMatches.threatMatches().stream()
|
||||||
.filter(
|
.filter(
|
||||||
threatMatch ->
|
threatMatch ->
|
||||||
tm().createQueryComposer(DomainBase.class)
|
tm()
|
||||||
|
.createQueryComposer(DomainBase.class)
|
||||||
.where(
|
.where(
|
||||||
"fullyQualifiedDomainName",
|
"fullyQualifiedDomainName",
|
||||||
Comparator.EQ,
|
Comparator.EQ,
|
||||||
threatMatch.fullyQualifiedDomainName())
|
threatMatch.fullyQualifiedDomainName())
|
||||||
.getSingleResult()
|
.stream()
|
||||||
.shouldPublishToDns())
|
.anyMatch(DomainBase::shouldPublishToDns))
|
||||||
.collect(toImmutableList());
|
.collect(toImmutableList());
|
||||||
});
|
});
|
||||||
return RegistrarThreatMatches.create(registrarThreatMatches.clientId(), filteredMatches);
|
return RegistrarThreatMatches.create(registrarThreatMatches.clientId(), filteredMatches);
|
||||||
|
|
|
@ -237,6 +237,49 @@ class Spec11EmailUtilsTest {
|
||||||
Optional.empty());
|
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<EmailMessage> 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, "<tr><td>a.com</td><td>MALWARE</td></tr>"),
|
||||||
|
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,
|
||||||
|
"<tr><td>b.com</td><td>MALWARE</td></tr><tr><td>c.com</td><td>MALWARE</td></tr>"),
|
||||||
|
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
|
@TestOfyAndSql
|
||||||
void testOneFailure_sendsAlert() throws Exception {
|
void testOneFailure_sendsAlert() throws Exception {
|
||||||
// If there is one failure, we should still send the other message and then an alert email
|
// If there is one failure, we should still send the other message and then an alert email
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue