mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(ses): check PutEmailIdentityDkimSigningAttributes against the SES v2 shapes (#7084)
A SigningAttributes member that is not a JSON object answered a Floci-only BadRequestException. The operation now runs the shared SES v2 shape check first, so a member of the wrong JSON type is a SerializationException with AWS's deserializer message, ahead of the origin check and the identity lookup, as AWS answers it. A missing identity now answers AWS's "The specified email identity, <id>, does not exist."
This commit is contained in:
1 parent
5e9df931e3
commit
f40d784f66
7 files changed
+49
-30
No files matched your search
@@ -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 |
|
||||
|---|---|---|
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}.
|
||||
*
|
||||
* <p>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.
|
||||
* <p>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.
|
||||
*
|
||||
* <p>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
|
||||
|
||||
+38
-1
@@ -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<Arguments> putDkimSigningAttributesWrongMemberTypeCases() {
|
||||
return Stream.of(
|
||||
Arguments.of("stringSigningAttributes",
|
||||
"{\"SigningAttributesOrigin\": \"AWS_SES\", \"SigningAttributes\": \"x\"}", EXPECTED_NULL),
|
||||
Arguments.of("stringSigningAttributesWithInvalidOrigin",
|
||||
"{\"SigningAttributesOrigin\": \"BAD\", \"SigningAttributes\": \"x\"}", EXPECTED_NULL),
|
||||
Arguments.of("arraySigningAttributes",
|
||||
"{\"SigningAttributesOrigin\": \"AWS_SES\", \"SigningAttributes\": []}", LIST),
|
||||
Arguments.of("arrayNextSigningKeyLength",
|
||||
"{\"SigningAttributesOrigin\": \"AWS_SES\", "
|
||||
+ "\"SigningAttributes\": {\"NextSigningKeyLength\": []}}", LIST),
|
||||
Arguments.of("objectDomainSigningSelector",
|
||||
"{\"SigningAttributesOrigin\": \"EXTERNAL\", "
|
||||
+ "\"SigningAttributes\": {\"DomainSigningSelector\": {}}}", STRUCTURE),
|
||||
Arguments.of("numericOrigin", "{\"SigningAttributesOrigin\": 1}", NUMBER));
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@MethodSource("putDkimSigningAttributesWrongMemberTypeCases")
|
||||
void putDkimSigningAttributes_wrongMemberType(String caseName, String body, String message) {
|
||||
assertSerializationException("PUT", "/v2/email/identities/dkim-missing.floci.test/dkim/signing",
|
||||
body, message);
|
||||
}
|
||||
|
||||
@Test
|
||||
void putEmailIdentityDkimAttributes_existingEmailWithRegisteredDomain_isNoOp() {
|
||||
String domain = "dkim-emailtoggle.floci.test";
|
||||
|
||||
@@ -81,17 +81,6 @@ class SesV2JsonTest {
|
||||
SesV2Json.requireJsonObject(json("{}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void requireObjectOrAbsent_returnsChild_rejectsScalars() {
|
||||
assertTrue(SesV2Json.requireObjectOrAbsent(json("{}"), "Options").isMissingNode());
|
||||
assertTrue(SesV2Json.requireObjectOrAbsent(json("{\"Options\":null}"), "Options").isNull());
|
||||
JsonNode nested = json("{\"Options\":{\"a\":\"x\"}}");
|
||||
assertEquals("x", SesV2Json.requireObjectOrAbsent(nested, "Options").path("a").asText());
|
||||
assertEquals("Options must be a JSON object.",
|
||||
assertAws("BadRequestException", 400, () -> SesV2Json.requireObjectOrAbsent(
|
||||
json("{\"Options\":1}"), "Options")).getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void parseTagsArray_absentIsNull_shapeErrorsAreWireErrors() {
|
||||
assertNull(SesV2Json.parseTagsArray(json("{}").path("Tags")));
|
||||
|
||||
Reference in new issue
Block a user