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
@@ -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()) {
|
||||
|
||||
Reference in new issue
Block a user