mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
feat(ses): add MAIL FROM domain and identity attribute operations (#716)
* feat(ses): add MAIL FROM domain and identity attribute operations
v1 (Query):
- SetIdentityMailFromDomain / GetIdentityMailFromDomainAttributes
- SetIdentityFeedbackForwardingEnabled
- SetIdentityHeadersInNotificationsEnabled
- GetIdentityNotificationAttributes now reflects the stored
feedbackForwardingEnabled and per-NotificationType
headersInNotificationsEnabled flags instead of hard-coded defaults
v2 (REST JSON):
- PUT /v2/email/identities/{id}/mail-from -> PutEmailIdentityMailFromAttributes
- GetEmailIdentity response surfaces real MailFromAttributes
(MailFromDomain / MailFromDomainStatus / BehaviorOnMxFailure) instead
of the previously hard-coded "" / NOT_STARTED / USE_DEFAULT_VALUE
- v1 PascalCase <-> v2 SCREAMING_SNAKE BehaviorOnMxFailure values are
translated at the controller boundary, with both ends rejecting
unknown enum values
Identity gains mailFromDomain, behaviorOnMxFailure (v1 form),
mailFromDomainStatus, and headersInNotificationsEnabled fields. The
service layer normalizes BehaviorOnMxFailure to the canonical SESv1
enum values (UseDefaultValue / RejectMessage), so storage is
consistent regardless of which protocol wrote it.
Validation (verified against live aws-cli output):
- ForwardingEnabled / Enabled / MailFromDomain are required on the
matching v1 setters; missing values produce InvalidParameterValue
rather than silently being treated as false / null
- An empty-string MailFromDomain remains the documented "clear" path,
distinct from a missing parameter; whitespace-only values are
rejected (only "" or null clear the setting)
- BehaviorOnMxFailure / NotificationType enum violations return the
AWS-canonical "1 validation error detected: Value at '<param>' failed
to satisfy constraint: Member must satisfy enum value set: [...]"
message: ValidationError on v1, BadRequestException on v2
- Unknown identity on v1 setters returns InvalidParameterValue with
the AWS-canonical "Identity <X> does not exist." form (HTTP 400)
- v2 PutEmailIdentityMailFromAttributes follows the same wire mapping:
unknown identity surfaces as BadRequestException (HTTP 400) via
remapV1Exception, with the same "Identity <X> does not exist."
message text. Schema / enum validation runs before the service call
so an unknown enum on a missing identity still surfaces as an enum
error rather than as the identity error
- v2 controller validates that MailFromDomain and BehaviorOnMxFailure
are JSON strings; non-textual values produce BadRequestException
- AwsQueryController.SES_ACTIONS picks up the new v1 actions for the
auth-less fallback dispatch
Tests: 21 v1 integration cases, 9 v2 integration cases, 4 SDK compat
cases (AWS Java SDK 2.42.24).
* fix(ses): align identity-setter missing-identity errors with live AWS
Previously setFeedbackForwardingEnabled threw NotFoundException/404 and
setHeadersInNotificationsEnabled threw a Floci-specific
"Identity <X> does not exist." message. Real AWS verified via
aws-cli returns InvalidParameterValue (HTTP 400) for both, but with
*different* operation-specific message texts:
- SetIdentityFeedbackForwardingEnabled (also v2 PUT /feedback after
remapV1Exception):
Identity X is invalid. Must be a verified email address or domain.
- SetIdentityHeadersInNotificationsEnabled:
Identity X is invalid. It must be a verified email address or domain.
- SetIdentityMailFromDomain (unchanged in this commit):
Identity <X> does not exist.
Update the service-level throws so each setter emits its operation's
exact wire shape. setFeedbackForwardingEnabled now also benefits the
pre-existing v2 PUT /feedback endpoint, which previously surfaced
NotFoundException/404 instead of BadRequestException/400.
Tests:
- v1 unknown-identity coverage for SetIdentityFeedbackForwardingEnabled
(new) and updated message-text assertion for HeadersInNotificationsEnabled
- v2 unknown-identity coverage for PUT /feedback
- SDK compat additions: getIdentityNotificationAttributes round-trip
exercising forwarding/header flags, and v2
PutEmailIdentityMailFromAttributes unknown-identity throwing
BadRequestException
* test(ses): update putFeedbackAttributes_notFound to expect BadRequest
The previous commit changed setFeedbackForwardingEnabled to throw
InvalidParameterValue (HTTP 400) for missing identities to match real
AWS, which propagates through remapV1Exception as BadRequestException
on the v2 PUT /feedback path. The pre-existing
SesV2IntegrationTest.putFeedbackAttributes_notFound still asserted the
old 404 / NotFoundException behavior, so it began failing in CI.
Update the test to expect 400 / BadRequestException, matching the
verified live AWS response.
This commit is contained in:
1 parent
aee46fe2da
commit
bd3a33326c
10 files changed
+951
-11
No files matched your search
@@ -299,6 +299,9 @@ public class AwsQueryController {
|
||||
"SendEmail", "SendRawEmail", "GetSendQuota", "GetSendStatistics",
|
||||
"GetAccountSendingEnabled", "ListVerifiedEmailAddresses", "DeleteVerifiedEmailAddress",
|
||||
"SetIdentityNotificationTopic", "GetIdentityNotificationAttributes",
|
||||
"SetIdentityFeedbackForwardingEnabled",
|
||||
"SetIdentityHeadersInNotificationsEnabled",
|
||||
"SetIdentityMailFromDomain", "GetIdentityMailFromDomainAttributes",
|
||||
"GetIdentityDkimAttributes",
|
||||
"CreateTemplate", "UpdateTemplate", "GetTemplate", "DeleteTemplate",
|
||||
"ListTemplates", "SendTemplatedEmail", "SendBulkTemplatedEmail",
|
||||
|
||||
@@ -156,6 +156,51 @@ public class SesController {
|
||||
}
|
||||
}
|
||||
|
||||
// ────────────────── Identity MAIL FROM ──────────────────────────
|
||||
|
||||
@PUT
|
||||
@Path("/identities/{emailIdentity}/mail-from")
|
||||
public Response putEmailIdentityMailFromAttributes(@Context HttpHeaders headers,
|
||||
@PathParam("emailIdentity") String emailIdentity,
|
||||
String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
if (body == null || body.isBlank()) {
|
||||
throw new AwsException("BadRequestException", "Request body is required.", 400);
|
||||
}
|
||||
JsonNode request = objectMapper.readTree(body);
|
||||
requireJsonObject(request);
|
||||
JsonNode mailFromDomainNode = request.path("MailFromDomain");
|
||||
if (mailFromDomainNode.isMissingNode()) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"MailFromDomain is required (use an empty string to clear the existing setting).", 400);
|
||||
}
|
||||
if (!mailFromDomainNode.isNull() && !mailFromDomainNode.isTextual()) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"MailFromDomain must be a JSON string (or null).", 400);
|
||||
}
|
||||
String mailFromDomain = mailFromDomainNode.isNull()
|
||||
? ""
|
||||
: mailFromDomainNode.asText("");
|
||||
JsonNode behaviorNode = request.path("BehaviorOnMxFailure");
|
||||
String behaviorV2 = null;
|
||||
if (!behaviorNode.isMissingNode() && !behaviorNode.isNull()) {
|
||||
if (!behaviorNode.isTextual()) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"BehaviorOnMxFailure must be a JSON string.", 400);
|
||||
}
|
||||
behaviorV2 = behaviorNode.asText(null);
|
||||
}
|
||||
String behaviorV1 = v2BehaviorToV1(behaviorV2);
|
||||
sesService.setMailFromDomain(emailIdentity, mailFromDomain, behaviorV1, region);
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
} catch (com.fasterxml.jackson.core.JsonProcessingException e) {
|
||||
throw new AwsException("BadRequestException", e.getMessage(), 400);
|
||||
}
|
||||
}
|
||||
|
||||
// ──────────────────── Identity Feedback ─────────────────────────
|
||||
|
||||
@PUT
|
||||
@@ -650,9 +695,12 @@ public class SesController {
|
||||
result.set("DkimAttributes", buildDkimAttributes(identity));
|
||||
|
||||
ObjectNode mailFromAttributes = result.putObject("MailFromAttributes");
|
||||
mailFromAttributes.put("MailFromDomain", "");
|
||||
mailFromAttributes.put("MailFromDomainStatus", "NOT_STARTED");
|
||||
mailFromAttributes.put("BehaviorOnMxFailure", "USE_DEFAULT_VALUE");
|
||||
String mailFromDomain = identity.getMailFromDomain();
|
||||
mailFromAttributes.put("MailFromDomain", mailFromDomain == null ? "" : mailFromDomain);
|
||||
mailFromAttributes.put("MailFromDomainStatus",
|
||||
mailFromDomain == null ? "NOT_STARTED" : toV2Status(identity.getMailFromDomainStatus()));
|
||||
mailFromAttributes.put("BehaviorOnMxFailure",
|
||||
v1BehaviorToV2(identity.getBehaviorOnMxFailure()));
|
||||
|
||||
result.putObject("Policies");
|
||||
result.putArray("Tags");
|
||||
@@ -660,6 +708,28 @@ public class SesController {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static String v1BehaviorToV2(String v1) {
|
||||
if ("RejectMessage".equals(v1)) {
|
||||
return "REJECT_MESSAGE";
|
||||
}
|
||||
return "USE_DEFAULT_VALUE";
|
||||
}
|
||||
|
||||
private static String v2BehaviorToV1(String v2) {
|
||||
if (v2 == null) {
|
||||
return null;
|
||||
}
|
||||
if ("REJECT_MESSAGE".equals(v2)) {
|
||||
return "RejectMessage";
|
||||
}
|
||||
if ("USE_DEFAULT_VALUE".equals(v2)) {
|
||||
return "UseDefaultValue";
|
||||
}
|
||||
throw new AwsException("BadRequestException",
|
||||
"1 validation error detected: Value at 'behaviorOnMxFailure' failed to satisfy "
|
||||
+ "constraint: Member must satisfy enum value set: [REJECT_MESSAGE, USE_DEFAULT_VALUE]", 400);
|
||||
}
|
||||
|
||||
private ObjectNode buildDkimAttributes(Identity identity) {
|
||||
ObjectNode dkim = objectMapper.createObjectNode();
|
||||
dkim.put("SigningEnabled", identity.isDkimEnabled());
|
||||
|
||||
@@ -58,6 +58,10 @@ public class SesQueryHandler {
|
||||
case "DeleteVerifiedEmailAddress" -> handleDeleteVerifiedEmailAddress(params, region);
|
||||
case "SetIdentityNotificationTopic" -> handleSetIdentityNotificationTopic(params, region);
|
||||
case "GetIdentityNotificationAttributes" -> handleGetIdentityNotificationAttributes(params, region);
|
||||
case "SetIdentityFeedbackForwardingEnabled" -> handleSetIdentityFeedbackForwardingEnabled(params, region);
|
||||
case "SetIdentityHeadersInNotificationsEnabled" -> handleSetIdentityHeadersInNotificationsEnabled(params, region);
|
||||
case "SetIdentityMailFromDomain" -> handleSetIdentityMailFromDomain(params, region);
|
||||
case "GetIdentityMailFromDomainAttributes" -> handleGetIdentityMailFromDomainAttributes(params, region);
|
||||
case "GetIdentityDkimAttributes" -> handleGetIdentityDkimAttributes(params, region);
|
||||
case "CreateTemplate" -> handleCreateTemplate(params, region);
|
||||
case "UpdateTemplate" -> handleUpdateTemplate(params, region);
|
||||
@@ -243,10 +247,13 @@ public class SesQueryHandler {
|
||||
xml.elem("BounceTopic", identity.getNotificationAttributes().getOrDefault("BounceTopic", ""));
|
||||
xml.elem("ComplaintTopic", identity.getNotificationAttributes().getOrDefault("ComplaintTopic", ""));
|
||||
xml.elem("DeliveryTopic", identity.getNotificationAttributes().getOrDefault("DeliveryTopic", ""));
|
||||
xml.elem("ForwardingEnabled", "true");
|
||||
xml.elem("HeadersInBounceNotificationsEnabled", "false");
|
||||
xml.elem("HeadersInComplaintNotificationsEnabled", "false");
|
||||
xml.elem("HeadersInDeliveryNotificationsEnabled", "false");
|
||||
xml.elem("ForwardingEnabled", String.valueOf(identity.isFeedbackForwardingEnabled()));
|
||||
xml.elem("HeadersInBounceNotificationsEnabled",
|
||||
String.valueOf(identity.getHeadersInNotificationsEnabled().getOrDefault("Bounce", false)));
|
||||
xml.elem("HeadersInComplaintNotificationsEnabled",
|
||||
String.valueOf(identity.getHeadersInNotificationsEnabled().getOrDefault("Complaint", false)));
|
||||
xml.elem("HeadersInDeliveryNotificationsEnabled",
|
||||
String.valueOf(identity.getHeadersInNotificationsEnabled().getOrDefault("Delivery", false)));
|
||||
}
|
||||
xml.end("value");
|
||||
xml.end("entry");
|
||||
@@ -274,6 +281,66 @@ public class SesQueryHandler {
|
||||
return Response.ok(AwsQueryResponse.envelope("GetIdentityDkimAttributes", AwsNamespaces.SES, xml.build())).build();
|
||||
}
|
||||
|
||||
private Response handleSetIdentityFeedbackForwardingEnabled(MultivaluedMap<String, String> params, String region) {
|
||||
String identityValue = getParam(params, "Identity");
|
||||
boolean enabled = parseRequiredBoolean(params, "ForwardingEnabled");
|
||||
sesService.setFeedbackForwardingEnabled(identityValue, enabled, region);
|
||||
return Response.ok(AwsQueryResponse.envelopeEmptyResult("SetIdentityFeedbackForwardingEnabled", AwsNamespaces.SES)).build();
|
||||
}
|
||||
|
||||
private Response handleSetIdentityHeadersInNotificationsEnabled(MultivaluedMap<String, String> params, String region) {
|
||||
String identityValue = getParam(params, "Identity");
|
||||
String notificationType = getParam(params, "NotificationType");
|
||||
boolean enabled = parseRequiredBoolean(params, "Enabled");
|
||||
sesService.setHeadersInNotificationsEnabled(identityValue, notificationType, enabled, region);
|
||||
return Response.ok(AwsQueryResponse.envelopeEmptyResult("SetIdentityHeadersInNotificationsEnabled", AwsNamespaces.SES)).build();
|
||||
}
|
||||
|
||||
private Response handleSetIdentityMailFromDomain(MultivaluedMap<String, String> params, String region) {
|
||||
String identityValue = getParam(params, "Identity");
|
||||
String mailFromDomain = getParam(params, "MailFromDomain");
|
||||
if (mailFromDomain == null) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"MailFromDomain is required (use an empty string to clear the existing setting).", 400);
|
||||
}
|
||||
String behaviorOnMxFailure = getParam(params, "BehaviorOnMXFailure");
|
||||
sesService.setMailFromDomain(identityValue, mailFromDomain, behaviorOnMxFailure, region);
|
||||
return Response.ok(AwsQueryResponse.envelopeEmptyResult("SetIdentityMailFromDomain", AwsNamespaces.SES)).build();
|
||||
}
|
||||
|
||||
private static boolean parseRequiredBoolean(MultivaluedMap<String, String> params, String name) {
|
||||
String raw = params.getFirst(name);
|
||||
if (raw == null) {
|
||||
throw new AwsException("InvalidParameterValue", name + " is required.", 400);
|
||||
}
|
||||
if (!"true".equalsIgnoreCase(raw) && !"false".equalsIgnoreCase(raw)) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
name + " must be \"true\" or \"false\".", 400);
|
||||
}
|
||||
return Boolean.parseBoolean(raw);
|
||||
}
|
||||
|
||||
private Response handleGetIdentityMailFromDomainAttributes(MultivaluedMap<String, String> params, String region) {
|
||||
List<String> identities = extractMembers(params, "Identities");
|
||||
var xml = new XmlBuilder().start("MailFromDomainAttributes");
|
||||
for (String identityValue : identities) {
|
||||
Identity identity = sesService.getMailFromAttributes(identityValue, region);
|
||||
xml.start("entry");
|
||||
xml.elem("key", identityValue);
|
||||
xml.start("value");
|
||||
xml.elem("MailFromDomain", identity != null && identity.getMailFromDomain() != null
|
||||
? identity.getMailFromDomain() : "");
|
||||
xml.elem("MailFromDomainStatus", identity != null
|
||||
? identity.getMailFromDomainStatus() : "Pending");
|
||||
xml.elem("BehaviorOnMXFailure", identity != null
|
||||
? identity.getBehaviorOnMxFailure() : "UseDefaultValue");
|
||||
xml.end("value");
|
||||
xml.end("entry");
|
||||
}
|
||||
xml.end("MailFromDomainAttributes");
|
||||
return Response.ok(AwsQueryResponse.envelope("GetIdentityMailFromDomainAttributes", AwsNamespaces.SES, xml.build())).build();
|
||||
}
|
||||
|
||||
// --- Templates ---
|
||||
|
||||
private Response handleCreateTemplate(MultivaluedMap<String, String> params, String region) {
|
||||
|
||||
@@ -238,13 +238,76 @@ public class SesService {
|
||||
public void setFeedbackForwardingEnabled(String identityValue, boolean enabled, String region) {
|
||||
String key = identityKey(region, identityValue);
|
||||
Identity identity = identityStore.get(key)
|
||||
.orElseThrow(() -> new AwsException("NotFoundException",
|
||||
"Identity does not exist: " + identityValue, 404));
|
||||
.orElseThrow(() -> new AwsException("InvalidParameterValue",
|
||||
"Identity " + identityValue
|
||||
+ " is invalid. Must be a verified email address or domain.", 400));
|
||||
identity.setFeedbackForwardingEnabled(enabled);
|
||||
identityStore.put(key, identity);
|
||||
LOG.infov("Updated feedback forwarding for {0}: enabled={1}", identityValue, enabled);
|
||||
}
|
||||
|
||||
public void setMailFromDomain(String identityValue, String mailFromDomain,
|
||||
String behaviorOnMxFailure, String region) {
|
||||
String normalizedBehavior = null;
|
||||
if (behaviorOnMxFailure != null) {
|
||||
if (!"UseDefaultValue".equals(behaviorOnMxFailure)
|
||||
&& !"RejectMessage".equals(behaviorOnMxFailure)) {
|
||||
throw new AwsException("ValidationError",
|
||||
"1 validation error detected: Value at 'behaviorOnMXFailure' failed to satisfy "
|
||||
+ "constraint: Member must satisfy enum value set: [RejectMessage, UseDefaultValue]", 400);
|
||||
}
|
||||
normalizedBehavior = behaviorOnMxFailure;
|
||||
}
|
||||
boolean clearing = mailFromDomain == null || mailFromDomain.isEmpty();
|
||||
if (!clearing && mailFromDomain.isBlank()) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"MailFromDomain must be a domain or an empty string to clear; whitespace is not accepted.", 400);
|
||||
}
|
||||
String key = identityKey(region, identityValue);
|
||||
Identity identity = identityStore.get(key)
|
||||
.orElseThrow(() -> new AwsException("InvalidParameterValue",
|
||||
"Identity <" + identityValue + "> does not exist.", 400));
|
||||
identity.setMailFromDomain(clearing ? null : mailFromDomain);
|
||||
identity.setMailFromDomainStatus(clearing ? "Pending" : "Success");
|
||||
if (normalizedBehavior != null) {
|
||||
identity.setBehaviorOnMxFailure(normalizedBehavior);
|
||||
}
|
||||
identityStore.put(key, identity);
|
||||
LOG.infov("Updated MAIL FROM domain for {0}: domain={1}, behavior={2}",
|
||||
identityValue, mailFromDomain, normalizedBehavior);
|
||||
}
|
||||
|
||||
public Identity getMailFromAttributes(String identityValue, String region) {
|
||||
String key = identityKey(region, identityValue);
|
||||
return identityStore.get(key).orElse(null);
|
||||
}
|
||||
|
||||
private static final java.util.List<String> NOTIFICATION_TYPES =
|
||||
java.util.List.of("Bounce", "Complaint", "Delivery");
|
||||
|
||||
public void setHeadersInNotificationsEnabled(String identityValue, String notificationType,
|
||||
boolean enabled, String region) {
|
||||
if (notificationType == null || notificationType.isBlank()) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"NotificationType is required.", 400);
|
||||
}
|
||||
if (!NOTIFICATION_TYPES.contains(notificationType)) {
|
||||
throw new AwsException("ValidationError",
|
||||
"1 validation error detected: Value at 'notificationType' failed to satisfy "
|
||||
+ "constraint: Member must satisfy enum value set: "
|
||||
+ NOTIFICATION_TYPES, 400);
|
||||
}
|
||||
String key = identityKey(region, identityValue);
|
||||
Identity identity = identityStore.get(key)
|
||||
.orElseThrow(() -> new AwsException("InvalidParameterValue",
|
||||
"Identity " + identityValue
|
||||
+ " is invalid. It must be a verified email address or domain.", 400));
|
||||
identity.getHeadersInNotificationsEnabled().put(notificationType, enabled);
|
||||
identityStore.put(key, identity);
|
||||
LOG.infov("Updated headers-in-notifications for {0}: {1}={2}",
|
||||
identityValue, notificationType, enabled);
|
||||
}
|
||||
|
||||
public List<String> getVerifiedEmailAddresses(String region) {
|
||||
String prefix = "identity::" + region + "::";
|
||||
List<Identity> all = identityStore.scan(k -> k.startsWith(prefix));
|
||||
|
||||
@@ -36,6 +36,18 @@ public class Identity {
|
||||
@JsonProperty("FeedbackForwardingEnabled")
|
||||
private boolean feedbackForwardingEnabled = true;
|
||||
|
||||
@JsonProperty("MailFromDomain")
|
||||
private String mailFromDomain;
|
||||
|
||||
@JsonProperty("BehaviorOnMxFailure")
|
||||
private String behaviorOnMxFailure = "UseDefaultValue";
|
||||
|
||||
@JsonProperty("MailFromDomainStatus")
|
||||
private String mailFromDomainStatus = "Pending";
|
||||
|
||||
@JsonProperty("HeadersInNotificationsEnabled")
|
||||
private Map<String, Boolean> headersInNotificationsEnabled = new HashMap<>();
|
||||
|
||||
@JsonProperty("CreatedAt")
|
||||
private Instant createdAt;
|
||||
|
||||
@@ -75,6 +87,18 @@ public class Identity {
|
||||
public boolean isFeedbackForwardingEnabled() { return feedbackForwardingEnabled; }
|
||||
public void setFeedbackForwardingEnabled(boolean feedbackForwardingEnabled) { this.feedbackForwardingEnabled = feedbackForwardingEnabled; }
|
||||
|
||||
public String getMailFromDomain() { return mailFromDomain; }
|
||||
public void setMailFromDomain(String mailFromDomain) { this.mailFromDomain = mailFromDomain; }
|
||||
|
||||
public String getBehaviorOnMxFailure() { return behaviorOnMxFailure; }
|
||||
public void setBehaviorOnMxFailure(String behaviorOnMxFailure) { this.behaviorOnMxFailure = behaviorOnMxFailure; }
|
||||
|
||||
public String getMailFromDomainStatus() { return mailFromDomainStatus; }
|
||||
public void setMailFromDomainStatus(String mailFromDomainStatus) { this.mailFromDomainStatus = mailFromDomainStatus; }
|
||||
|
||||
public Map<String, Boolean> getHeadersInNotificationsEnabled() { return headersInNotificationsEnabled; }
|
||||
public void setHeadersInNotificationsEnabled(Map<String, Boolean> headersInNotificationsEnabled) { this.headersInNotificationsEnabled = headersInNotificationsEnabled; }
|
||||
|
||||
public Instant getCreatedAt() { return createdAt; }
|
||||
public void setCreatedAt(Instant createdAt) { this.createdAt = createdAt; }
|
||||
}
|
||||
Reference in new issue
Block a user