mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(ses): answer a paused account with the AWS message and order (#9417)
A send while account sending is paused now answers AWS's message, "Sending is paused for this account.", on v1 and v2, in place of "Account sending is disabled." The codes are unchanged. v2 SendEmail with Raw content, v2 SendBulkEmail and v1 SendBulkTemplatedEmail check the sender before refusing a paused account, as AWS does, so an unverified sender gets MessageRejected first. Every other send still refuses a paused account ahead of every check.
This commit is contained in:
1 parent
732001a90f
commit
1d74e9adc8
12 files changed
+348
-41
No files matched your search
@@ -542,7 +542,7 @@ The operations whose body has a structure member holding another structure, or h
|
||||
| map | array / any other non-object | `Start of list found where not expected` / `Expected map or null` |
|
||||
| list | object / any other non-array | `Start of structure or map found where not expected.` / `Expected list or null` |
|
||||
|
||||
A JSON `null` member counts as absent. A `null` address list element passes this check and fails later, as on AWS: `SendEmail` answers `Invalid email address null.` after its content and sender checks and before the tenant lookup, and `SendBulkEmail` reports it as the `INVALID_PARAMETER` status of the entry it belongs to (of every entry for a `null` Reply-To), or as `Destination cannot be empty` when no entry of the request has a non-null recipient, the answer every entry gets then, whatever its lists hold. A `null` element of `Topics` (`CreateContactList`, `UpdateContactList`) or `TopicPreferences` (`CreateContact`, `UpdateContact`) also passes this check, but there AWS answers it with a `500 InternalFailure`, which Floci replaces with `BadRequestException` naming the element ("1 validation error detected: Value at 'topics.1.member.topicName' failed to satisfy constraint: Member must not be null"). The account-level sending switch is still checked first, so a paused account answers `SendingPausedException` even for a malformed body. Likewise `BatchGetMetricData` checks that Virtual Deliverability Manager is enabled before it reads the body.
|
||||
A JSON `null` member counts as absent. A `null` address list element passes this check and fails later, as on AWS: `SendEmail` answers `Invalid email address null.` after its content and sender checks and before the tenant lookup, and `SendBulkEmail` reports it as the `INVALID_PARAMETER` status of the entry it belongs to (of every entry for a `null` Reply-To), or as `Destination cannot be empty` when no entry of the request has a non-null recipient, the answer every entry gets then, whatever its lists hold. A `null` element of `Topics` (`CreateContactList`, `UpdateContactList`) or `TopicPreferences` (`CreateContact`, `UpdateContact`) also passes this check, but there AWS answers it with a `500 InternalFailure`, which Floci replaces with `BadRequestException` naming the element ("1 validation error detected: Value at 'topics.1.member.topicName' failed to satisfy constraint: Member must not be null"). The account-level sending switch is still checked first on `SendEmail` with `Simple` or `Template` content and on `SendCustomVerificationEmail`, so a paused account answers `SendingPausedException` even for a malformed body. `SendEmail` with `Raw` content and `SendBulkEmail` (and v1 `SendBulkTemplatedEmail`) refuse a paused account only after the sender check, so an unverified sender gets `MessageRejected` first, as on AWS. A bulk send in which no entry names a recipient checks no sender and is still refused. Likewise `BatchGetMetricData` checks that Virtual Deliverability Manager is enabled before it reads the body.
|
||||
|
||||
The other operations check their members one at a time, and some of them still answer a wrong JSON type with `BadRequestException`. The list operations' map `Filter` answers as in the table. Their integer `PageSize`, like `CreateExportJob`'s `MaxResults`, answers a string with `STRING_VALUE can not be converted to an Integer` (`TRUE_VALUE` / `FALSE_VALUE` for a boolean, and as in the table for an object or an array), while a number is read as an int first, as on AWS: `1.5` is accepted, and a value above the int range is checked against the page-size bounds as `2147483647`.
|
||||
|
||||
|
||||
@@ -60,6 +60,16 @@ public class SesAccountService {
|
||||
return accountSettingsStore.get("sending::" + region).orElse(true);
|
||||
}
|
||||
|
||||
public void requireAccountSendingEnabled(String region) {
|
||||
if (!isAccountSendingEnabled(region)) {
|
||||
throw sendingPaused();
|
||||
}
|
||||
}
|
||||
|
||||
static AwsException sendingPaused() {
|
||||
return new AwsException("AccountSendingPausedException", "Sending is paused for this account.", 400);
|
||||
}
|
||||
|
||||
public void setAccountSendingEnabled(String region, boolean enabled) {
|
||||
accountSettingsStore.put("sending::" + region, enabled);
|
||||
LOG.infov("Updated account sending enabled for region {0}: {1}", region, enabled);
|
||||
|
||||
@@ -277,10 +277,7 @@ public class SesQueryHandler {
|
||||
}
|
||||
|
||||
private Response handleSendEmail(MultivaluedMap<String, String> params, String region) {
|
||||
if (!accountService.isAccountSendingEnabled(region)) {
|
||||
throw new AwsException("AccountSendingPausedException",
|
||||
"Account sending is disabled.", 400);
|
||||
}
|
||||
accountService.requireAccountSendingEnabled(region);
|
||||
String source = getParam(params, "Source");
|
||||
List<String> toAddresses = extractMembers(params, "Destination.ToAddresses");
|
||||
List<String> ccAddresses = extractMembers(params, "Destination.CcAddresses");
|
||||
@@ -314,10 +311,7 @@ public class SesQueryHandler {
|
||||
}
|
||||
|
||||
private Response handleSendRawEmail(MultivaluedMap<String, String> params, String region) {
|
||||
if (!accountService.isAccountSendingEnabled(region)) {
|
||||
throw new AwsException("AccountSendingPausedException",
|
||||
"Account sending is disabled.", 400);
|
||||
}
|
||||
accountService.requireAccountSendingEnabled(region);
|
||||
String source = getParam(params, "Source");
|
||||
List<String> destinations = extractMembers(params, "Destinations");
|
||||
String rawMessage = getParam(params, "RawMessage.Data");
|
||||
@@ -635,10 +629,7 @@ public class SesQueryHandler {
|
||||
}
|
||||
|
||||
private Response handleSendTemplatedEmail(MultivaluedMap<String, String> params, String region) {
|
||||
if (!accountService.isAccountSendingEnabled(region)) {
|
||||
throw new AwsException("AccountSendingPausedException",
|
||||
"Account sending is disabled.", 400);
|
||||
}
|
||||
accountService.requireAccountSendingEnabled(region);
|
||||
String source = getParam(params, "Source");
|
||||
List<String> toAddresses = extractMembers(params, "Destination.ToAddresses");
|
||||
List<String> ccAddresses = extractMembers(params, "Destination.CcAddresses");
|
||||
@@ -746,10 +737,7 @@ public class SesQueryHandler {
|
||||
}
|
||||
|
||||
private Response handleSendCustomVerificationEmail(MultivaluedMap<String, String> params, String region) {
|
||||
if (!accountService.isAccountSendingEnabled(region)) {
|
||||
throw new AwsException("AccountSendingPausedException",
|
||||
"Account sending is disabled.", 400);
|
||||
}
|
||||
accountService.requireAccountSendingEnabled(region);
|
||||
// getParam (not requireParam) so the service is the single validation authority and returns
|
||||
// the AWS-faithful "Email address not specified." / "Invalid email address<...>." shapes.
|
||||
String messageId = sesService.sendCustomVerificationEmail(
|
||||
@@ -772,10 +760,6 @@ public class SesQueryHandler {
|
||||
}
|
||||
|
||||
private Response handleSendBulkTemplatedEmail(MultivaluedMap<String, String> params, String region) {
|
||||
if (!accountService.isAccountSendingEnabled(region)) {
|
||||
throw new AwsException("AccountSendingPausedException",
|
||||
"Account sending is disabled.", 400);
|
||||
}
|
||||
String templateName = getParam(params, "Template");
|
||||
String templateArn = getParam(params, "TemplateArn");
|
||||
BulkDestinationIndexes destinations = bulkDestinationIndexes(params);
|
||||
|
||||
@@ -39,6 +39,7 @@ import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static io.floci.aws.services.ses.SesV2Json.namesRawContent;
|
||||
import static io.floci.aws.services.ses.SesV2Json.readOptionBody;
|
||||
import static io.floci.aws.services.ses.SesV2Json.remapCvetException;
|
||||
import static io.floci.aws.services.ses.SesV2Json.remapV1Exception;
|
||||
@@ -82,9 +83,8 @@ public class SesSendController {
|
||||
public Response sendEmail(@Context HttpHeaders headers, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
if (!accountService.isAccountSendingEnabled(region)) {
|
||||
throw new AwsException("SendingPausedException",
|
||||
"Account sending is disabled.", 400);
|
||||
if (!accountService.isAccountSendingEnabled(region) && !namesRawContent(objectMapper, body)) {
|
||||
throw SesAccountService.sendingPaused();
|
||||
}
|
||||
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
@@ -221,11 +221,6 @@ public class SesSendController {
|
||||
public Response sendBulkEmail(@Context HttpHeaders headers, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
if (!accountService.isAccountSendingEnabled(region)) {
|
||||
throw new AwsException("SendingPausedException",
|
||||
"Account sending is disabled.", 400);
|
||||
}
|
||||
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
SesV2RequestShapes.check("SendBulkEmail", request);
|
||||
validateTrackingOverrides(request);
|
||||
@@ -362,10 +357,7 @@ public class SesSendController {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
String templateName = null;
|
||||
try {
|
||||
if (!accountService.isAccountSendingEnabled(region)) {
|
||||
throw new AwsException("SendingPausedException",
|
||||
"Account sending is disabled.", 400);
|
||||
}
|
||||
accountService.requireAccountSendingEnabled(region);
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
SesV2RequestShapes.check("SendCustomVerificationEmail", request);
|
||||
templateName = request.path("TemplateName").asText(null);
|
||||
|
||||
@@ -136,6 +136,7 @@ public class SesService {
|
||||
// S/MIME certificate associations live in SesIdentityCertificateService, which the v2 controller
|
||||
// calls directly; the facade only reaches it for the identity delete-guard.
|
||||
private final SesIdentityCertificateService certificateService;
|
||||
private final SesAccountService accountService;
|
||||
private final SmtpRelay smtpRelay;
|
||||
private final SesEventPublisher eventPublisher;
|
||||
private final String defaultAccountId;
|
||||
@@ -154,8 +155,8 @@ public class SesService {
|
||||
SesSuppressionService suppressionService, SesDedicatedIpService dedicatedIpService,
|
||||
SesTemplateService templateService, SesSentEmailService sentEmailService,
|
||||
SesTenantService tenantService, SesConfigurationSetService configSetService,
|
||||
SesIdentityCertificateService certificateService, SmtpRelay smtpRelay,
|
||||
SesEventPublisher eventPublisher, EmulatorConfig config,
|
||||
SesIdentityCertificateService certificateService, SesAccountService accountService,
|
||||
SmtpRelay smtpRelay, SesEventPublisher eventPublisher, EmulatorConfig config,
|
||||
RegionResolver regionResolver) {
|
||||
this.identityService = identityService;
|
||||
this.sentEmailService = sentEmailService;
|
||||
@@ -168,6 +169,7 @@ public class SesService {
|
||||
this.cvetService = cvetService;
|
||||
this.tenantService = tenantService;
|
||||
this.certificateService = certificateService;
|
||||
this.accountService = accountService;
|
||||
this.smtpRelay = smtpRelay;
|
||||
this.eventPublisher = eventPublisher;
|
||||
this.defaultAccountId = config.defaultAccountId();
|
||||
@@ -187,6 +189,7 @@ public class SesService {
|
||||
SesCvetService cvetService,
|
||||
SesTenantService tenantService,
|
||||
SesIdentityCertificateService certificateService,
|
||||
SesAccountService accountService,
|
||||
SmtpRelay smtpRelay) {
|
||||
this.identityService = identityService;
|
||||
this.sentEmailService = sentEmailService;
|
||||
@@ -199,6 +202,7 @@ public class SesService {
|
||||
this.cvetService = cvetService;
|
||||
this.tenantService = tenantService;
|
||||
this.certificateService = certificateService;
|
||||
this.accountService = accountService;
|
||||
this.smtpRelay = smtpRelay;
|
||||
this.eventPublisher = null;
|
||||
this.defaultAccountId = "000000000000";
|
||||
@@ -590,6 +594,9 @@ public class SesService {
|
||||
SesAddressLength.requireRaw(request, raw, parsed.message());
|
||||
if (requireVerifiedSender) {
|
||||
requireVerifiedSenders(rawSendingAddresses(request, raw, headers), region);
|
||||
// v2 refuses a paused account only here, after the sender check; v1 SendRawEmail has
|
||||
// already refused it ahead of every check (probe-confirmed).
|
||||
accountService.requireAccountSendingEnabled(region);
|
||||
}
|
||||
requireTenantAssociations(tenant, effectiveSource, effectiveConfigSet, null, region);
|
||||
// Resolve suppression before recording the message so a bad ListManagementOptions (e.g. an
|
||||
@@ -1723,8 +1730,10 @@ public class SesService {
|
||||
}
|
||||
|
||||
// When no entry names a recipient, SES answers every entry the same, whatever its lists hold
|
||||
// (probe-confirmed for null elements, empty lists and an empty Destination).
|
||||
// (probe-confirmed for null elements, empty lists and an empty Destination). No sender is
|
||||
// checked then, so a paused account is still refused (unprobed).
|
||||
if (!anyBulkRecipient(request.entries())) {
|
||||
accountService.requireAccountSendingEnabled(request.region());
|
||||
return request.entries().stream()
|
||||
.map(entry -> BulkEmailEntryResult.failure(BulkEmailEntryResult.Status.INVALID_PARAMETER,
|
||||
"Destination cannot be empty"))
|
||||
@@ -1734,10 +1743,13 @@ public class SesService {
|
||||
SesTemplateService.requireSendTemplateName(request.templateName());
|
||||
}
|
||||
// The sender and return path are checked once for the whole call, then a stored template is
|
||||
// looked up, then the tenant associations, as on a single send (probe-confirmed).
|
||||
// looked up, then the tenant associations, as on a single send (probe-confirmed). A paused
|
||||
// account is refused after the sender check (probe-confirmed); placing it ahead of the
|
||||
// template lookup is a choice.
|
||||
requireVerifiedSenders(List.of(
|
||||
new SendingAddress(request.source(), request.sourceArn()),
|
||||
new SendingAddress(request.returnPath(), request.returnPathArn())), request.region());
|
||||
accountService.requireAccountSendingEnabled(request.region());
|
||||
EmailContent.InlineTemplate template = switch (request.defaultContent()) {
|
||||
case EmailContent.Template stored -> templateService.inline(stored, request.region());
|
||||
case EmailContent.InlineTemplate inline -> inline;
|
||||
|
||||
@@ -51,7 +51,7 @@ final class SesV2Json {
|
||||
case "AlreadyExists", "ConfigurationSetAlreadyExists",
|
||||
"CustomVerificationEmailTemplateAlreadyExists" ->
|
||||
new AwsException("AlreadyExistsException", e.getMessage(), 400);
|
||||
case "ConfigurationSetSendingPausedException" ->
|
||||
case "ConfigurationSetSendingPausedException", "AccountSendingPausedException" ->
|
||||
new AwsException("SendingPausedException", e.getMessage(), 400);
|
||||
default -> e;
|
||||
};
|
||||
@@ -146,6 +146,19 @@ final class SesV2Json {
|
||||
return request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a SendEmail body names Raw content, which a paused account refuses only after the
|
||||
* sender check. A body that does not parse names none.
|
||||
*/
|
||||
static boolean namesRawContent(ObjectMapper objectMapper, String body) {
|
||||
try {
|
||||
return readOptionBody(objectMapper, body).path("Content").has("Raw");
|
||||
} catch (AwsException ignored) {
|
||||
// A body that does not parse is not a raw send, so a paused account still answers first.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** Read an optional string member, rejecting a non-string value the way the AWS deserialization layer does. */
|
||||
static String parseOptionString(JsonNode node, String field) {
|
||||
if (node.isMissingNode() || node.isNull()) {
|
||||
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
package io.floci.aws.services.ses;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
|
||||
import static io.floci.aws.services.ses.SesV2Requests.post;
|
||||
import static io.floci.aws.services.ses.SesV2Requests.v2;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
/**
|
||||
* Where a paused account is refused among the v2 send checks (probe-confirmed): SendEmail with Simple
|
||||
* or Template content refuses it first, SendEmail with Raw content and SendBulkEmail only after the
|
||||
* sender check.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class SesAccountSendingPausedV2IntegrationTest {
|
||||
|
||||
private static final String VERIFIED = "paused-v2-verified@floci.test";
|
||||
private static final String UNVERIFIED = "paused-v2-unverified@floci.test";
|
||||
private static final String PAUSED = "Sending is paused for this account.";
|
||||
private static final String NOT_VERIFIED = "Email address is not verified.";
|
||||
|
||||
@BeforeEach
|
||||
void pauseSending() {
|
||||
post("/v2/email/identities", "{\"EmailIdentity\":\"" + VERIFIED + "\"}");
|
||||
setSending(false);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void resumeSending() {
|
||||
setSending(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
void sendEmailSimple_unverifiedSender_isRefusedByThePause() {
|
||||
post("/v2/email/outbound-emails", """
|
||||
{"FromEmailAddress": "%s", "Destination": {"ToAddresses": ["to@example.com"]},
|
||||
"Content": {"Simple": {"Subject": {"Data": "s"}, "Body": {"Text": {"Data": "b"}}}}}
|
||||
""".formatted(UNVERIFIED))
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("SendingPausedException"))
|
||||
.body("message", equalTo(PAUSED));
|
||||
}
|
||||
|
||||
@Test
|
||||
void sendEmailTemplate_unverifiedSenderAndMissingTemplate_isRefusedByThePause() {
|
||||
post("/v2/email/outbound-emails", """
|
||||
{"FromEmailAddress": "%s", "Destination": {"ToAddresses": ["to@example.com"]},
|
||||
"Content": {"Template": {"TemplateName": "paused-v2-missing", "TemplateData": "{}"}}}
|
||||
""".formatted(UNVERIFIED))
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("SendingPausedException"))
|
||||
.body("message", equalTo(PAUSED));
|
||||
}
|
||||
|
||||
@Test
|
||||
void sendEmail_malformedBody_isRefusedByThePause() {
|
||||
post("/v2/email/outbound-emails", "{not json")
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("SendingPausedException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void sendEmailRaw_unverifiedSender_isRejectedBeforeThePause() {
|
||||
post("/v2/email/outbound-emails", rawBody(UNVERIFIED))
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("MessageRejected"))
|
||||
.body("message", startsWith(NOT_VERIFIED));
|
||||
}
|
||||
|
||||
@Test
|
||||
void sendEmailRaw_verifiedSender_isRefusedByThePause() {
|
||||
post("/v2/email/outbound-emails", rawBody(VERIFIED))
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("SendingPausedException"))
|
||||
.body("message", equalTo(PAUSED));
|
||||
}
|
||||
|
||||
@Test
|
||||
void sendBulkEmail_unverifiedSender_isRejectedBeforeThePause() {
|
||||
post("/v2/email/outbound-bulk-emails", bulkBody(UNVERIFIED))
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("MessageRejected"))
|
||||
.body("message", startsWith(NOT_VERIFIED));
|
||||
}
|
||||
|
||||
@Test
|
||||
void sendBulkEmail_verifiedSender_isRefusedByThePause() {
|
||||
post("/v2/email/outbound-bulk-emails", bulkBody(VERIFIED))
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("SendingPausedException"))
|
||||
.body("message", equalTo(PAUSED));
|
||||
}
|
||||
|
||||
private static String rawBody(String sender) {
|
||||
String mime = "From: " + sender + "\r\nTo: to@example.com\r\nSubject: s\r\n\r\nbody";
|
||||
String data = Base64.getEncoder().encodeToString(mime.getBytes(StandardCharsets.UTF_8));
|
||||
return "{\"Content\": {\"Raw\": {\"Data\": \"" + data + "\"}}}";
|
||||
}
|
||||
|
||||
private static String bulkBody(String sender) {
|
||||
return """
|
||||
{"FromEmailAddress": "%s",
|
||||
"DefaultContent": {"Template": {"TemplateContent": {"Subject": "s", "Text": "t"}}},
|
||||
"BulkEmailEntries": [{"Destination": {"ToAddresses": ["to@example.com"]}}]}
|
||||
""".formatted(sender);
|
||||
}
|
||||
|
||||
private static void setSending(boolean enabled) {
|
||||
v2()
|
||||
.body("{\"SendingEnabled\":" + enabled + "}")
|
||||
.when()
|
||||
.put("/v2/email/account/sending")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
}
|
||||
@@ -222,6 +222,7 @@ class SesBulkV1IntegrationTest {
|
||||
.formParam("Action", "SendBulkTemplatedEmail")
|
||||
.formParam("Source", SENDER)
|
||||
.formParam("Template", "v1-bulk-welcome")
|
||||
.formParam("DefaultTemplateData", "{}")
|
||||
.formParam("Destinations.member.1.Destination.ToAddresses.member.1", "alice@example.com")
|
||||
.when()
|
||||
.post("/")
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
package io.floci.aws.services.ses;
|
||||
|
||||
import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.services.ses.model.BulkEmailEntry;
|
||||
import io.floci.aws.services.ses.model.EmailContent;
|
||||
import io.floci.aws.services.ses.model.SendBulkEmailRequest;
|
||||
import io.floci.aws.services.ses.model.SendEmailRequest;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
/**
|
||||
* A raw send and a bulk send check the sender before they refuse a paused account
|
||||
* (probe-confirmed on v2 SendEmail Raw, v2 SendBulkEmail and v1 SendBulkTemplatedEmail).
|
||||
*/
|
||||
class SesServiceAccountSendingPausedTest {
|
||||
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String SENDER = "from@example.com";
|
||||
private static final String TO = "to@example.com";
|
||||
private static final EmailContent.InlineTemplate INLINE =
|
||||
new EmailContent.InlineTemplate("s", "t", null, null, List.of());
|
||||
private static final String RAW = "From: " + SENDER + "\r\nTo: " + TO + "\r\nSubject: s\r\n\r\nbody";
|
||||
|
||||
private SesServiceTestBuilder builder;
|
||||
private SesService service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
builder = SesServiceTestBuilder.create();
|
||||
service = builder.build();
|
||||
builder.accountService().setAccountSendingEnabled(REGION, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
void rawSend_unverifiedSender_isRejectedBeforeThePause() {
|
||||
AwsException e = assertThrows(AwsException.class, () -> service.sendEmail(rawRequest()));
|
||||
|
||||
assertEquals("MessageRejected", e.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rawSend_verifiedSender_isRefusedByThePause() {
|
||||
builder.identityService().verifyEmailIdentity(SENDER, REGION);
|
||||
|
||||
AwsException e = assertThrows(AwsException.class, () -> service.sendEmail(rawRequest()));
|
||||
|
||||
assertPaused(e);
|
||||
}
|
||||
|
||||
@Test
|
||||
void bulkSend_unverifiedSender_isRejectedBeforeThePause() {
|
||||
AwsException e = assertThrows(AwsException.class, () -> service.sendBulkEmail(bulkRequest(INLINE)));
|
||||
|
||||
assertEquals("MessageRejected", e.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void bulkSend_verifiedSender_isRefusedByThePause() {
|
||||
builder.identityService().verifyEmailIdentity(SENDER, REGION);
|
||||
|
||||
AwsException e = assertThrows(AwsException.class, () -> service.sendBulkEmail(bulkRequest(INLINE)));
|
||||
|
||||
assertPaused(e);
|
||||
}
|
||||
|
||||
@Test
|
||||
void bulkSend_verifiedSender_isRefusedByThePauseBeforeAMissingTemplate() {
|
||||
builder.identityService().verifyEmailIdentity(SENDER, REGION);
|
||||
|
||||
AwsException e = assertThrows(AwsException.class, () -> service.sendBulkEmail(
|
||||
bulkRequest(new EmailContent.Template("missing", null, List.of()))));
|
||||
|
||||
assertPaused(e);
|
||||
}
|
||||
|
||||
@Test
|
||||
void bulkSend_noRecipient_isRefusedByThePause() {
|
||||
AwsException e = assertThrows(AwsException.class, () -> service.sendBulkEmail(SendBulkEmailRequest.builder()
|
||||
.source(SENDER)
|
||||
.region(REGION)
|
||||
.defaultContent(INLINE)
|
||||
.entries(List.of(new BulkEmailEntry(List.of(), null, null, null, null, null)))
|
||||
.build()));
|
||||
|
||||
assertPaused(e);
|
||||
}
|
||||
|
||||
private static SendEmailRequest rawRequest() {
|
||||
return SendEmailRequest.builder()
|
||||
.region(REGION)
|
||||
.content(new EmailContent.Raw(RAW))
|
||||
.build();
|
||||
}
|
||||
|
||||
private static SendBulkEmailRequest bulkRequest(EmailContent.TemplateContent content) {
|
||||
return SendBulkEmailRequest.builder()
|
||||
.source(SENDER)
|
||||
.region(REGION)
|
||||
.defaultContent(content)
|
||||
.entries(List.of(new BulkEmailEntry(List.of(TO), null, null, null, null, null)))
|
||||
.build();
|
||||
}
|
||||
|
||||
private static void assertPaused(AwsException e) {
|
||||
assertEquals("AccountSendingPausedException", e.getErrorCode());
|
||||
assertEquals("Sending is paused for this account.", e.getMessage());
|
||||
assertEquals(400, e.getHttpStatus());
|
||||
}
|
||||
}
|
||||
@@ -65,6 +65,8 @@ final class SesServiceTestBuilder {
|
||||
private SesCvetService cvetService;
|
||||
private SesSentEmailService sentEmailService;
|
||||
private SesIdentityCertificateService certificateService;
|
||||
private final SesAccountService accountService =
|
||||
new SesAccountService(new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>());
|
||||
|
||||
static SesServiceTestBuilder create() {
|
||||
return new SesServiceTestBuilder();
|
||||
@@ -166,6 +168,10 @@ final class SesServiceTestBuilder {
|
||||
return identityService;
|
||||
}
|
||||
|
||||
SesAccountService accountService() {
|
||||
return accountService;
|
||||
}
|
||||
|
||||
SesIdentityCertificateService certificateService() {
|
||||
if (certificateService == null) {
|
||||
throw new IllegalStateException("call build() first");
|
||||
@@ -196,6 +202,7 @@ final class SesServiceTestBuilder {
|
||||
cvetService,
|
||||
new SesTenantService(tenantStore, tenantAssociationStore, clock, new SecureRandom()),
|
||||
certificateService,
|
||||
accountService,
|
||||
smtpRelay);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
package io.floci.aws.services.ses;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.floci.aws.services.ses.SesV1Requests.query;
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
|
||||
@@ -51,7 +53,8 @@ class SesV1AccountSendingPausedTest {
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body(containsString("<Code>AccountSendingPausedException</Code>"));
|
||||
.body(containsString("<Code>AccountSendingPausedException</Code>"))
|
||||
.body(containsString("<Message>Sending is paused for this account.</Message>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -67,7 +70,8 @@ class SesV1AccountSendingPausedTest {
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body(containsString("<Code>AccountSendingPausedException</Code>"));
|
||||
.body(containsString("<Code>AccountSendingPausedException</Code>"))
|
||||
.body(containsString("<Message>Sending is paused for this account.</Message>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -84,6 +88,42 @@ class SesV1AccountSendingPausedTest {
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body(containsString("<Code>AccountSendingPausedException</Code>"));
|
||||
.body(containsString("<Code>AccountSendingPausedException</Code>"))
|
||||
.body(containsString("<Message>Sending is paused for this account.</Message>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void sendBulkTemplatedEmail_pausedUnverifiedSender_isRejectedBeforeThePause() {
|
||||
sendBulkTemplatedEmail("paused-v1-unverified@floci.test")
|
||||
.statusCode(400)
|
||||
.body(containsString("<Code>MessageRejected</Code>"))
|
||||
.body(containsString("Email address is not verified."));
|
||||
}
|
||||
|
||||
@Test
|
||||
void sendBulkTemplatedEmail_pausedVerifiedSender_returnsAccountSendingPausedException() {
|
||||
String sender = "paused-v1-verified@floci.test";
|
||||
query("VerifyEmailIdentity")
|
||||
.formParam("EmailAddress", sender)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
sendBulkTemplatedEmail(sender)
|
||||
.statusCode(400)
|
||||
.body(containsString("<Code>AccountSendingPausedException</Code>"))
|
||||
.body(containsString("<Message>Sending is paused for this account.</Message>"));
|
||||
}
|
||||
|
||||
private static ValidatableResponse sendBulkTemplatedEmail(String sender) {
|
||||
return query("SendBulkTemplatedEmail")
|
||||
.formParam("Source", sender)
|
||||
.formParam("Template", "any-template")
|
||||
.formParam("DefaultTemplateData", "{}")
|
||||
.formParam("Destinations.member.1.Destination.ToAddresses.member.1", "recipient@example.com")
|
||||
.when()
|
||||
.post("/")
|
||||
.then();
|
||||
}
|
||||
}
|
||||
@@ -63,6 +63,8 @@ class SesV2JsonTest {
|
||||
"CustomVerificationEmailTemplateAlreadyExists", "m", 400)).getErrorCode());
|
||||
assertEquals("SendingPausedException", SesV2Json.remapV1Exception(new AwsException(
|
||||
"ConfigurationSetSendingPausedException", "m", 400)).getErrorCode());
|
||||
assertEquals("SendingPausedException", SesV2Json.remapV1Exception(new AwsException(
|
||||
"AccountSendingPausedException", "m", 400)).getErrorCode());
|
||||
|
||||
AwsException restatedByCallers = new AwsException(
|
||||
"CustomVerificationEmailTemplateDoesNotExist", "v1 sentence", 400);
|
||||
@@ -72,6 +74,15 @@ class SesV2JsonTest {
|
||||
assertSame(untouched, SesV2Json.remapV1Exception(untouched));
|
||||
}
|
||||
|
||||
@Test
|
||||
void namesRawContent_readsTheContentMember() {
|
||||
assertTrue(SesV2Json.namesRawContent(MAPPER, "{\"Content\": {\"Raw\": {\"Data\": \"x\"}}}"));
|
||||
assertFalse(SesV2Json.namesRawContent(MAPPER, "{\"Content\": {\"Simple\": {}}}"));
|
||||
assertFalse(SesV2Json.namesRawContent(MAPPER, ""));
|
||||
assertFalse(SesV2Json.namesRawContent(MAPPER, "{not json"));
|
||||
assertFalse(SesV2Json.namesRawContent(MAPPER, "[]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void remapCvetException_restatesAMissingTemplateAndRemapsTheRest() {
|
||||
AwsException missing = SesV2Json.remapCvetException(new AwsException(
|
||||
|
||||
Reference in new issue
Block a user