mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(ses): add DKIM actions with domain-inherited email DKIM (#1904)
* feat(ses): add DKIM actions with domain-inherited email DKIM
Adds three DKIM actions and aligns DKIM status with AWS:
- v1 SetIdentityDkimEnabled: toggles the signing flag only (unknown identity ->
InvalidParameterValue).
- v1 VerifyDomainDkim: returns a domain's three DKIM CNAME tokens (stable across
calls), registering the domain as pending if absent.
- v2 PutEmailIdentityDkimSigningAttributes (PUT .../dkim/signing): sets the
signing origin (AWS_SES Easy DKIM, regenerating tokens when the key length
changes; EXTERNAL BYODKIM), returning DkimStatus + DkimTokens.
DkimVerificationStatus now tracks DNS record detection (via the Route53 lookup
in refreshIdentityState) rather than the enabled flag, so setDkimAttributes no
longer forces the status; the v1-native InvalidParameterValue is remapped to
BadRequestException on the v2 path. An email identity inherits its parent
domain's DKIM (SigningEnabled/Status/Tokens), matching AWS. Adds the
SigningAttributesOrigin / signing key length / last-key-generation fields to the
DkimAttributes response (LastKeyGenerationTimestamp is emitted as epoch seconds,
matching the SES v2 wire format).
Includes an AWS Java SDK compatibility test that exercises all three actions and
the email-inherits-domain behavior end-to-end.
* fix(ses): decouple DKIM status from signing flag and reject DKIM signing on email identities
- refreshIdentityState no longer gates the DkimVerificationStatus -> Success
transition on isDkimEnabled(), so a domain with the expected CNAMEs reaches
Success even when DKIM signing is disabled (status tracks DNS detection).
- putDkimSigningAttributes now rejects an email-address identity with
BadRequestException ("The EmailIdentity value must be a valid domain."),
matching real AWS — previously it mutated state the email would just inherit
back from its parent domain on every read.
* fix(ses): report domain DKIM as NotStarted on create, Pending on read
CreateEmailIdentity now returns DkimAttributes.Status=NOT_STARTED for a new
domain (SES has not begun tracking the CNAMEs yet); the first GetEmailIdentity
/ ListEmailIdentities refresh transitions it to PENDING, matching AWS. The
signing-enabled flag no longer gates the NotStarted->Pending transition, so a
disabled domain still reports PENDING on read.
* fix(ses): reject blank identity on PutEmailIdentityDkimSigningAttributes with a 400
A blank or whitespace EmailIdentity fell through to a NotFoundException (404) instead
of the validation error AWS returns. AWS rejects a missing/blank value with the same
400 "The EmailIdentity value must be a valid domain." as an email-shaped identity
(verified), so extend the guard to also cover null/blank.
* docs(ses): clarify DKIM inheritance is from the exact parent domain
An email inherits DKIM only from an exactly-matching registered parent domain, not from a
verified ancestor — a verified example.com does not cover user@mail.example.com unless
mail.example.com is itself registered (verified against AWS). Note this in the DKIM
paragraph so "parent domain identity when one is registered" isn't read as ancestor coverage.
This commit is contained in:
1 parent
5afb60d0f5
commit
ff0201a13a
10 files changed
+739
-47
No files matched your search
+254
@@ -0,0 +1,254 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.XmlParser;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
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.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
/**
|
||||
* Integration tests for the DKIM actions: v1 {@code VerifyDomainDkim} / {@code SetIdentityDkimEnabled}
|
||||
* and v2 {@code PutEmailIdentityDkimSigningAttributes}, plus the email-inherits-parent-domain DKIM
|
||||
* behavior. Verified against real AWS (tokens stable on VerifyDomainDkim; email DKIM mirrors the
|
||||
* parent domain; DKIM status tracks DNS detection, not the enabled flag).
|
||||
*/
|
||||
@QuarkusTest
|
||||
class SesDkimSigningActionsIntegrationTest {
|
||||
|
||||
private static final String V1_AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/email/aws4_request";
|
||||
private static final String V2_AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/ses/aws4_request";
|
||||
|
||||
private io.restassured.specification.RequestSpecification v1(String action) {
|
||||
return given().contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", V1_AUTH).formParam("Action", action);
|
||||
}
|
||||
|
||||
@Test
|
||||
void verifyDomainDkim_returnsThreeStableTokens_andRegistersDomain() {
|
||||
String domain = "dkim-verify.floci.test";
|
||||
List<String> first = XmlParser.extractAll(v1("VerifyDomainDkim").formParam("Domain", domain)
|
||||
.when().post("/").then().statusCode(200).extract().asString(), "member");
|
||||
assertEquals(3, first.size());
|
||||
|
||||
// Stable across calls (AWS does not regenerate).
|
||||
List<String> second = XmlParser.extractAll(v1("VerifyDomainDkim").formParam("Domain", domain)
|
||||
.when().post("/").then().statusCode(200).extract().asString(), "member");
|
||||
assertEquals(first, second);
|
||||
|
||||
// The domain is now a DKIM identity, visible via GetIdentityDkimAttributes.
|
||||
v1("GetIdentityDkimAttributes").formParam("Identities.member.1", domain)
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body(containsString("<key>" + domain + "</key>"))
|
||||
.body(containsString("<DkimEnabled>true</DkimEnabled>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void setIdentityDkimEnabled_togglesFlag_andUnknownIdentityErrors() {
|
||||
String domain = "dkim-toggle.floci.test";
|
||||
v1("VerifyDomainIdentity").formParam("Domain", domain).when().post("/").then().statusCode(200);
|
||||
|
||||
v1("SetIdentityDkimEnabled").formParam("Identity", domain).formParam("DkimEnabled", "false")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body(containsString("SetIdentityDkimEnabledResponse"));
|
||||
|
||||
v1("GetIdentityDkimAttributes").formParam("Identities.member.1", domain)
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body(containsString("<DkimEnabled>false</DkimEnabled>"));
|
||||
|
||||
// Unknown identity -> v1-native InvalidParameterValue.
|
||||
v1("SetIdentityDkimEnabled").formParam("Identity", "unknown-dkim.floci.test")
|
||||
.formParam("DkimEnabled", "true")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>InvalidParameterValue</Code>"))
|
||||
.body(containsString("is not verified for DKIM signing."));
|
||||
}
|
||||
|
||||
@Test
|
||||
void putDkimSigningAttributes_awsSes_regeneratesTokensOnKeyLengthChange() {
|
||||
String domain = "dkim-signing.floci.test";
|
||||
List<String> before = given().contentType("application/json").header("Authorization", V2_AUTH)
|
||||
.body("{\"EmailIdentity\":\"" + domain + "\"}")
|
||||
.when().post("/v2/email/identities").then().statusCode(200)
|
||||
.extract().path("DkimAttributes.Tokens");
|
||||
|
||||
// Change the key length (default is RSA_2048_BIT) -> tokens regenerate.
|
||||
Response resp = given().contentType("application/json").header("Authorization", V2_AUTH)
|
||||
.body("{\"SigningAttributesOrigin\":\"AWS_SES\","
|
||||
+ "\"SigningAttributes\":{\"NextSigningKeyLength\":\"RSA_1024_BIT\"}}")
|
||||
.when().put("/v2/email/identities/" + domain + "/dkim/signing").then().statusCode(200)
|
||||
.body("DkimTokens", hasSize(3))
|
||||
// Regenerated tokens reset the status: the new CNAMEs are not yet detected in DNS.
|
||||
.body("DkimStatus", equalTo("PENDING")).extract().response();
|
||||
List<String> after = resp.path("DkimTokens");
|
||||
assertNotEquals(before, after, "changing the key length must regenerate the tokens");
|
||||
|
||||
given().header("Authorization", V2_AUTH)
|
||||
.when().get("/v2/email/identities/" + domain).then().statusCode(200)
|
||||
.body("DkimAttributes.CurrentSigningKeyLength", equalTo("RSA_1024_BIT"))
|
||||
.body("DkimAttributes.Tokens", equalTo(after));
|
||||
}
|
||||
|
||||
@Test
|
||||
void putDkimSigningAttributes_emailIdentity_returns400() {
|
||||
// DKIM signing attributes are domain-level; an email-shaped identity is rejected.
|
||||
given().contentType("application/json").header("Authorization", V2_AUTH)
|
||||
.body("{\"SigningAttributesOrigin\":\"AWS_SES\"}")
|
||||
.when().put("/v2/email/identities/bob@dkim-emailsigning.floci.test/dkim/signing")
|
||||
.then().statusCode(400).body("__type", equalTo("BadRequestException"))
|
||||
.body("message", equalTo("The EmailIdentity value must be a valid domain."));
|
||||
}
|
||||
|
||||
@Test
|
||||
void putDkimSigningAttributes_blankIdentity_returns400() {
|
||||
// A blank/whitespace identity is rejected with the same 400 "must be a valid domain" as an
|
||||
// email-shaped one (verified against AWS), rather than falling through to a 404.
|
||||
given().urlEncodingEnabled(false).contentType("application/json").header("Authorization", V2_AUTH)
|
||||
.body("{\"SigningAttributesOrigin\":\"AWS_SES\"}")
|
||||
.when().put("/v2/email/identities/%20/dkim/signing")
|
||||
.then().statusCode(400).body("__type", equalTo("BadRequestException"))
|
||||
.body("message", equalTo("The EmailIdentity value must be a valid domain."));
|
||||
}
|
||||
|
||||
@Test
|
||||
void putDkimSigningAttributes_unknownIdentity_returns404() {
|
||||
given().contentType("application/json").header("Authorization", V2_AUTH)
|
||||
.body("{\"SigningAttributesOrigin\":\"AWS_SES\"}")
|
||||
.when().put("/v2/email/identities/ghost-signing.floci.test/dkim/signing")
|
||||
.then().statusCode(404).body("__type", equalTo("NotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void putDkimSigningAttributes_externalWithBlankPrivateKey_returns400() {
|
||||
String domain = "dkim-external.floci.test";
|
||||
given().contentType("application/json").header("Authorization", V2_AUTH)
|
||||
.body("{\"EmailIdentity\":\"" + domain + "\"}")
|
||||
.when().post("/v2/email/identities").then().statusCode(200);
|
||||
|
||||
given().contentType("application/json").header("Authorization", V2_AUTH)
|
||||
.body("{\"SigningAttributesOrigin\":\"EXTERNAL\",\"SigningAttributes\":"
|
||||
+ "{\"DomainSigningSelector\":\"sel\",\"DomainSigningPrivateKey\":\"\"}}")
|
||||
.when().put("/v2/email/identities/" + domain + "/dkim/signing")
|
||||
.then().statusCode(400).body("__type", equalTo("BadRequestException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void setIdentityDkimEnabled_missingIdentity_returns400() {
|
||||
v1("SetIdentityDkimEnabled").formParam("DkimEnabled", "true")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>InvalidParameterValue</Code>"))
|
||||
.body(containsString("Identity is required."));
|
||||
}
|
||||
|
||||
@Test
|
||||
void verifyDomainDkim_whitespaceDomain_returns400() {
|
||||
v1("VerifyDomainDkim").formParam("Domain", " dkim-ws.floci.test")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>InvalidParameterValue</Code>"))
|
||||
.body(containsString("whitespace"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void verifyDomainDkim_emailShapedInput_returns400() {
|
||||
v1("VerifyDomainDkim").formParam("Domain", "bob@dkim-bad.floci.test")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>InvalidParameterValue</Code>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void putDkimSigningAttributes_invalidKeyLength_returns400() {
|
||||
String domain = "dkim-badkeylen.floci.test";
|
||||
given().contentType("application/json").header("Authorization", V2_AUTH)
|
||||
.body("{\"EmailIdentity\":\"" + domain + "\"}")
|
||||
.when().post("/v2/email/identities").then().statusCode(200);
|
||||
|
||||
given().contentType("application/json").header("Authorization", V2_AUTH)
|
||||
.body("{\"SigningAttributesOrigin\":\"AWS_SES\","
|
||||
+ "\"SigningAttributes\":{\"NextSigningKeyLength\":\"RSA_4096_BIT\"}}")
|
||||
.when().put("/v2/email/identities/" + domain + "/dkim/signing")
|
||||
.then().statusCode(400).body("__type", equalTo("BadRequestException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void putDkimSigningAttributes_external_clearsTokensAndResetsStatusToPending() {
|
||||
String domain = "dkim-byodkim.floci.test";
|
||||
given().contentType("application/json").header("Authorization", V2_AUTH)
|
||||
.body("{\"EmailIdentity\":\"" + domain + "\"}")
|
||||
.when().post("/v2/email/identities").then().statusCode(200);
|
||||
|
||||
given().contentType("application/json").header("Authorization", V2_AUTH)
|
||||
.body("{\"SigningAttributesOrigin\":\"EXTERNAL\",\"SigningAttributes\":"
|
||||
+ "{\"DomainSigningSelector\":\"sel\",\"DomainSigningPrivateKey\":\"key\"}}")
|
||||
.when().put("/v2/email/identities/" + domain + "/dkim/signing").then().statusCode(200)
|
||||
.body("DkimStatus", equalTo("PENDING"))
|
||||
.body("DkimTokens", hasSize(0));
|
||||
|
||||
given().header("Authorization", V2_AUTH)
|
||||
.when().get("/v2/email/identities/" + domain).then().statusCode(200)
|
||||
.body("DkimAttributes.Status", equalTo("PENDING"))
|
||||
.body("DkimAttributes.SigningAttributesOrigin", equalTo("EXTERNAL"))
|
||||
.body("DkimAttributes.Tokens", hasSize(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void putDkimSigningAttributes_nonObjectBody_returns400() {
|
||||
given().contentType("application/json").header("Authorization", V2_AUTH).body("[]")
|
||||
.when().put("/v2/email/identities/dkim-nonobj.floci.test/dkim/signing")
|
||||
.then().statusCode(400).body("__type", equalTo("BadRequestException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void putEmailIdentityDkimAttributes_existingEmailWithRegisteredDomain_isNoOp() {
|
||||
String domain = "dkim-emailtoggle.floci.test";
|
||||
given().contentType("application/json").header("Authorization", V2_AUTH)
|
||||
.body("{\"EmailIdentity\":\"" + domain + "\"}")
|
||||
.when().post("/v2/email/identities").then().statusCode(200);
|
||||
given().contentType("application/json").header("Authorization", V2_AUTH)
|
||||
.body("{\"EmailIdentity\":\"bob@" + domain + "\"}")
|
||||
.when().post("/v2/email/identities").then().statusCode(200);
|
||||
|
||||
// Toggling DKIM on the email is a no-op (DKIM is domain-controlled) — 200, nothing changes.
|
||||
given().contentType("application/json").header("Authorization", V2_AUTH)
|
||||
.body("{\"SigningEnabled\": false}")
|
||||
.when().put("/v2/email/identities/bob@" + domain + "/dkim").then().statusCode(200);
|
||||
|
||||
// The email still reports the domain's DKIM (enabled), and the domain is untouched.
|
||||
given().header("Authorization", V2_AUTH)
|
||||
.when().get("/v2/email/identities/bob@" + domain).then().statusCode(200)
|
||||
.body("DkimAttributes.SigningEnabled", equalTo(true));
|
||||
given().header("Authorization", V2_AUTH)
|
||||
.when().get("/v2/email/identities/" + domain).then().statusCode(200)
|
||||
.body("DkimAttributes.SigningEnabled", equalTo(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
void emailIdentity_inheritsParentDomainDkim() {
|
||||
String domain = "dkim-inherit.floci.test";
|
||||
List<String> domainTokens = given().contentType("application/json").header("Authorization", V2_AUTH)
|
||||
.body("{\"EmailIdentity\":\"" + domain + "\"}")
|
||||
.when().post("/v2/email/identities").then().statusCode(200)
|
||||
.extract().path("DkimAttributes.Tokens");
|
||||
|
||||
// An email under that domain inherits the domain's DKIM (tokens, enabled, pending status).
|
||||
given().contentType("application/json").header("Authorization", V2_AUTH)
|
||||
.body("{\"EmailIdentity\":\"bob@" + domain + "\"}")
|
||||
.when().post("/v2/email/identities").then().statusCode(200);
|
||||
|
||||
given().header("Authorization", V2_AUTH)
|
||||
.when().get("/v2/email/identities/bob@" + domain).then().statusCode(200)
|
||||
.body("DkimAttributes.SigningEnabled", equalTo(true))
|
||||
.body("DkimAttributes.Status", equalTo("PENDING"))
|
||||
.body("DkimAttributes.Tokens", equalTo(domainTokens))
|
||||
.body("DkimAttributes.Tokens", not(hasSize(0)));
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -78,7 +78,9 @@ class SesServiceLegacyDkimTokensTest {
|
||||
assertTrue(refreshed.getDkimTokens().stream().allMatch(token -> token != null && !token.isBlank()));
|
||||
assertEquals("Pending", refreshed.getVerificationStatus());
|
||||
assertFalse(refreshed.isDkimEnabled());
|
||||
assertEquals("NotStarted", refreshed.getDkimVerificationStatus());
|
||||
// Once tokens are backfilled the domain is pending DNS detection (status tracks detection, not
|
||||
// the signing flag), rather than staying NotStarted.
|
||||
assertEquals("Pending", refreshed.getDkimVerificationStatus());
|
||||
|
||||
List<String> persistedTokens = identityStore.get(key).orElseThrow().getDkimTokens();
|
||||
assertNotNull(persistedTokens);
|
||||
|
||||
@@ -54,8 +54,19 @@ class SesV2IntegrationTest {
|
||||
.body("IdentityType", equalTo("DOMAIN"))
|
||||
.body("VerifiedForSendingStatus", equalTo(false))
|
||||
.body("DkimAttributes.SigningEnabled", equalTo(true))
|
||||
.body("DkimAttributes.Status", equalTo("PENDING"))
|
||||
// CreateEmailIdentity reports NOT_STARTED (SES hasn't begun tracking the CNAMEs yet).
|
||||
.body("DkimAttributes.Status", equalTo("NOT_STARTED"))
|
||||
.body("DkimAttributes.Tokens", not(empty()));
|
||||
|
||||
// A subsequent GetEmailIdentity transitions the DKIM status to PENDING, matching AWS.
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.get("/v2/email/identities/v2example.com")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DkimAttributes.Status", equalTo("PENDING"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -199,6 +210,64 @@ class SesV2IntegrationTest {
|
||||
.body("DkimAttributes.SigningEnabled", equalTo(true))
|
||||
.body("DkimAttributes.Status", equalTo("SUCCESS"))
|
||||
.body("DkimAttributes.Tokens", not(empty()));
|
||||
|
||||
// DKIM verification status tracks DNS detection independently of the signing flag: disabling
|
||||
// DKIM keeps Status=SUCCESS while the CNAMEs remain published.
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"SigningEnabled": false}
|
||||
""")
|
||||
.when()
|
||||
.put("/v2/email/identities/v2dkim-success.floci.test/dkim")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.get("/v2/email/identities/v2dkim-success.floci.test")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DkimAttributes.SigningEnabled", equalTo(false))
|
||||
.body("DkimAttributes.Status", equalTo("SUCCESS"));
|
||||
|
||||
// Re-enable so the key-rotation assertion below starts from the signing-enabled state.
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"SigningEnabled": true}
|
||||
""")
|
||||
.when()
|
||||
.put("/v2/email/identities/v2dkim-success.floci.test/dkim")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
// Rotating the DKIM key must not revoke the identity's sending verification (matching AWS):
|
||||
// VerificationStatus stays SUCCESS, but DKIM re-pends until the new tokens' records are detected.
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"SigningAttributesOrigin":"AWS_SES","SigningAttributes":{"NextSigningKeyLength":"RSA_1024_BIT"}}
|
||||
""")
|
||||
.when()
|
||||
.put("/v2/email/identities/v2dkim-success.floci.test/dkim/signing")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.get("/v2/email/identities/v2dkim-success.floci.test")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("VerificationStatus", equalTo("SUCCESS"))
|
||||
.body("DkimAttributes.Status", equalTo("PENDING"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -519,7 +588,9 @@ class SesV2IntegrationTest {
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DkimAttributes.SigningEnabled", equalTo(true))
|
||||
.body("DkimAttributes.Status", equalTo("SUCCESS"));
|
||||
// example.com is not a DKIM-verified domain identity, so the enabled flag is set but the
|
||||
// DKIM verification status stays NOT_STARTED (status tracks DNS detection, not the flag).
|
||||
.body("DkimAttributes.Status", equalTo("NOT_STARTED"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user