Remove appengine-based email client (#2354)

Remove email classes that depend on AppEngine API. They have been
replaced by the gmail-based client.

Remove `EmailMessage.from` method, which is no longer used.
There is a fixed sender address for the entire domain, and is
set by the gmail client.

The configs remain to be cleaned up. There is a bug (b/279671974) that
tracks it.
This commit is contained in:
Weimin Yu
2024-03-07 03:26:12 +00:00
committed by GitHub
parent 1cac9c9684
commit df4e345961
28 changed files with 21 additions and 514 deletions
@@ -44,7 +44,6 @@ import google.registry.ui.server.SendEmailUtils;
import google.registry.util.EmailMessage;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.internet.InternetAddress;
import org.joda.money.CurrencyUnit;
import org.joda.money.Money;
import org.joda.time.DateTime;
@@ -89,8 +88,6 @@ public class CheckBulkComplianceActionTest {
loggerToIntercept.addHandler(logHandler);
sendEmailUtils =
new SendEmailUtils(
new InternetAddress("outgoing@registry.example"),
"UnitTest Registry",
ImmutableList.of("notification@test.example", "notification2@test.example"),
gmailClient);
createTld("tld");
@@ -258,7 +258,6 @@ public class RelockDomainActionTest {
+ "contact support at support@example.com if you have any questions.")
.setRecipients(
ImmutableSet.of(new InternetAddress("Marla.Singer.RegistryLock@crr.com")))
.setFrom(new InternetAddress("outgoing@example.com"))
.build();
verify(gmailClient).sendEmail(expectedEmail);
}
@@ -292,7 +291,6 @@ public class RelockDomainActionTest {
.setSubject("Error re-locking domain example.tld")
.setBody(body)
.setRecipients(recipients)
.setFrom(new InternetAddress("outgoing@example.com"))
.build();
verify(gmailClient).sendEmail(expectedEmail);
}
@@ -321,12 +319,10 @@ public class RelockDomainActionTest {
private RelockDomainAction createAction(Long oldUnlockRevisionId, int previousAttempts)
throws Exception {
InternetAddress alertRecipientAddress = new InternetAddress("alerts@example.com");
InternetAddress gSuiteOutgoingAddress = new InternetAddress("outgoing@example.com");
return new RelockDomainAction(
oldUnlockRevisionId,
previousAttempts,
alertRecipientAddress,
gSuiteOutgoingAddress,
"support@example.com",
gmailClient,
domainLockUtils,
@@ -98,7 +98,6 @@ class SendExpiringCertificateNotificationEmailActionTest {
new SendExpiringCertificateNotificationEmailAction(
EXPIRATION_WARNING_EMAIL_BODY_TEXT,
EXPIRATION_WARNING_EMAIL_SUBJECT_TEXT,
new InternetAddress("test@example.com"),
sendEmailService,
certificateChecker,
response);
@@ -87,7 +87,6 @@ public class PublishDnsUpdatesActionTest {
private final DnsMetrics dnsMetrics = mock(DnsMetrics.class);
private final CloudTasksHelper cloudTasksHelper = new CloudTasksHelper();
private PublishDnsUpdatesAction action;
private InternetAddress outgoingRegistry;
private Lazy<InternetAddress> registrySupportEmail;
private Lazy<InternetAddress> registryCcEmail;
private final GmailClient emailService = mock(GmailClient.class);
@@ -96,7 +95,6 @@ public class PublishDnsUpdatesActionTest {
void beforeEach() throws Exception {
createTld("xn--q9jyb4c");
createTld("com");
outgoingRegistry = new InternetAddress("outgoing@registry.example");
registrySupportEmail = Lazies.of(new InternetAddress("registry@test.com"));
registryCcEmail = Lazies.of(new InternetAddress("registry-cc@test.com"));
persistResource(
@@ -159,7 +157,6 @@ public class PublishDnsUpdatesActionTest {
"awesomeRegistry",
registrySupportEmail,
registryCcEmail,
outgoingRegistry,
retryCount,
new DnsWriterProxy(ImmutableMap.of("correctWriter", dnsWriter)),
dnsMetrics,
@@ -75,7 +75,6 @@ public class GmailClientTest {
EmailMessage.create(
"subject",
"body",
new InternetAddress("from@example.com"),
new InternetAddress("to@example.com"));
Send gSend = mock(Send.class);
Messages gMessages = mock(Messages.class);
@@ -93,7 +92,6 @@ public class GmailClientTest {
EmailMessage.create(
"subject",
"body",
new InternetAddress("from@example.com"),
new InternetAddress("to@example.com"));
getGmailClient(false).sendEmail(message);
verifyNoInteractions(gmail);
@@ -107,7 +105,6 @@ public class GmailClientTest {
InternetAddress bccAddr = new InternetAddress("bcc@example.com");
EmailMessage emailMessage =
EmailMessage.newBuilder()
.setFrom(fromAddr)
.setRecipients(ImmutableList.of(toAddr))
.setSubject("My subject")
.setBody("My body")
@@ -148,7 +145,6 @@ public class GmailClientTest {
InternetAddress replyToAddr = new InternetAddress("some-addr@another.com");
EmailMessage emailMessage =
EmailMessage.newBuilder()
.setFrom(fromAddr)
.setRecipients(ImmutableList.of(toAddr))
.setReplyToEmailAddress(replyToAddr)
.setSubject("My subject")
@@ -55,7 +55,6 @@ class BillingEmailUtilsTest {
return new BillingEmailUtils(
gmailClient,
new YearMonth(2017, 10),
new InternetAddress("my-sender@test.com"),
new InternetAddress("my-receiver@test.com"),
ImmutableList.of(
new InternetAddress("hello@world.com"), new InternetAddress("hola@mundo.com")),
@@ -75,7 +74,6 @@ class BillingEmailUtilsTest {
EmailMessage emailMessage = contentCaptor.getValue();
EmailMessage expectedContent =
EmailMessage.newBuilder()
.setFrom(new InternetAddress("my-sender@test.com"))
.setRecipients(
ImmutableList.of(
new InternetAddress("hello@world.com"), new InternetAddress("hola@mundo.com")))
@@ -126,7 +124,6 @@ class BillingEmailUtilsTest {
private void validateAlertMessage(EmailMessage emailMessage, String body)
throws MessagingException {
assertThat(emailMessage.from()).isEqualTo(new InternetAddress("my-sender@test.com"));
assertThat(emailMessage.recipients())
.containsExactly(new InternetAddress("my-receiver@test.com"));
assertThat(emailMessage.subject()).isEqualTo("Billing Pipeline Alert: 2017-10");
@@ -63,7 +63,6 @@ class IcannReportingStagingActionTest {
action.response = response;
action.stager = stager;
action.retrier = new Retrier(new FakeSleeper(new FakeClock()), 3);
action.sender = new InternetAddress("sender@example.com");
action.recipient = new InternetAddress("recipient@example.com");
action.gmailClient = mock(GmailClient.class);
action.cloudTasksUtils = cloudTasksHelper.getTestCloudTasksUtils();
@@ -94,8 +93,7 @@ class IcannReportingStagingActionTest {
EmailMessage.create(
"ICANN Monthly report staging summary [SUCCESS]",
"Completed staging the following 2 ICANN reports:\na\nb",
new InternetAddress("recipient@example.com"),
new InternetAddress("sender@example.com")));
new InternetAddress("recipient@example.com")));
assertUploadTaskEnqueued();
}
@@ -110,8 +108,7 @@ class IcannReportingStagingActionTest {
EmailMessage.create(
"ICANN Monthly report staging summary [SUCCESS]",
"Completed staging the following 4 ICANN reports:\na\nb\nc\nd",
new InternetAddress("recipient@example.com"),
new InternetAddress("sender@example.com")));
new InternetAddress("recipient@example.com")));
assertUploadTaskEnqueued();
}
@@ -129,8 +126,7 @@ class IcannReportingStagingActionTest {
EmailMessage.create(
"ICANN Monthly report staging summary [SUCCESS]",
"Completed staging the following 4 ICANN reports:\na\nb\nc\nd",
new InternetAddress("recipient@example.com"),
new InternetAddress("sender@example.com")));
new InternetAddress("recipient@example.com")));
assertUploadTaskEnqueued();
}
@@ -153,8 +149,7 @@ class IcannReportingStagingActionTest {
"ICANN Monthly report staging summary [FAILURE]",
"Staging failed due to google.registry.bigquery.BigqueryJobFailureException: "
+ "BigqueryJobFailureException: Expected failure, check logs for more details.",
new InternetAddress("recipient@example.com"),
new InternetAddress("sender@example.com")));
new InternetAddress("recipient@example.com")));
// Assert no upload task enqueued
cloudTasksHelper.assertNoTasksEnqueued("retryable-cron-tasks");
}
@@ -78,7 +78,6 @@ class IcannReportingUploadActionTest {
action.retrier = new Retrier(new FakeSleeper(new FakeClock()), 3);
action.reportingBucket = "basin";
action.gmailClient = gmailClient;
action.sender = new InternetAddress("sender@example.com");
action.recipient = new InternetAddress("recipient@example.com");
action.response = response;
action.clock = clock;
@@ -136,8 +135,7 @@ class IcannReportingUploadActionTest {
+ "foo-transactions-200606.csv - SUCCESS\n"
+ "tld-activity-200606.csv - FAILURE\n"
+ "tld-transactions-200606.csv - SUCCESS",
new InternetAddress("recipient@example.com"),
new InternetAddress("sender@example.com")));
new InternetAddress("recipient@example.com")));
}
@Test
@@ -169,8 +167,7 @@ class IcannReportingUploadActionTest {
"Report Filename - Upload status:\n"
+ "tld-activity-200512.csv - SUCCESS\n"
+ "tld-transactions-200512.csv - SUCCESS",
new InternetAddress("recipient@example.com"),
new InternetAddress("sender@example.com")));
new InternetAddress("recipient@example.com")));
}
@Test
@@ -215,8 +212,7 @@ class IcannReportingUploadActionTest {
+ "foo-transactions-200606.csv - SUCCESS\n"
+ "tld-activity-200606.csv - FAILURE\n"
+ "tld-transactions-200606.csv - SUCCESS",
new InternetAddress("recipient@example.com"),
new InternetAddress("sender@example.com")));
new InternetAddress("recipient@example.com")));
}
@Test
@@ -275,8 +271,7 @@ class IcannReportingUploadActionTest {
+ "foo-transactions-200606.csv - SUCCESS\n"
+ "tld-activity-200606.csv - FAILURE\n"
+ "tld-transactions-200606.csv - SUCCESS",
new InternetAddress("recipient@example.com"),
new InternetAddress("sender@example.com")));
new InternetAddress("recipient@example.com")));
}
@Test
@@ -345,8 +340,7 @@ class IcannReportingUploadActionTest {
+ "foo-transactions-200606.csv - SUCCESS\n"
+ "tld-activity-200606.csv - FAILURE\n"
+ "tld-transactions-200606.csv - SUCCESS",
new InternetAddress("recipient@example.com"),
new InternetAddress("sender@example.com")));
new InternetAddress("recipient@example.com")));
Cursor newActivityCursor =
loadByKey(Cursor.createScopedVKey(CursorType.ICANN_UPLOAD_ACTIVITY, Tld.get("new")));
@@ -161,7 +161,6 @@ class Spec11EmailUtilsTest {
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]",
@@ -169,7 +168,6 @@ class Spec11EmailUtilsTest {
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]",
@@ -179,7 +177,6 @@ class Spec11EmailUtilsTest {
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",
@@ -199,7 +196,6 @@ class Spec11EmailUtilsTest {
List<EmailMessage> capturedMessages = contentCaptor.getAllValues();
validateMessage(
capturedMessages.get(0),
"abuse@test.com",
"the.registrar@example.com",
ImmutableList.of("abuse@test.com", "bcc@test.com"),
"Super Cool Registry Daily Threat Detector [2018-07-15]",
@@ -207,7 +203,6 @@ class Spec11EmailUtilsTest {
Optional.of(MediaType.HTML_UTF_8));
validateMessage(
capturedMessages.get(1),
"abuse@test.com",
"new.registrar@example.com",
ImmutableList.of("abuse@test.com", "bcc@test.com"),
"Super Cool Registry Daily Threat Detector [2018-07-15]",
@@ -217,7 +212,6 @@ class Spec11EmailUtilsTest {
Optional.of(MediaType.HTML_UTF_8));
validateMessage(
capturedMessages.get(2),
"abuse@test.com",
"my-receiver@test.com",
ImmutableList.of(),
"Spec11 Pipeline Success 2018-07-15",
@@ -240,7 +234,6 @@ class Spec11EmailUtilsTest {
List<EmailMessage> capturedContents = contentCaptor.getAllValues();
validateMessage(
capturedContents.get(0),
"abuse@test.com",
"new.registrar@example.com",
ImmutableList.of("abuse@test.com", "bcc@test.com"),
"Super Cool Registry Monthly Threat Detector [2018-07-15]",
@@ -248,7 +241,6 @@ class Spec11EmailUtilsTest {
Optional.of(MediaType.HTML_UTF_8));
validateMessage(
capturedContents.get(1),
"abuse@test.com",
"my-receiver@test.com",
ImmutableList.of(),
"Spec11 Pipeline Success 2018-07-15",
@@ -273,7 +265,6 @@ class Spec11EmailUtilsTest {
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]",
@@ -281,7 +272,6 @@ class Spec11EmailUtilsTest {
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]",
@@ -291,7 +281,6 @@ class Spec11EmailUtilsTest {
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",
@@ -328,7 +317,6 @@ class Spec11EmailUtilsTest {
List<EmailMessage> capturedMessages = contentCaptor.getAllValues();
validateMessage(
capturedMessages.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]",
@@ -336,7 +324,6 @@ class Spec11EmailUtilsTest {
Optional.of(MediaType.HTML_UTF_8));
validateMessage(
capturedMessages.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]",
@@ -346,7 +333,6 @@ class Spec11EmailUtilsTest {
Optional.of(MediaType.HTML_UTF_8));
validateMessage(
capturedMessages.get(2),
"abuse@test.com",
"my-receiver@test.com",
ImmutableList.of(),
"Spec11 Emailing Failure 2018-07-15",
@@ -360,7 +346,6 @@ class Spec11EmailUtilsTest {
verify(gmailClient).sendEmail(contentCaptor.capture());
validateMessage(
contentCaptor.getValue(),
"abuse@test.com",
"my-receiver@test.com",
ImmutableList.of(),
"Spec11 Pipeline Alert: 2018-07",
@@ -409,7 +394,6 @@ class Spec11EmailUtilsTest {
private void validateMessage(
EmailMessage message,
String from,
String recipient,
ImmutableList<String> bccs,
String subject,
@@ -418,7 +402,6 @@ class Spec11EmailUtilsTest {
throws MessagingException {
EmailMessage.Builder expectedContentBuilder =
EmailMessage.newBuilder()
.setFrom(new InternetAddress(from))
.addRecipient(new InternetAddress(recipient))
.setSubject(subject)
.setBody(body);
@@ -39,8 +39,6 @@ class SendEmailUtilsTest {
private void setRecipients(ImmutableList<String> recipients) throws Exception {
sendEmailUtils =
new SendEmailUtils(
new InternetAddress("outgoing@registry.example"),
"outgoing display name",
recipients,
gmailClient);
}
@@ -141,7 +139,6 @@ class SendEmailUtilsTest {
EmailMessage.newBuilder()
.setSubject("Welcome to the Internet")
.setBody("It is a dark and scary place.")
.setFrom(new InternetAddress("outgoing@registry.example"))
.addBcc(new InternetAddress("bar@example.com"))
.setRecipients(recipientBuilder.build())
.build();
@@ -186,7 +183,6 @@ class SendEmailUtilsTest {
EmailMessage.newBuilder()
.setSubject("Welcome to the Internet")
.setBody("It is a dark and scary place.")
.setFrom(new InternetAddress("outgoing@registry.example"))
.setRecipients(recipientBuilder.build())
.build();
assertThat(emailMessage).isEqualTo(expectedContent);
@@ -47,7 +47,6 @@ import google.registry.ui.server.SendEmailUtils;
import google.registry.util.EmailMessage;
import google.registry.util.RegistryEnvironment;
import java.util.Optional;
import javax.mail.internet.InternetAddress;
import javax.servlet.http.HttpServletRequest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Order;
@@ -94,8 +93,6 @@ public final class ConsoleOteSetupActionTest {
action.authResult = AuthResult.createUser(UserAuthInfo.create(user, false));
action.sendEmailUtils =
new SendEmailUtils(
new InternetAddress("outgoing@registry.example"),
"UnitTest Registry",
ImmutableList.of("notification@test.example", "notification2@test.example"),
gmailClient);
action.logoFilename = "logo.png";
@@ -48,7 +48,6 @@ import google.registry.ui.server.SendEmailUtils;
import google.registry.util.EmailMessage;
import google.registry.util.RegistryEnvironment;
import java.util.Optional;
import javax.mail.internet.InternetAddress;
import javax.servlet.http.HttpServletRequest;
import org.joda.money.CurrencyUnit;
import org.junit.jupiter.api.BeforeEach;
@@ -95,8 +94,6 @@ final class ConsoleRegistrarCreatorActionTest {
action.authResult = AuthResult.createUser(UserAuthInfo.create(user, false));
action.sendEmailUtils =
new SendEmailUtils(
new InternetAddress("outgoing@registry.example"),
"UnitTest Registry",
ImmutableList.of("notification@test.example", "notification2@test.example"),
gmailClient);
action.logoFilename = "logo.png";
@@ -16,8 +16,6 @@ package google.registry.ui.server.registrar;
import static com.google.common.collect.Iterables.getOnlyElement;
import static com.google.monitoring.metrics.contrib.LongMetricSubject.assertThat;
import static google.registry.config.RegistryConfig.getGSuiteOutgoingEmailAddress;
import static google.registry.config.RegistryConfig.getGSuiteOutgoingEmailDisplayName;
import static google.registry.request.auth.AuthenticatedRegistrarAccessor.Role.ADMIN;
import static google.registry.request.auth.AuthenticatedRegistrarAccessor.Role.OWNER;
import static google.registry.security.JsonHttpTestUtils.createJsonPayload;
@@ -106,8 +104,6 @@ public abstract class RegistrarSettingsActionTestCase {
new JsonActionRunner(ImmutableMap.of(), new JsonResponse(new ResponseImpl(rsp)));
action.sendEmailUtils =
new SendEmailUtils(
getGSuiteOutgoingEmailAddress(),
getGSuiteOutgoingEmailDisplayName(),
ImmutableList.of("notification@test.example", "notification2@test.example"),
gmailClient);
action.registrarConsoleMetrics = new RegistrarConsoleMetrics();
@@ -91,8 +91,6 @@ final class RegistryLockPostActionTest {
private User userWithoutPermission;
private User userWithLockPermission;
private InternetAddress outgoingAddress;
private Domain domain;
private RegistryLockPostAction action;
@@ -109,8 +107,6 @@ final class RegistryLockPostActionTest {
createTld("tld");
domain = persistResource(DatabaseHelper.newDomain("example.tld"));
outgoingAddress = new InternetAddress("domain-registry@example.com");
when(mockRequest.getServerName()).thenReturn("registrarconsole.tld");
action =
@@ -502,7 +498,6 @@ final class RegistryLockPostActionTest {
EmailMessage sentMessage = emailCaptor.getValue();
assertThat(sentMessage.subject()).matches("Registry (un)?lock verification");
assertThat(sentMessage.body()).matches(EMAIL_MESSAGE_TEMPLATE);
assertThat(sentMessage.from()).isEqualTo(new InternetAddress("domain-registry@example.com"));
assertThat(sentMessage.recipients()).containsExactly(new InternetAddress(recipient));
}
@@ -524,12 +519,6 @@ final class RegistryLockPostActionTest {
"adminreg",
new CloudTasksHelper(clock).getTestCloudTasksUtils());
return new RegistryLockPostAction(
mockRequest,
jsonActionRunner,
authResult,
registrarAccessor,
gmailClient,
domainLockUtils,
outgoingAddress);
mockRequest, jsonActionRunner, authResult, registrarAccessor, gmailClient, domainLockUtils);
}
}