mirror of
https://github.com/google/nomulus
synced 2026-09-01 13:46:55 +00:00
Add email notification when DNS update fails (#1734)
This commit is contained in:
@@ -38,6 +38,7 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import google.registry.dns.DnsMetrics.ActionStatus;
|
||||
@@ -54,13 +55,18 @@ import google.registry.testing.CloudTasksHelper.TaskMatcher;
|
||||
import google.registry.testing.FakeClock;
|
||||
import google.registry.testing.FakeLockHandler;
|
||||
import google.registry.testing.FakeResponse;
|
||||
import google.registry.ui.server.SendEmailUtils;
|
||||
import google.registry.util.EmailMessage;
|
||||
import google.registry.util.SendEmailService;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Duration;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
/** Unit tests for {@link PublishDnsUpdatesAction}. */
|
||||
public class PublishDnsUpdatesActionTest {
|
||||
@@ -77,9 +83,18 @@ public class PublishDnsUpdatesActionTest {
|
||||
private final DnsQueue dnsQueue = mock(DnsQueue.class);
|
||||
private final CloudTasksHelper cloudTasksHelper = new CloudTasksHelper();
|
||||
private PublishDnsUpdatesAction action;
|
||||
private final SendEmailService emailService = mock(SendEmailService.class);
|
||||
private SendEmailUtils sendEmailUtils;
|
||||
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
void beforeEach() throws Exception {
|
||||
sendEmailUtils =
|
||||
new SendEmailUtils(
|
||||
new InternetAddress("outgoing@registry.example"),
|
||||
"UnitTest Registry",
|
||||
ImmutableList.of("notification@test.example", "notification2@test.example"),
|
||||
emailService);
|
||||
|
||||
createTld("xn--q9jyb4c");
|
||||
persistResource(
|
||||
Registry.get("xn--q9jyb4c")
|
||||
@@ -138,6 +153,10 @@ public class PublishDnsUpdatesActionTest {
|
||||
hosts,
|
||||
tld,
|
||||
Duration.standardSeconds(10),
|
||||
"Subj",
|
||||
"Body %1$s %2$s %3$s %4$s %5$s",
|
||||
"registry@test.com",
|
||||
"awesomeRegistry",
|
||||
Optional.ofNullable(retryCount),
|
||||
Optional.empty(),
|
||||
dnsQueue,
|
||||
@@ -146,6 +165,7 @@ public class PublishDnsUpdatesActionTest {
|
||||
lockHandler,
|
||||
clock,
|
||||
cloudTasksHelper.getTestCloudTasksUtils(),
|
||||
sendEmailUtils,
|
||||
response);
|
||||
}
|
||||
|
||||
@@ -381,6 +401,37 @@ public class PublishDnsUpdatesActionTest {
|
||||
assertThat(response.getStatus()).isEqualTo(SC_ACCEPTED);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDomainDnsUpdateRetriesExhausted_emailIsSent() {
|
||||
action =
|
||||
createAction("xn--q9jyb4c", ImmutableSet.of("example.xn--q9jyb4c"), ImmutableSet.of(), 10);
|
||||
doThrow(new RuntimeException()).when(dnsWriter).commit();
|
||||
action.run();
|
||||
ArgumentCaptor<EmailMessage> contentCaptor = ArgumentCaptor.forClass(EmailMessage.class);
|
||||
verify(emailService).sendEmail(contentCaptor.capture());
|
||||
EmailMessage emailMessage = contentCaptor.getValue();
|
||||
assertThat(emailMessage.subject()).isEqualTo("Subj");
|
||||
assertThat(emailMessage.body())
|
||||
.isEqualTo(
|
||||
"Body The Registrar example.xn--q9jyb4c domain awesomeRegistry registry@test.com");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testHostDnsUpdateRetriesExhausted_emailIsSent() {
|
||||
action =
|
||||
createAction(
|
||||
"xn--q9jyb4c", ImmutableSet.of(), ImmutableSet.of("ns1.example.xn--q9jyb4c"), 10);
|
||||
doThrow(new RuntimeException()).when(dnsWriter).commit();
|
||||
action.run();
|
||||
ArgumentCaptor<EmailMessage> contentCaptor = ArgumentCaptor.forClass(EmailMessage.class);
|
||||
verify(emailService).sendEmail(contentCaptor.capture());
|
||||
EmailMessage emailMessage = contentCaptor.getValue();
|
||||
assertThat(emailMessage.subject()).isEqualTo("Subj");
|
||||
assertThat(emailMessage.body())
|
||||
.isEqualTo(
|
||||
"Body The Registrar ns1.example.xn--q9jyb4c host awesomeRegistry registry@test.com");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTaskMissingRetryHeaders_throwsException() {
|
||||
IllegalStateException thrown =
|
||||
|
||||
Reference in New Issue
Block a user