Skip emailing registrars with a null or empty email address

Obviously this is a bad thing and would fail if it ever happened. If this does occur, we will send a warning email.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=240977242
This commit is contained in:
gbrodman 2019-03-29 07:47:51 -07:00 committed by jianglai
parent c8aa6005f2
commit c174c86437
2 changed files with 62 additions and 4 deletions

View file

@ -14,6 +14,7 @@
package google.registry.reporting.spec11;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.reporting.spec11.Spec11RegistrarThreatMatchesParserTest.sampleThreatMatches;
import static google.registry.testing.JUnitBackports.assertThrows;
@ -24,6 +25,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.net.MediaType;
import google.registry.reporting.spec11.soy.Spec11EmailSoyInfo;
import google.registry.util.EmailMessage;
@ -221,6 +223,36 @@ public class Spec11EmailUtilsTest {
Optional.empty());
}
@Test
public void testWarning_emptyEmailAddressForRegistrars() throws Exception {
ImmutableSet<RegistrarThreatMatches> matchesWithoutEmails =
sampleThreatMatches().stream()
.map(matches -> RegistrarThreatMatches.create("", matches.threatMatches()))
.collect(toImmutableSet());
emailUtils.emailSpec11Reports(
date,
Spec11EmailSoyInfo.DAILY_SPEC_11_EMAIL,
"Super Cool Registry Daily Threat Detector [2018-07-15]",
matchesWithoutEmails);
verify(emailService).sendEmail(contentCaptor.capture());
validateMessage(
contentCaptor.getValue(),
"my-sender@test.com",
"my-receiver@test.com",
Optional.empty(),
"Spec11 Pipeline Warning 2018-07-15",
"No errors occurred but the following matches had no associated email: \n"
+ "[RegistrarThreatMatches{registrarEmailAddress=, threatMatches=[ThreatMatch"
+ "{threatType=MALWARE, platformType=ANY_PLATFORM, metadata=NONE,"
+ " fullyQualifiedDomainName=a.com}]}, RegistrarThreatMatches{registrarEmailAddress=,"
+ " threatMatches=[ThreatMatch{threatType=MALWARE, platformType=ANY_PLATFORM,"
+ " metadata=NONE, fullyQualifiedDomainName=b.com}, ThreatMatch{threatType=MALWARE,"
+ " platformType=ANY_PLATFORM, metadata=NONE, fullyQualifiedDomainName=c.com}]}]\n\n"
+ "This should not occur; please make sure we have email addresses for these"
+ " registrar(s).",
Optional.empty());
}
private void validateMessage(
EmailMessage message,
String from,