diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesQueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesQueryHandler.java index 678ce465e9..abadf99914 100644 --- a/src/main/java/io/github/hectorvent/floci/services/ses/SesQueryHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesQueryHandler.java @@ -267,21 +267,22 @@ public class SesQueryHandler { var xml = new XmlBuilder().start("NotificationAttributes"); for (String identityValue : identities) { Identity identity = sesService.getIdentityNotificationAttributes(identityValue, region); + if (identity == null) { + continue; + } xml.start("entry"); xml.elem("key", identityValue); xml.start("value"); - if (identity != null) { - xml.elem("BounceTopic", identity.getNotificationAttributes().getOrDefault("BounceTopic", "")); - xml.elem("ComplaintTopic", identity.getNotificationAttributes().getOrDefault("ComplaintTopic", "")); - xml.elem("DeliveryTopic", identity.getNotificationAttributes().getOrDefault("DeliveryTopic", "")); - 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.elem("BounceTopic", identity.getNotificationAttributes().getOrDefault("BounceTopic", "")); + xml.elem("ComplaintTopic", identity.getNotificationAttributes().getOrDefault("ComplaintTopic", "")); + xml.elem("DeliveryTopic", identity.getNotificationAttributes().getOrDefault("DeliveryTopic", "")); + 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"); } diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesIdentityAttributesV1IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesIdentityAttributesV1IntegrationTest.java index 9c711cc80a..595b6510d9 100644 --- a/src/test/java/io/github/hectorvent/floci/services/ses/SesIdentityAttributesV1IntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesIdentityAttributesV1IntegrationTest.java @@ -8,6 +8,7 @@ import org.junit.jupiter.api.TestMethodOrder; import static io.restassured.RestAssured.given; import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.not; @QuarkusTest @TestMethodOrder(MethodOrderer.OrderAnnotation.class) @@ -327,4 +328,42 @@ class SesIdentityAttributesV1IntegrationTest { .body(containsString("false")) .body(containsString("false")); } + + @Test + @Order(22) + void getIdentityNotificationAttributes_unknownIdentity_omittedFromMap() { + // Real AWS returns an empty NotificationAttributes map for an identity + // that doesn't exist, rather than an entry with empty values + // (verified against real AWS SES on 2026-06-13). + given() + .contentType("application/x-www-form-urlencoded") + .header("Authorization", AUTH) + .formParam("Action", "GetIdentityNotificationAttributes") + .formParam("Identities.member.1", "ghost-notif.floci.test") + .when() + .post("/") + .then() + .statusCode(200) + .body(containsString("GetIdentityNotificationAttributesResponse")) + .body(containsString("")) + .body(not(containsString("ghost-notif.floci.test"))); + } + + @Test + @Order(23) + void getIdentityNotificationAttributes_mixedKnownAndUnknown_returnsOnlyKnown() { + // The unknown identity is dropped from the map; the known one stays. + given() + .contentType("application/x-www-form-urlencoded") + .header("Authorization", AUTH) + .formParam("Action", "GetIdentityNotificationAttributes") + .formParam("Identities.member.1", "v1-attrs.floci.test") + .formParam("Identities.member.2", "ghost-notif2.floci.test") + .when() + .post("/") + .then() + .statusCode(200) + .body(containsString("v1-attrs.floci.test")) + .body(not(containsString("ghost-notif2.floci.test"))); + } }