fix(ses): align V2 identity error responses with AWS (#723)

PutEmailIdentityDkimAttributes, CreateEmailIdentity, and DeleteEmailIdentity
now return the same error codes and messages as real AWS SES v2:

- PutEmailIdentityDkimAttributes on unknown identity -> 400 BadRequestException
  ("Domain X is not verified for DKIM signing.")
- PutEmailIdentityDkimAttributes on email-format identity whose parent
  domain is registered -> 200 OK no-op (DKIM is a domain-level concept)
- CreateEmailIdentity on duplicate identity -> 400 AlreadyExistsException
- DeleteEmailIdentity on unknown identity -> 404 NotFoundException

V1 idempotent semantics (VerifyEmailIdentity / VerifyDomainIdentity /
DeleteIdentity) are preserved -- strict checks are added at the V2
controller level only.

Integration tests assert the exact AWS error messages (with trailing
period) and, for the email-with-registered-parent no-op case, verify
that the parent domain's DkimAttributes are unchanged before and after.
This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-05-06 18:51:48 -05:00
1 parent 692d665734
commit 59faf568fc
4 files changed
+141 -20

No files matched your search

@@ -72,6 +72,11 @@ public class SesController {
throw new AwsException("BadRequestException", "EmailIdentity is required.", 400);
}
if (sesService.getIdentityVerificationAttributes(emailIdentity, region) != null) {
throw new AwsException("AlreadyExistsException",
"Email identity " + emailIdentity + " already exist.", 400);
}
Identity identity = emailIdentity.contains("@")
? sesService.verifyEmailIdentity(emailIdentity, region)
: sesService.verifyDomainIdentity(emailIdentity, region);
@@ -126,6 +131,10 @@ public class SesController {
public Response deleteEmailIdentity(@Context HttpHeaders headers,
@PathParam("emailIdentity") String emailIdentity) {
String region = regionResolver.resolveRegion(headers);
if (sesService.getIdentityVerificationAttributes(emailIdentity, region) == null) {
throw new AwsException("NotFoundException",
"Email identity " + emailIdentity + " does not exist.", 404);
}
sesService.deleteIdentity(emailIdentity, region);
LOG.infov("SES V2 DeleteEmailIdentity: {0}", emailIdentity);
return Response.ok(objectMapper.createObjectNode()).build();
@@ -222,9 +222,20 @@ public class SesService {
public void setDkimAttributes(String identityValue, boolean signingEnabled, String region) {
String key = identityKey(region, identityValue);
Identity identity = identityStore.get(key)
.orElseThrow(() -> new AwsException("NotFoundException",
"Identity does not exist: " + identityValue, 404));
Identity identity = identityStore.get(key).orElse(null);
if (identity == null) {
String domain = identityValue != null && identityValue.contains("@")
? identityValue.substring(identityValue.indexOf('@') + 1)
: identityValue;
if (identityValue != null && identityValue.contains("@")
&& identityStore.get(identityKey(region, domain)).isPresent()) {
return;
}
throw new AwsException("BadRequestException",
"Domain " + domain + " is not verified for DKIM signing.", 400);
}
identity.setDkimEnabled(signingEnabled);
if (signingEnabled) {
identity.setDkimVerificationStatus("Success");