Light, fluffy, and always free - The AWS Local Emulator alternative
fix(ses): return Easy DKIM signing hosted zone (#5068)
XuJian58ac05433aa7
diff --git a/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java b/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.javaindex e7b3725b46..4a6cb9ec37 100644--- a/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java+++ b/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java@@ -1041,6 +1041,10 @@ public final class TestFixtures {if (tokens == null || tokens.isEmpty()) {throw new IllegalStateException("CreateEmailIdentity did not return DKIM tokens for " + domain);}+ String signingHostedZone = identity.dkimAttributes().signingHostedZone();+ if (signingHostedZone == null || signingHostedZone.isBlank()) {+ throw new IllegalStateException("CreateEmailIdentity did not return SigningHostedZone for " + domain);+ }try (Route53Client route53 = route53Client()) {CreateHostedZoneResponse zone = route53.createHostedZone(CreateHostedZoneRequest.builder()@@ -1056,7 +1060,7 @@ public final class TestFixtures {.type(RRType.CNAME).ttl(300L).resourceRecords(ResourceRecord.builder()- .value(token + ".dkim.amazonses.com")+ .value(token + "." + signingHostedZone).build()).build()).build())diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/SesSigningHostedZoneTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/SesSigningHostedZoneTest.javanew file mode 100644index 0000000000..5437b9808a--- /dev/null+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/SesSigningHostedZoneTest.java@@ -0,0 +1,32 @@+package com.floci.test;++import org.junit.jupiter.api.Test;+import software.amazon.awssdk.services.sesv2.SesV2Client;+import software.amazon.awssdk.services.sesv2.model.CreateEmailIdentityRequest;+import software.amazon.awssdk.services.sesv2.model.CreateEmailIdentityResponse;+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 static org.assertj.core.api.Assertions.assertThat;++class SesSigningHostedZoneTest {++ @Test+ void createAndGetReturnTheSameSigningHostedZone() {+ String domain = TestFixtures.uniqueName("compat-ses-signing-zone") + ".floci.test";+ try (SesV2Client ses = TestFixtures.sesV2Client()) {+ CreateEmailIdentityResponse created = ses.createEmailIdentity(CreateEmailIdentityRequest.builder()+ .emailIdentity(domain).build());+ try {+ assertThat(created.dkimAttributes().signingHostedZone()).isNotBlank();+ GetEmailIdentityResponse fetched = ses.getEmailIdentity(GetEmailIdentityRequest.builder()+ .emailIdentity(domain).build());+ assertThat(fetched.dkimAttributes().signingHostedZone())+ .isEqualTo(created.dkimAttributes().signingHostedZone());+ } finally {+ ses.deleteEmailIdentity(DeleteEmailIdentityRequest.builder().emailIdentity(domain).build());+ }+ }+ }+}diff --git a/docs/services/ses.md b/docs/services/ses.mdindex 9f8c6b2b00..3b5a1f19d2 100644--- a/docs/services/ses.md+++ b/docs/services/ses.md@@ -483,6 +483,14 @@ The contact lists (`ListContactLists`, `ListContacts`), the dedicated-IP lists (DKIM follows AWS's domain-centric model. A **domain** identity carries DKIM tokens (generated at verification, stable across `VerifyDomainDkim` calls); its `DkimVerificationStatus` tracks **DNS record detection** — it transitions to `Success` when the expected `<token>._domainkey.<domain>` CNAMEs are present in the Route53 emulation, not when DKIM is enabled. An **email** identity has no DKIM of its own: its `DkimAttributes` (`SigningEnabled`, `Status`, `Tokens`) are inherited from its parent domain identity when one is registered. The parent is the exact domain after the `@` (verified against AWS): a verified `example.com` covers `[email protected]` but not `[email protected]` unless `mail.example.com` is itself a registered identity. `SetIdentityDkimEnabled` / `PutEmailIdentityDkimAttributes` only toggle the signing flag (they no longer force the verification status); `PutEmailIdentityDkimSigningAttributes` sets the signing origin (`AWS_SES` Easy DKIM — regenerating tokens when the key length changes — or `EXTERNAL` BYODKIM).+SES v2 `CreateEmailIdentity` and `GetEmailIdentity` report `DkimAttributes.SigningHostedZone` for+Easy DKIM identities. Floci reports the fixed emulator value `dkim.amazonses.com`, and+Route53-backed DKIM detection uses that same constant to construct `<token>.<SigningHostedZone>`.+The zone is not identity state or configurable; Floci does not reproduce AWS's region-+and identity-specific hosted-zone assignment. Email identities inherit their registered domain's+DKIM attributes. BYODKIM identities and email identities without a+registered Easy DKIM domain do not report this SES-hosted zone.+S/MIME certificate associations are stored per region and never used: Floci does not sign mail. Associating validates the request as SES does (a domain identity needs a `FromAddress` in the domain or one of its subdomains, one certificate per address regardless of case) but, like SES, does not inspect the certificate. `ListEmailIdentityCertificates` reports `ACTIVE` while the association meets the [S/MIME certificate considerations](https://docs.aws.amazon.com/ses/latest/dg/send-email-authentication-smime.html#send-email-authentication-smime-certificate-considerations), plus the requirements a probe found SES also enforces (an end-entity certificate whose key usage includes `digitalSignature` and whose extended key usage includes `emailProtection`), checked against Floci's ACM and identity verification when the list is read, with the certificate's expiry as `CertificateExpiryTime`, and `FAILED` otherwise. There is no `PROVISIONING` phase, `DisassociateEmailIdentityCertificate` removes an association at once, and the certificate is not listed as in use by ACM. As on SES, `DeleteEmailIdentity` refuses an identity that still has a certificate associated, whatever its status. The v1 `DeleteIdentity` and `DeleteVerifiedEmailAddress` share the identities and refuse it too, with the same `BadRequestException` the tenant-association guard returns there; SES's v1 behaviour was not probed.### IAM enforcementdiff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityController.javaindex c9f1f27d31..fa8fcc0308 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityController.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityController.java@@ -579,6 +579,10 @@ public class SesIdentityController {tokens.add(token);}}+ if ("Domain".equals(src.getIdentityType()) && "AWS_SES".equals(src.getDkimSigningAttributesOrigin())+ && !tokens.isEmpty()) {+ dkim.put("SigningHostedZone", SesIdentityService.DKIM_SIGNING_HOSTED_ZONE);+ }dkim.put("SigningAttributesOrigin", src.getDkimSigningAttributesOrigin());dkim.put("NextSigningKeyLength", src.getDkimNextSigningKeyLength());dkim.put("CurrentSigningKeyLength", src.getDkimCurrentSigningKeyLength());diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityService.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityService.javaindex e0cef100d3..5800a619b9 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityService.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityService.java@@ -45,6 +45,8 @@ import java.util.concurrent.ConcurrentHashMap;@ApplicationScopedpublic class SesIdentityService implements SesTaggable {+ static final String DKIM_SIGNING_HOSTED_ZONE = "dkim.amazonses.com";+private static final Logger LOG = Logger.getLogger(SesIdentityService.class);private static final Duration DKIM_LOOKUP_CACHE_TTL = Duration.ofSeconds(5);@@ -714,7 +716,7 @@ public class SesIdentityService implements SesTaggable {private boolean hasExpectedDkimRecord(String domain, String token) {String expectedName = normalizeDnsName(token + "._domainkey." + domain);- String expectedValue = normalizeDnsName(token + ".dkim.amazonses.com");+ String expectedValue = normalizeDnsName(token + "." + DKIM_SIGNING_HOSTED_ZONE);for (HostedZone zone : route53Service.listHostedZones(null, Integer.MAX_VALUE)) {for (ResourceRecordSet recordSet : route53Service.listResourceRecordSets(zone.getId(), null, null,Integer.MAX_VALUE)) {diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesDkimSigningActionsIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesDkimSigningActionsIntegrationTest.javaindex dcbe1cd488..88a759e91b 100644--- a/src/test/java/io/github/hectorvent/floci/services/ses/SesDkimSigningActionsIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesDkimSigningActionsIntegrationTest.java@@ -12,6 +12,7 @@ import static org.hamcrest.Matchers.containsString;import static org.hamcrest.Matchers.equalTo;import static org.hamcrest.Matchers.hasSize;import static org.hamcrest.Matchers.not;+import static org.hamcrest.Matchers.nullValue;import static org.junit.jupiter.api.Assertions.assertEquals;import static org.junit.jupiter.api.Assertions.assertNotEquals;@@ -96,6 +97,7 @@ class SesDkimSigningActionsIntegrationTest {given().header("Authorization", V2_AUTH).when().get("/v2/email/identities/" + domain).then().statusCode(200).body("DkimAttributes.CurrentSigningKeyLength", equalTo("RSA_1024_BIT"))+ .body("DkimAttributes.SigningHostedZone", equalTo("dkim.amazonses.com")).body("DkimAttributes.Tokens", equalTo(after));}@@ -197,6 +199,7 @@ class SesDkimSigningActionsIntegrationTest {.when().get("/v2/email/identities/" + domain).then().statusCode(200).body("DkimAttributes.Status", equalTo("PENDING")).body("DkimAttributes.SigningAttributesOrigin", equalTo("EXTERNAL"))+ .body("DkimAttributes.SigningHostedZone", nullValue()).body("DkimAttributes.Tokens", hasSize(0));}@@ -248,6 +251,7 @@ class SesDkimSigningActionsIntegrationTest {.when().get("/v2/email/identities/bob@" + domain).then().statusCode(200).body("DkimAttributes.SigningEnabled", equalTo(true)).body("DkimAttributes.Status", equalTo("PENDING"))+ .body("DkimAttributes.SigningHostedZone", equalTo("dkim.amazonses.com")).body("DkimAttributes.Tokens", equalTo(domainTokens)).body("DkimAttributes.Tokens", not(hasSize(0)));}diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesIdentityAttributesV2IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesIdentityAttributesV2IntegrationTest.javaindex ff7adf7618..5a84fc037e 100644--- a/src/test/java/io/github/hectorvent/floci/services/ses/SesIdentityAttributesV2IntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesIdentityAttributesV2IntegrationTest.java@@ -30,7 +30,8 @@ class SesIdentityAttributesV2IntegrationTest {.when().post("/v2/email/identities").then()- .statusCode(200);+ .statusCode(200)+ .body("DkimAttributes.SigningHostedZone", equalTo("dkim.amazonses.com"));// With no MAIL FROM domain configured, AWS keeps the MailFromAttributes// block carrying only BehaviorOnMxFailure and omits the inner@@ -41,6 +42,7 @@ class SesIdentityAttributesV2IntegrationTest {.get("/v2/email/identities/v2-attrs.floci.test").then().statusCode(200)+ .body("DkimAttributes.SigningHostedZone", equalTo("dkim.amazonses.com")).body("MailFromAttributes.BehaviorOnMxFailure", equalTo("USE_DEFAULT_VALUE")).body("MailFromAttributes.MailFromDomain", nullValue()).body("MailFromAttributes.MailFromDomainStatus", nullValue());diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesIdentityDkimLookupCacheTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesIdentityDkimLookupCacheTest.javaindex 8222075c80..bf4d3ac01a 100644--- a/src/test/java/io/github/hectorvent/floci/services/ses/SesIdentityDkimLookupCacheTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesIdentityDkimLookupCacheTest.java@@ -102,6 +102,15 @@ class SesIdentityDkimLookupCacheTest {verify(route53Service, times(4)).listResourceRecordSets(eq("zone-1"), eq(null), eq(null), eq(Integer.MAX_VALUE));}+ @Test+ void dnsDetectionUsesTheReportedSigningHostedZone() {+ Identity identity = storePendingDomainIdentity();+ stubRoute53(identity, buildMatchingRecords(identity));++ assertEquals("Success", identities.getIdentityVerificationAttributes(DOMAIN, REGION)+ .getDkimVerificationStatus());+ }+private Identity storePendingDomainIdentity() {Identity identity = new Identity(DOMAIN, "Domain");identity.setVerificationStatus("Pending");