diff --git a/docs/services/ses.md b/docs/services/ses.md index ee562e84cf..c8732e5b42 100644 --- a/docs/services/ses.md +++ b/docs/services/ses.md @@ -530,7 +530,7 @@ Deviations from AWS: Floci keeps no recommendation history, so every recommendat ### Request member types -The operations whose body nests a structure in a structure, or holds a list of structures, check the request body against the SES v2 service model before anything else is validated, as AWS's restJson1 deserializer does: the send operations (`SendEmail`, `SendBulkEmail`, `SendCustomVerificationEmail`), `CreateConfigurationSet`, `UpdateConfigurationSet`, `PutConfigurationSetSuppressionOptions`, `PutConfigurationSetVdmOptions`, `CreateConfigurationSetEventDestination`, `UpdateConfigurationSetEventDestination`, `CreateContactList`, `UpdateContactList`, `CreateContact`, `UpdateContact`, `ListContacts`, `PutAccountSuppressionAttributes`, `PutAccountVdmAttributes`, `BatchGetMetricData`, `CreateImportJob` and `CreateExportJob`. `ListReputationEntities`, `UpdateReputationEntityPolicy`, `UpdateReputationEntityCustomerManagedStatus`, `GetEmailAddressInsights` and `ListRecommendations` run the same check although their bodies are flat. In those operations, the first body member of the wrong JSON type, in body order, is a `SerializationException` with AWS's deserializer message: +The operations whose body has a structure member holding another structure, or holds a list of structures, check the request body against the SES v2 service model before anything else is validated, as AWS's restJson1 deserializer does: the send operations (`SendEmail`, `SendBulkEmail`, `SendCustomVerificationEmail`), `CreateConfigurationSet`, `UpdateConfigurationSet`, `PutConfigurationSetSuppressionOptions`, `PutConfigurationSetVdmOptions`, `CreateConfigurationSetEventDestination`, `UpdateConfigurationSetEventDestination`, `CreateContactList`, `UpdateContactList`, `CreateContact`, `UpdateContact`, `ListContacts`, `PutAccountSuppressionAttributes`, `PutAccountVdmAttributes`, `BatchGetMetricData`, `CreateImportJob` and `CreateExportJob`. `ListReputationEntities`, `UpdateReputationEntityPolicy`, `UpdateReputationEntityCustomerManagedStatus`, `GetEmailAddressInsights`, `ListRecommendations` and `PutEmailIdentityDkimSigningAttributes` run the same check although their bodies are flat (`SigningAttributes` holds only scalars). In those operations, the first body member of the wrong JSON type, in body order, is a `SerializationException` with AWS's deserializer message: | Member type | Value sent | Message | |---|---|---| diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityController.java index f1213d9b7e..970e6e05c5 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 @@ -36,7 +36,6 @@ import static io.github.hectorvent.floci.services.ses.SesV2Json.parseTagsArray; import static io.github.hectorvent.floci.services.ses.SesV2Json.putTimestamp; import static io.github.hectorvent.floci.services.ses.SesV2Json.readOptionBody; import static io.github.hectorvent.floci.services.ses.SesV2Json.remapV1Exception; -import static io.github.hectorvent.floci.services.ses.SesV2Json.requireObjectOrAbsent; import static io.github.hectorvent.floci.services.ses.SesV2Json.stringMapMemberOrAbsent; import static io.github.hectorvent.floci.services.ses.SesV2Json.stringMemberOrAbsent; @@ -315,12 +314,13 @@ public class SesIdentityController { String region = regionResolver.resolveRegion(headers); try { JsonNode request = readOptionBody(objectMapper, body); + SesV2RequestShapes.check("PutEmailIdentityDkimSigningAttributes", request); String origin = request.path("SigningAttributesOrigin").asText(null); if (!"AWS_SES".equals(origin) && !"EXTERNAL".equals(origin)) { throw new AwsException("BadRequestException", "SigningAttributesOrigin must be AWS_SES or EXTERNAL.", 400); } - JsonNode attrs = requireObjectOrAbsent(request, "SigningAttributes"); + JsonNode attrs = request.path("SigningAttributes"); String selector = attrs.path("DomainSigningSelector").asText(null); String nextKeyLength = attrs.path("NextSigningKeyLength").asText(null); if (nextKeyLength != null 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.java index 40f0a23f84..4a1f28c1bd 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 @@ -631,7 +631,7 @@ public class SesIdentityService implements SesTaggable { } Identity identity = identityStore.get(identityKey(region, identityValue)) .orElseThrow(() -> new AwsException("NotFoundException", - "Email identity " + identityValue + " does not exist.", 404)); + "The specified email identity, " + identityValue + ", does not exist.", 404)); if ("EXTERNAL".equals(origin)) { identity.setDkimSigningAttributesOrigin("EXTERNAL"); // Clear the Easy DKIM tokens and reset the status: Floci can't verify a BYODKIM selector, diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesV2Json.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesV2Json.java index 88fd28817a..dab295d2bd 100644 --- a/src/main/java/io/github/hectorvent/floci/services/ses/SesV2Json.java +++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesV2Json.java @@ -67,15 +67,6 @@ final class SesV2Json { throw new AwsException(SERIALIZATION_EXCEPTION, null, 400); } - static JsonNode requireObjectOrAbsent(JsonNode parent, String fieldName) { - JsonNode child = parent.path(fieldName); - if (!child.isMissingNode() && !child.isNull() && !child.isObject()) { - throw new AwsException("BadRequestException", - fieldName + " must be a JSON object.", 400); - } - return child; - } - /** * Parse a JSON {@code Tags} array node into a list of tag records. Returns {@code null} * when the node is missing or null so callers can decide whether that is an error diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesV2RequestShapes.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesV2RequestShapes.java index d873142ec2..5d768de1b8 100644 --- a/src/main/java/io/github/hectorvent/floci/services/ses/SesV2RequestShapes.java +++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesV2RequestShapes.java @@ -12,11 +12,13 @@ import java.util.Set; * {@code aws/sesv2-request-shapes.json}, generated from botocore's SES v2 model by * {@code tools/aws/regen_sesv2_shapes.py}, and are walked by {@link RequestShapeCheck}. * - *
An operation calls this when its body nests a structure in a structure or holds a list of - * structures, where member-by-member checks drift apart. A flat body, a {@code Tags}-only body and - * a list operation's map {@code Filter} keep the {@link SesV2Json} member helpers, except in the - * reputation entity operations, which were added after this check and call it although their - * bodies are flat. + *
An operation calls this when a structure member of its body holds another structure, or the + * body holds a list of structures, where member-by-member checks drift apart. A flat body, a + * {@code Tags}-only body and a list operation's map {@code Filter} keep the {@link SesV2Json} + * member helpers, except in the reputation entity operations, {@code GetEmailAddressInsights} and + * {@code ListRecommendations}, which were added after this check, and + * {@code PutEmailIdentityDkimSigningAttributes}, whose hand-written object check this replaced. + * Those call it although their bodies are flat. * *
AWS reads the body in order and reports the first bad member, without naming it. A map
* container answers like a structure, except that a scalar for it is "Expected map or null". Only
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.java
index 2125727023..b00ea65ba3 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
@@ -5,9 +5,18 @@ import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
import java.util.List;
+import java.util.stream.Stream;
+import static io.github.hectorvent.floci.services.ses.SesV2SerializationErrors.EXPECTED_NULL;
+import static io.github.hectorvent.floci.services.ses.SesV2SerializationErrors.LIST;
+import static io.github.hectorvent.floci.services.ses.SesV2SerializationErrors.NUMBER;
+import static io.github.hectorvent.floci.services.ses.SesV2SerializationErrors.STRUCTURE;
+import static io.github.hectorvent.floci.services.ses.SesV2SerializationErrors.assertSerializationException;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
@@ -128,7 +137,9 @@ class SesDkimSigningActionsIntegrationTest {
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"));
+ .then().statusCode(404).body("__type", equalTo("NotFoundException"))
+ .body("message", equalTo(
+ "The specified email identity, ghost-signing.floci.test, does not exist."));
}
@Test
@@ -212,6 +223,32 @@ class SesDkimSigningActionsIntegrationTest {
.body("message", equalTo("Start of list found where not expected"));
}
+ // The identity does not exist and some cases send an invalid origin: AWS reads the body
+ // against the shapes before either check.
+ static Stream