mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix(ses): make FromEmailAddress optional for v2 SendEmail (#1561)
The v2 SendEmail handler required FromEmailAddress for every content type,
diverging from AWS where it is marked Required: No. Match the AWS behavior,
verified against real AWS via probes (including the raw HTTP error bodies):
- Raw content takes its sender from the MIME From header; FromEmailAddress may
be omitted. When neither is present the send fails. The check lives in the
shared SesService.sendRawEmail and throws the v1-native InvalidParameterValue
"Missing required header 'From'." — the v2 controller's remapV1Exception turns
it into BadRequestException, so v1 Query keeps InvalidParameterValue and v2
REST returns BadRequestException, both matching real AWS. This also fixes the
v1 SendRawEmail path, which previously accepted a From-less raw message.
- Simple content with no FromEmailAddress returns BadRequestException with a
null message body ({"message":null}), exactly as AWS does.
- Templated content with no FromEmailAddress returns BadRequestException
"Source cannot be empty".
Tests: v2 cases folded into SesV2IntegrationTest (Raw-with-MIME-From success,
Simple null-message, Templated "Source cannot be empty") and a v1 case in
SesIntegrationTest pinning the Query wire shape.
This commit is contained in:
1 parent
2142ff6e3c
commit
01c7e1e62d
4 files changed
+105
-5
No files matched your search
@@ -270,11 +270,10 @@ public class SesController {
|
||||
JsonNode request = objectMapper.readTree(body);
|
||||
requireJsonObject(request);
|
||||
|
||||
// FromEmailAddress is optional per the AWS v2 contract. Each content type below
|
||||
// enforces the sender requirement the way AWS does: Raw can take its From from the
|
||||
// MIME message, while Simple and Templated require FromEmailAddress.
|
||||
String fromEmailAddress = request.path("FromEmailAddress").asText(null);
|
||||
if (fromEmailAddress == null || fromEmailAddress.isBlank()) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"FromEmailAddress is required.", 400);
|
||||
}
|
||||
|
||||
JsonNode destination = requireObjectOrAbsent(request, "Destination");
|
||||
List<String> toAddresses = jsonArrayToList(destination.path("ToAddresses"));
|
||||
@@ -301,6 +300,10 @@ public class SesController {
|
||||
messageId = sesService.sendRawEmail(fromEmailAddress, allDestinations, rawData,
|
||||
configurationSetName, emailTags, region);
|
||||
} else if (content.has("Simple")) {
|
||||
if (fromEmailAddress == null || fromEmailAddress.isBlank()) {
|
||||
// AWS returns BadRequestException with a null message body here.
|
||||
throw new AwsException("BadRequestException", null, 400);
|
||||
}
|
||||
JsonNode simple = content.path("Simple");
|
||||
String subject = simple.path("Subject").path("Data").asText("");
|
||||
String bodyText = simple.path("Body").path("Text").path("Data").asText(null);
|
||||
@@ -310,6 +313,9 @@ public class SesController {
|
||||
bccAddresses, replyToAddresses, subject, bodyText, bodyHtml,
|
||||
configurationSetName, emailTags, additionalHeaders, region);
|
||||
} else if (content.has("Template")) {
|
||||
if (fromEmailAddress == null || fromEmailAddress.isBlank()) {
|
||||
throw new AwsException("BadRequestException", "Source cannot be empty", 400);
|
||||
}
|
||||
JsonNode template = content.path("Template");
|
||||
String templateName = template.path("TemplateName").asText(null);
|
||||
String templateArn = template.path("TemplateArn").asText(null);
|
||||
|
||||
@@ -254,6 +254,13 @@ public class SesService {
|
||||
String effectiveSource = sourceOmitted && headers != null && !headers.from().isBlank()
|
||||
? headers.from()
|
||||
: source;
|
||||
if (effectiveSource == null || effectiveSource.isBlank()) {
|
||||
// Shared by the v1 Query and v2 REST surfaces. Throw the v1-native code; the v2
|
||||
// controller's remapV1Exception translates InvalidParameterValue -> BadRequestException.
|
||||
// Verified against real AWS: v1 returns InvalidParameterValue and v2 BadRequestException,
|
||||
// both with this message.
|
||||
throw new AwsException("InvalidParameterValue", "Missing required header 'From'.", 400);
|
||||
}
|
||||
List<String> effectiveDestinations = hasExplicitDestinations
|
||||
? destinations
|
||||
: allRecipients(headers.to(), headers.cc(), headers.bcc());
|
||||
|
||||
Reference in new issue
Block a user