mirror of
https://github.com/google/nomulus.git
synced 2025-07-23 19:20:44 +02:00
Use Gmail for RegistryLock emails (#2122)
This commit is contained in:
parent
a91ed0f1ad
commit
bcb2b2c784
5 changed files with 27 additions and 25 deletions
|
@ -26,6 +26,7 @@ import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.flogger.FluentLogger;
|
import com.google.common.flogger.FluentLogger;
|
||||||
import com.google.common.net.MediaType;
|
import com.google.common.net.MediaType;
|
||||||
import google.registry.config.RegistryConfig.Config;
|
import google.registry.config.RegistryConfig.Config;
|
||||||
|
import google.registry.groups.GmailClient;
|
||||||
import google.registry.model.domain.Domain;
|
import google.registry.model.domain.Domain;
|
||||||
import google.registry.model.domain.RegistryLock;
|
import google.registry.model.domain.RegistryLock;
|
||||||
import google.registry.model.eppcommon.StatusValue;
|
import google.registry.model.eppcommon.StatusValue;
|
||||||
|
@ -40,7 +41,6 @@ import google.registry.request.auth.Auth;
|
||||||
import google.registry.tools.DomainLockUtils;
|
import google.registry.tools.DomainLockUtils;
|
||||||
import google.registry.util.DateTimeUtils;
|
import google.registry.util.DateTimeUtils;
|
||||||
import google.registry.util.EmailMessage;
|
import google.registry.util.EmailMessage;
|
||||||
import google.registry.util.SendEmailService;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.mail.internet.AddressException;
|
import javax.mail.internet.AddressException;
|
||||||
|
@ -84,7 +84,7 @@ public class RelockDomainAction implements Runnable {
|
||||||
private final InternetAddress alertRecipientAddress;
|
private final InternetAddress alertRecipientAddress;
|
||||||
private final InternetAddress gSuiteOutgoingEmailAddress;
|
private final InternetAddress gSuiteOutgoingEmailAddress;
|
||||||
private final String supportEmail;
|
private final String supportEmail;
|
||||||
private final SendEmailService sendEmailService;
|
private final GmailClient gmailClient;
|
||||||
private final DomainLockUtils domainLockUtils;
|
private final DomainLockUtils domainLockUtils;
|
||||||
private final Response response;
|
private final Response response;
|
||||||
|
|
||||||
|
@ -92,10 +92,10 @@ public class RelockDomainAction implements Runnable {
|
||||||
public RelockDomainAction(
|
public RelockDomainAction(
|
||||||
@Parameter(OLD_UNLOCK_REVISION_ID_PARAM) long oldUnlockRevisionId,
|
@Parameter(OLD_UNLOCK_REVISION_ID_PARAM) long oldUnlockRevisionId,
|
||||||
@Parameter(PREVIOUS_ATTEMPTS_PARAM) int previousAttempts,
|
@Parameter(PREVIOUS_ATTEMPTS_PARAM) int previousAttempts,
|
||||||
@Config("alertRecipientEmailAddress") InternetAddress alertRecipientAddress,
|
@Config("newAlertRecipientEmailAddress") InternetAddress alertRecipientAddress,
|
||||||
@Config("gSuiteOutgoingEmailAddress") InternetAddress gSuiteOutgoingEmailAddress,
|
@Config("gSuiteOutgoingEmailAddress") InternetAddress gSuiteOutgoingEmailAddress,
|
||||||
@Config("supportEmail") String supportEmail,
|
@Config("supportEmail") String supportEmail,
|
||||||
SendEmailService sendEmailService,
|
GmailClient gmailClient,
|
||||||
DomainLockUtils domainLockUtils,
|
DomainLockUtils domainLockUtils,
|
||||||
Response response) {
|
Response response) {
|
||||||
this.oldUnlockRevisionId = oldUnlockRevisionId;
|
this.oldUnlockRevisionId = oldUnlockRevisionId;
|
||||||
|
@ -103,7 +103,7 @@ public class RelockDomainAction implements Runnable {
|
||||||
this.alertRecipientAddress = alertRecipientAddress;
|
this.alertRecipientAddress = alertRecipientAddress;
|
||||||
this.gSuiteOutgoingEmailAddress = gSuiteOutgoingEmailAddress;
|
this.gSuiteOutgoingEmailAddress = gSuiteOutgoingEmailAddress;
|
||||||
this.supportEmail = supportEmail;
|
this.supportEmail = supportEmail;
|
||||||
this.sendEmailService = sendEmailService;
|
this.gmailClient = gmailClient;
|
||||||
this.domainLockUtils = domainLockUtils;
|
this.domainLockUtils = domainLockUtils;
|
||||||
this.response = response;
|
this.response = response;
|
||||||
}
|
}
|
||||||
|
@ -215,7 +215,7 @@ public class RelockDomainAction implements Runnable {
|
||||||
oldLock.getDomainName(),
|
oldLock.getDomainName(),
|
||||||
t.getMessage(),
|
t.getMessage(),
|
||||||
supportEmail);
|
supportEmail);
|
||||||
sendEmailService.sendEmail(
|
gmailClient.sendEmail(
|
||||||
EmailMessage.newBuilder()
|
EmailMessage.newBuilder()
|
||||||
.setFrom(gSuiteOutgoingEmailAddress)
|
.setFrom(gSuiteOutgoingEmailAddress)
|
||||||
.setBody(body)
|
.setBody(body)
|
||||||
|
@ -245,7 +245,7 @@ public class RelockDomainAction implements Runnable {
|
||||||
String body =
|
String body =
|
||||||
String.format(RELOCK_SUCCESS_EMAIL_TEMPLATE, oldLock.getDomainName(), supportEmail);
|
String.format(RELOCK_SUCCESS_EMAIL_TEMPLATE, oldLock.getDomainName(), supportEmail);
|
||||||
|
|
||||||
sendEmailService.sendEmail(
|
gmailClient.sendEmail(
|
||||||
EmailMessage.newBuilder()
|
EmailMessage.newBuilder()
|
||||||
.setFrom(gSuiteOutgoingEmailAddress)
|
.setFrom(gSuiteOutgoingEmailAddress)
|
||||||
.setBody(body)
|
.setBody(body)
|
||||||
|
@ -264,7 +264,7 @@ public class RelockDomainAction implements Runnable {
|
||||||
.addAll(getEmailRecipients(oldLock.getRegistrarId()))
|
.addAll(getEmailRecipients(oldLock.getRegistrarId()))
|
||||||
.add(alertRecipientAddress)
|
.add(alertRecipientAddress)
|
||||||
.build();
|
.build();
|
||||||
sendEmailService.sendEmail(
|
gmailClient.sendEmail(
|
||||||
EmailMessage.newBuilder()
|
EmailMessage.newBuilder()
|
||||||
.setFrom(gSuiteOutgoingEmailAddress)
|
.setFrom(gSuiteOutgoingEmailAddress)
|
||||||
.setBody(body)
|
.setBody(body)
|
||||||
|
@ -274,7 +274,7 @@ public class RelockDomainAction implements Runnable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendUnknownRevisionIdAlertEmail() {
|
private void sendUnknownRevisionIdAlertEmail() {
|
||||||
sendEmailService.sendEmail(
|
gmailClient.sendEmail(
|
||||||
EmailMessage.newBuilder()
|
EmailMessage.newBuilder()
|
||||||
.setFrom(gSuiteOutgoingEmailAddress)
|
.setFrom(gSuiteOutgoingEmailAddress)
|
||||||
.setBody(String.format(RELOCK_UNKNOWN_ID_FAILURE_EMAIL_TEMPLATE, oldUnlockRevisionId))
|
.setBody(String.format(RELOCK_UNKNOWN_ID_FAILURE_EMAIL_TEMPLATE, oldUnlockRevisionId))
|
||||||
|
|
|
@ -23,6 +23,7 @@ import google.registry.config.RegistryConfig.ConfigModule;
|
||||||
import google.registry.flows.ServerTridProviderModule;
|
import google.registry.flows.ServerTridProviderModule;
|
||||||
import google.registry.flows.custom.CustomLogicFactoryModule;
|
import google.registry.flows.custom.CustomLogicFactoryModule;
|
||||||
import google.registry.groups.DirectoryModule;
|
import google.registry.groups.DirectoryModule;
|
||||||
|
import google.registry.groups.GmailModule;
|
||||||
import google.registry.groups.GroupsModule;
|
import google.registry.groups.GroupsModule;
|
||||||
import google.registry.groups.GroupssettingsModule;
|
import google.registry.groups.GroupssettingsModule;
|
||||||
import google.registry.keyring.KeyringModule;
|
import google.registry.keyring.KeyringModule;
|
||||||
|
@ -54,6 +55,7 @@ import javax.inject.Singleton;
|
||||||
DirectoryModule.class,
|
DirectoryModule.class,
|
||||||
DummyKeyringModule.class,
|
DummyKeyringModule.class,
|
||||||
FrontendRequestComponentModule.class,
|
FrontendRequestComponentModule.class,
|
||||||
|
GmailModule.class,
|
||||||
GroupsModule.class,
|
GroupsModule.class,
|
||||||
GroupssettingsModule.class,
|
GroupssettingsModule.class,
|
||||||
GsonModule.class,
|
GsonModule.class,
|
||||||
|
|
|
@ -31,6 +31,7 @@ import com.google.common.flogger.FluentLogger;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import google.registry.config.RegistryConfig.Config;
|
import google.registry.config.RegistryConfig.Config;
|
||||||
import google.registry.flows.domain.DomainFlowUtils;
|
import google.registry.flows.domain.DomainFlowUtils;
|
||||||
|
import google.registry.groups.GmailClient;
|
||||||
import google.registry.model.domain.RegistryLock;
|
import google.registry.model.domain.RegistryLock;
|
||||||
import google.registry.model.registrar.Registrar;
|
import google.registry.model.registrar.Registrar;
|
||||||
import google.registry.model.registrar.RegistrarPoc;
|
import google.registry.model.registrar.RegistrarPoc;
|
||||||
|
@ -46,7 +47,6 @@ import google.registry.request.auth.UserAuthInfo;
|
||||||
import google.registry.security.JsonResponseHelper;
|
import google.registry.security.JsonResponseHelper;
|
||||||
import google.registry.tools.DomainLockUtils;
|
import google.registry.tools.DomainLockUtils;
|
||||||
import google.registry.util.EmailMessage;
|
import google.registry.util.EmailMessage;
|
||||||
import google.registry.util.SendEmailService;
|
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
@ -83,7 +83,7 @@ public class RegistryLockPostAction implements Runnable, JsonActionRunner.JsonAc
|
||||||
private final JsonActionRunner jsonActionRunner;
|
private final JsonActionRunner jsonActionRunner;
|
||||||
private final AuthResult authResult;
|
private final AuthResult authResult;
|
||||||
private final AuthenticatedRegistrarAccessor registrarAccessor;
|
private final AuthenticatedRegistrarAccessor registrarAccessor;
|
||||||
private final SendEmailService sendEmailService;
|
private final GmailClient gmailClient;
|
||||||
private final DomainLockUtils domainLockUtils;
|
private final DomainLockUtils domainLockUtils;
|
||||||
private final InternetAddress gSuiteOutgoingEmailAddress;
|
private final InternetAddress gSuiteOutgoingEmailAddress;
|
||||||
|
|
||||||
|
@ -93,14 +93,14 @@ public class RegistryLockPostAction implements Runnable, JsonActionRunner.JsonAc
|
||||||
JsonActionRunner jsonActionRunner,
|
JsonActionRunner jsonActionRunner,
|
||||||
AuthResult authResult,
|
AuthResult authResult,
|
||||||
AuthenticatedRegistrarAccessor registrarAccessor,
|
AuthenticatedRegistrarAccessor registrarAccessor,
|
||||||
SendEmailService sendEmailService,
|
GmailClient gmailClient,
|
||||||
DomainLockUtils domainLockUtils,
|
DomainLockUtils domainLockUtils,
|
||||||
@Config("gSuiteOutgoingEmailAddress") InternetAddress gSuiteOutgoingEmailAddress) {
|
@Config("gSuiteOutgoingEmailAddress") InternetAddress gSuiteOutgoingEmailAddress) {
|
||||||
this.req = req;
|
this.req = req;
|
||||||
this.jsonActionRunner = jsonActionRunner;
|
this.jsonActionRunner = jsonActionRunner;
|
||||||
this.authResult = authResult;
|
this.authResult = authResult;
|
||||||
this.registrarAccessor = registrarAccessor;
|
this.registrarAccessor = registrarAccessor;
|
||||||
this.sendEmailService = sendEmailService;
|
this.gmailClient = gmailClient;
|
||||||
this.domainLockUtils = domainLockUtils;
|
this.domainLockUtils = domainLockUtils;
|
||||||
this.gSuiteOutgoingEmailAddress = gSuiteOutgoingEmailAddress;
|
this.gSuiteOutgoingEmailAddress = gSuiteOutgoingEmailAddress;
|
||||||
}
|
}
|
||||||
|
@ -168,7 +168,7 @@ public class RegistryLockPostAction implements Runnable, JsonActionRunner.JsonAc
|
||||||
ImmutableList<InternetAddress> recipients =
|
ImmutableList<InternetAddress> recipients =
|
||||||
ImmutableList.of(new InternetAddress(userEmail, true));
|
ImmutableList.of(new InternetAddress(userEmail, true));
|
||||||
String action = isLock ? "lock" : "unlock";
|
String action = isLock ? "lock" : "unlock";
|
||||||
sendEmailService.sendEmail(
|
gmailClient.sendEmail(
|
||||||
EmailMessage.newBuilder()
|
EmailMessage.newBuilder()
|
||||||
.setBody(body)
|
.setBody(body)
|
||||||
.setSubject(String.format("Registry %s verification", action))
|
.setSubject(String.format("Registry %s verification", action))
|
||||||
|
|
|
@ -35,6 +35,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
|
|
||||||
import com.google.cloud.tasks.v2.HttpMethod;
|
import com.google.cloud.tasks.v2.HttpMethod;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import google.registry.groups.GmailClient;
|
||||||
import google.registry.model.domain.Domain;
|
import google.registry.model.domain.Domain;
|
||||||
import google.registry.model.domain.RegistryLock;
|
import google.registry.model.domain.RegistryLock;
|
||||||
import google.registry.model.host.Host;
|
import google.registry.model.host.Host;
|
||||||
|
@ -48,7 +49,6 @@ import google.registry.testing.FakeClock;
|
||||||
import google.registry.testing.FakeResponse;
|
import google.registry.testing.FakeResponse;
|
||||||
import google.registry.tools.DomainLockUtils;
|
import google.registry.tools.DomainLockUtils;
|
||||||
import google.registry.util.EmailMessage;
|
import google.registry.util.EmailMessage;
|
||||||
import google.registry.util.SendEmailService;
|
|
||||||
import google.registry.util.StringGenerator.Alphabets;
|
import google.registry.util.StringGenerator.Alphabets;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import javax.mail.internet.InternetAddress;
|
import javax.mail.internet.InternetAddress;
|
||||||
|
@ -85,7 +85,7 @@ public class RelockDomainActionTest {
|
||||||
|
|
||||||
private Domain domain;
|
private Domain domain;
|
||||||
private RegistryLock oldLock;
|
private RegistryLock oldLock;
|
||||||
@Mock private SendEmailService sendEmailService;
|
@Mock private GmailClient gmailClient;
|
||||||
private RelockDomainAction action;
|
private RelockDomainAction action;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
|
@ -107,7 +107,7 @@ public class RelockDomainActionTest {
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
void afterEach() {
|
void afterEach() {
|
||||||
verifyNoMoreInteractions(sendEmailService);
|
verifyNoMoreInteractions(gmailClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -260,7 +260,7 @@ public class RelockDomainActionTest {
|
||||||
ImmutableSet.of(new InternetAddress("Marla.Singer.RegistryLock@crr.com")))
|
ImmutableSet.of(new InternetAddress("Marla.Singer.RegistryLock@crr.com")))
|
||||||
.setFrom(new InternetAddress("outgoing@example.com"))
|
.setFrom(new InternetAddress("outgoing@example.com"))
|
||||||
.build();
|
.build();
|
||||||
verify(sendEmailService).sendEmail(expectedEmail);
|
verify(gmailClient).sendEmail(expectedEmail);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertNonTransientFailureEmail(String exceptionMessage) throws Exception {
|
private void assertNonTransientFailureEmail(String exceptionMessage) throws Exception {
|
||||||
|
@ -294,7 +294,7 @@ public class RelockDomainActionTest {
|
||||||
.setRecipients(recipients)
|
.setRecipients(recipients)
|
||||||
.setFrom(new InternetAddress("outgoing@example.com"))
|
.setFrom(new InternetAddress("outgoing@example.com"))
|
||||||
.build();
|
.build();
|
||||||
verify(sendEmailService).sendEmail(expectedEmail);
|
verify(gmailClient).sendEmail(expectedEmail);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertTaskEnqueued(int numAttempts) {
|
private void assertTaskEnqueued(int numAttempts) {
|
||||||
|
@ -328,7 +328,7 @@ public class RelockDomainActionTest {
|
||||||
alertRecipientAddress,
|
alertRecipientAddress,
|
||||||
gSuiteOutgoingAddress,
|
gSuiteOutgoingAddress,
|
||||||
"support@example.com",
|
"support@example.com",
|
||||||
sendEmailService,
|
gmailClient,
|
||||||
domainLockUtils,
|
domainLockUtils,
|
||||||
response);
|
response);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ import com.google.appengine.api.users.User;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import google.registry.groups.GmailClient;
|
||||||
import google.registry.model.console.RegistrarRole;
|
import google.registry.model.console.RegistrarRole;
|
||||||
import google.registry.model.console.UserRoles;
|
import google.registry.model.console.UserRoles;
|
||||||
import google.registry.model.domain.Domain;
|
import google.registry.model.domain.Domain;
|
||||||
|
@ -54,7 +55,6 @@ import google.registry.testing.DeterministicStringGenerator;
|
||||||
import google.registry.testing.FakeClock;
|
import google.registry.testing.FakeClock;
|
||||||
import google.registry.tools.DomainLockUtils;
|
import google.registry.tools.DomainLockUtils;
|
||||||
import google.registry.util.EmailMessage;
|
import google.registry.util.EmailMessage;
|
||||||
import google.registry.util.SendEmailService;
|
|
||||||
import google.registry.util.StringGenerator.Alphabets;
|
import google.registry.util.StringGenerator.Alphabets;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
@ -97,7 +97,7 @@ final class RegistryLockPostActionTest {
|
||||||
private Domain domain;
|
private Domain domain;
|
||||||
private RegistryLockPostAction action;
|
private RegistryLockPostAction action;
|
||||||
|
|
||||||
@Mock SendEmailService emailService;
|
@Mock GmailClient gmailClient;
|
||||||
@Mock HttpServletRequest mockRequest;
|
@Mock HttpServletRequest mockRequest;
|
||||||
@Mock HttpServletResponse mockResponse;
|
@Mock HttpServletResponse mockResponse;
|
||||||
|
|
||||||
|
@ -510,12 +510,12 @@ final class RegistryLockPostActionTest {
|
||||||
private void assertFailureWithMessage(Map<String, ?> response, String message) {
|
private void assertFailureWithMessage(Map<String, ?> response, String message) {
|
||||||
assertThat(response)
|
assertThat(response)
|
||||||
.containsExactly("status", "ERROR", "results", ImmutableList.of(), "message", message);
|
.containsExactly("status", "ERROR", "results", ImmutableList.of(), "message", message);
|
||||||
verifyNoMoreInteractions(emailService);
|
verifyNoMoreInteractions(gmailClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void verifyEmail(String recipient) throws Exception {
|
private void verifyEmail(String recipient) throws Exception {
|
||||||
ArgumentCaptor<EmailMessage> emailCaptor = ArgumentCaptor.forClass(EmailMessage.class);
|
ArgumentCaptor<EmailMessage> emailCaptor = ArgumentCaptor.forClass(EmailMessage.class);
|
||||||
verify(emailService).sendEmail(emailCaptor.capture());
|
verify(gmailClient).sendEmail(emailCaptor.capture());
|
||||||
EmailMessage sentMessage = emailCaptor.getValue();
|
EmailMessage sentMessage = emailCaptor.getValue();
|
||||||
assertThat(sentMessage.subject()).matches("Registry (un)?lock verification");
|
assertThat(sentMessage.subject()).matches("Registry (un)?lock verification");
|
||||||
assertThat(sentMessage.body()).matches(EMAIL_MESSAGE_TEMPLATE);
|
assertThat(sentMessage.body()).matches(EMAIL_MESSAGE_TEMPLATE);
|
||||||
|
@ -545,7 +545,7 @@ final class RegistryLockPostActionTest {
|
||||||
jsonActionRunner,
|
jsonActionRunner,
|
||||||
authResult,
|
authResult,
|
||||||
registrarAccessor,
|
registrarAccessor,
|
||||||
emailService,
|
gmailClient,
|
||||||
domainLockUtils,
|
domainLockUtils,
|
||||||
outgoingAddress);
|
outgoingAddress);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue