From efc9453fd71a0e9187ffb9d63d1b685bd609856a Mon Sep 17 00:00:00 2001 From: Kenshin Okinaka Date: Fri, 10 Jul 2026 13:54:43 +0900 Subject: [PATCH] fix(ses): populate VerificationStatus in v2 ListEmailIdentities (#1722) * fix(ses): populate VerificationStatus in v2 ListEmailIdentities ListEmailIdentities built each item with only IdentityType / IdentityName / SendingEnabled, so VerificationStatus always serialized as null and clients had to call GetEmailIdentity per identity. Populate it from the identity's stored status (mapped to the v2 enum via toV2Status), and refresh each identity's state the same way GetEmailIdentity does so the list stays consistent (e.g. a domain that transitioned to SUCCESS via its DKIM records). * fix(ses): derive SendingEnabled from verification status in v2 ListEmailIdentities SendingEnabled was hard-coded to true, so a not-yet-verified identity was reported as sendable, which is inconsistent now that VerificationStatus is populated. AWS returns SendingEnabled=true only when the identity is verified (VerificationStatus SUCCESS) and false otherwise (PENDING/FAILED), matching the VerifiedForSendingStatus logic already used by GetEmailIdentity. Derive it the same way here. --- .../floci/test/SesIdentityAttributesTest.java | 31 +++++++++++++++++++ .../floci/services/ses/SesController.java | 16 ++++++++-- .../services/ses/SesV2IntegrationTest.java | 13 +++++++- 3 files changed, 56 insertions(+), 4 deletions(-) diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/SesIdentityAttributesTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/SesIdentityAttributesTest.java index dd9d706629..122c137522 100644 --- a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/SesIdentityAttributesTest.java +++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/SesIdentityAttributesTest.java @@ -28,7 +28,12 @@ import software.amazon.awssdk.services.sesv2.model.CreateEmailIdentityRequest; import software.amazon.awssdk.services.sesv2.model.DeleteEmailIdentityRequest; import software.amazon.awssdk.services.sesv2.model.GetEmailIdentityRequest; import software.amazon.awssdk.services.sesv2.model.GetEmailIdentityResponse; +import software.amazon.awssdk.services.sesv2.model.IdentityInfo; +import software.amazon.awssdk.services.sesv2.model.ListEmailIdentitiesRequest; import software.amazon.awssdk.services.sesv2.model.PutEmailIdentityMailFromAttributesRequest; +import software.amazon.awssdk.services.sesv2.model.VerificationStatus; + +import java.util.List; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -167,4 +172,30 @@ class SesIdentityAttributesTest { .extracting(e -> ((AwsServiceException) e).statusCode()) .isEqualTo(400); } + + @Test + @Order(12) + void listEmailIdentities_populatesVerificationStatus() { + String email = TestFixtures.uniqueName("lei") + "@example.com"; + String domain = TestFixtures.uniqueName("lei") + ".example.com"; + sesV2.createEmailIdentity(CreateEmailIdentityRequest.builder().emailIdentity(email).build()); + sesV2.createEmailIdentity(CreateEmailIdentityRequest.builder().emailIdentity(domain).build()); + try { + List identities = sesV2.listEmailIdentities( + ListEmailIdentitiesRequest.builder().build()).emailIdentities(); + IdentityInfo emailIdentity = identities.stream() + .filter(i -> email.equals(i.identityName())).findFirst().orElseThrow(); + IdentityInfo domainIdentity = identities.stream() + .filter(i -> domain.equals(i.identityName())).findFirst().orElseThrow(); + // Regression: VerificationStatus used to be null in the list response. + assertThat(emailIdentity.verificationStatus()).isEqualTo(VerificationStatus.SUCCESS); + assertThat(domainIdentity.verificationStatus()).isEqualTo(VerificationStatus.PENDING); + // SendingEnabled tracks verification status on AWS: SUCCESS -> true, PENDING -> false. + assertThat(emailIdentity.sendingEnabled()).isTrue(); + assertThat(domainIdentity.sendingEnabled()).isFalse(); + } finally { + sesV2.deleteEmailIdentity(DeleteEmailIdentityRequest.builder().emailIdentity(email).build()); + sesV2.deleteEmailIdentity(DeleteEmailIdentityRequest.builder().emailIdentity(domain).build()); + } + } } diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesController.java index 22c149a996..14529eab89 100644 --- a/src/main/java/io/github/hectorvent/floci/services/ses/SesController.java +++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesController.java @@ -127,10 +127,20 @@ public class SesController { ObjectNode result = objectMapper.createObjectNode(); ArrayNode items = result.putArray("EmailIdentities"); for (Identity id : identities) { + // Only a not-yet-verified domain can still transition (via its DKIM records), + // so refresh just those; refreshing every identity would scan Route53 per call. + Identity current = id; + if ("Domain".equals(id.getIdentityType()) && !"Success".equals(id.getVerificationStatus())) { + Identity refreshed = sesService.getIdentityVerificationAttributes(id.getIdentity(), region); + if (refreshed != null) { + current = refreshed; + } + } ObjectNode item = objectMapper.createObjectNode(); - item.put("IdentityType", toV2IdentityType(id.getIdentityType())); - item.put("IdentityName", id.getIdentity()); - item.put("SendingEnabled", true); + item.put("IdentityType", toV2IdentityType(current.getIdentityType())); + item.put("IdentityName", current.getIdentity()); + item.put("SendingEnabled", "Success".equals(current.getVerificationStatus())); + item.put("VerificationStatus", toV2Status(current.getVerificationStatus())); items.add(item); } return Response.ok(result).build(); diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesV2IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesV2IntegrationTest.java index 29aaec4afc..ffcca1bb04 100644 --- a/src/test/java/io/github/hectorvent/floci/services/ses/SesV2IntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesV2IntegrationTest.java @@ -85,7 +85,18 @@ class SesV2IntegrationTest { .body("EmailIdentities", notNullValue()) .body("EmailIdentities.size()", greaterThanOrEqualTo(2)) .body("EmailIdentities.IdentityName", hasItem("v2sender@example.com")) - .body("EmailIdentities.IdentityName", hasItem("v2example.com")); + .body("EmailIdentities.IdentityName", hasItem("v2example.com")) + // VerificationStatus must be populated per identity (never null), matching AWS. + .body("EmailIdentities.VerificationStatus", everyItem(notNullValue())) + .body("EmailIdentities.find { it.IdentityName == 'v2sender@example.com' }.VerificationStatus", + equalTo("SUCCESS")) + .body("EmailIdentities.find { it.IdentityName == 'v2example.com' }.VerificationStatus", + equalTo("PENDING")) + // SendingEnabled tracks verification: SUCCESS -> true, PENDING -> false (matches AWS). + .body("EmailIdentities.find { it.IdentityName == 'v2sender@example.com' }.SendingEnabled", + equalTo(true)) + .body("EmailIdentities.find { it.IdentityName == 'v2example.com' }.SendingEnabled", + equalTo(false)); } @Test