diff --git a/docs/services/iam.md b/docs/services/iam.md index 8de6d39241..96e1a4d37d 100644 --- a/docs/services/iam.md +++ b/docs/services/iam.md @@ -159,11 +159,14 @@ violation at once, the map's own length ahead of its entries. An entry's values member being present rather than by what it holds, the list's members publishing no constraint of their own, so a replacement value sent empty is a value. -The message for a broken entry names it by its key, as `replacementValues.Department.values`, which -is how IAM reports a bad value in its account properties map. No recorded AWS violation on a map -member is on hand to confirm that spelling, so it is Floci's reading of it: a capture would either -keep it or replace it with the nested form, where the path is the map itself and the constraint -reads "Map value must satisfy constraint". +The message for a broken entry names it by its key and then the field under `.member`, as +`replacementValues.Department.member.values`. The key half is how IAM reports a bad value in its +account properties map; the `.member` half comes from an AWS-validated recording of the same +protocol, SNS answering a missing `DataType` inside its `MessageAttributes` map as `Value null at +'messageAttributes.attr1.member.dataType'`, and inside a list's member as +`publishBatchRequestEntries.1.member.messageAttributes.attr1.member.dataType`. So a map of +structures is named the way a list of structures is, the entry's key standing where a list's index +stands. ### Policies @@ -222,15 +225,24 @@ breaking a minimum of 1. A structure member arrives as `TaskPolicyArn.Arn` and i A map is read the same way, from the entries the protocol numbers under its name: `ReplacementValues.entry.1.key` and `.entry.1.value`, which is the form `AcquireRole`'s own sample publishes, or the bare `ReplacementValues.1.key`. An entry's value is named under the key that -entry carries, `replacementValues.Department.values` and `properties.Team/Owner`, which is how both -maps this service answered by hand already named one and how the JSON protocols name a map's value -here. An entry is read off its key, so one numbered with a value and no key is not an entry the map -could hold: it is neither counted nor answered. The count is held to the map's own bounds with the -value left out of the message, and a map the request names nowhere is how an absent map arrives, so -a required one reads as null. A key outside its shape's rules is answered with the whole set that -shape declares, nested under the map's own name, `Value at 'properties' failed to satisfy -constraint: Map keys must satisfy constraint: [...]`, which is the form every map key recorded here -carries and what this service already answered for an account property key. +entry carries, `replacementValues.Department.member.values` and `properties.Team/Owner`, which is +how both maps this service answered by hand already named one and how the JSON protocols name a +map's value here. A value that is a structure carries `.member` between the key and the field, as +AWS writes it on this protocol and as a list of structures already reads here. A scalar value is +named at the key itself: nothing recorded covers one on this protocol, and the only recording of a +scalar-valued map anywhere, Lambda's `routingConfig.additionalVersionWeights` on REST-JSON, +answers the map rather than the entry, `Value '{2=-1.0}' at +'routingConfig.additionalVersionWeights' failed to satisfy constraint: Map value must satisfy +constraint: [...]`. That is a different protocol and a different service, so +`properties.Team/Owner` keeps the answer this service already gave, and a recording of a +scalar-valued map on the Query protocol is what would move it. An entry is read off its key, so +one numbered with a value and no key is not an entry the map could hold: it is neither counted nor +answered. The count is held to the map's own bounds with the value left out of the message, and a +map the request names nowhere is how an absent map arrives, so a required one reads as null. A key +outside its shape's rules is answered with the whole set that shape declares, nested under the +map's own name, `Value at 'properties' failed to satisfy constraint: Map keys must satisfy +constraint: [...]`, which is the form every map key recorded here carries and what this service +already answered for an account property key. The two maps answered by hand are answered from the model now, and `AcquireRole`'s answers do not move at all: its count of 30, each entry's required `Values` and the 20 values one entry admits read diff --git a/src/main/java/io/github/hectorvent/floci/core/common/QueryConstraintCheck.java b/src/main/java/io/github/hectorvent/floci/core/common/QueryConstraintCheck.java index de1ad49da8..245081ad3e 100644 --- a/src/main/java/io/github/hectorvent/floci/core/common/QueryConstraintCheck.java +++ b/src/main/java/io/github/hectorvent/floci/core/common/QueryConstraintCheck.java @@ -50,10 +50,16 @@ import java.util.regex.Pattern; * {@code Properties.entry.1.value}, or bare as {@code Properties.1.key}. An entry's value is named * under the key the entry carries, {@code properties.Team/Owner}, which is how the hand-written * checks these waves replace already named one and how {@link RequestConstraintCheck} names a map's - * value on the JSON protocols. An entry numbered with no key of its own is no entry the map could - * hold, so it is neither counted nor answered. A key outside its shape's rules is answered with the - * whole set the shape declares, nested under the map's own name, which is the form AWS answers for - * a map key everywhere this repository has one recorded. + * value on the JSON protocols. A value that is a structure carries {@code .member} between the key + * and the field, {@code replacementValues.Department.member.values}: that is the form AWS writes on + * this protocol, recorded against SNS as {@code messageAttributes.attr1.member.dataType}, and a + * list of structures already reads the same way, its index standing where the key stands. A scalar + * value is named at the key itself, which nothing recorded covers here: the one recording of a + * scalar-valued map, on another protocol, answers the map rather than the entry. An entry numbered + * with no key of its own is no entry the map could hold, so it is neither counted nor answered. A + * key outside its shape's rules is answered with the whole set the shape declares, nested under the + * map's own name, which is the form AWS answers for a map key everywhere this repository has one + * recorded. * *

Every one of those may hold any of the others: a structure's field may be a list, a list's * member a map, a map's value a structure. A shape of some other type is one this walk would pass @@ -242,10 +248,11 @@ public final class QueryConstraintCheck { /** * A map's entries, held to the map's own bounds and then each key and value to its shape. An - * entry arrives as {@code Properties.entry.1.key} and {@code Properties.entry.1.value}, and - * the value is named under the key the entry carries. An entry is read off that key, as the - * count of one has always been here, so one numbered with no key is not an entry the map could - * hold: it is neither counted nor answered. + * entry arrives as {@code Properties.entry.1.key} and {@code Properties.entry.1.value}, and the + * value is named under the key the entry carries, with {@code .member} after it where that + * value is a structure and the field inside it is what broke. An entry is read off that key, as + * the count of one has always been here, so one numbered with no key is not an entry the map + * could hold: it is neither counted nor answered. */ private List mapViolations(JsonNode shape, String param, String path, boolean required, MultivaluedMap params) { @@ -270,8 +277,9 @@ public final class QueryConstraintCheck { if (structure) { // An entry the request numbered with a key is an entry, so what the structure // under it requires is answered inside it rather than the value reading as absent. + // The field sits under `.member` after the key, which is how AWS names one. violations.addAll(structureViolations(shapes.path(valueShape), valueParam + ".", - valuePath + ".", params, Map.of())); + valuePath + ".member.", params, Map.of())); } else { violations.addAll(memberViolations(valueShape, valueParam, valuePath, true, params)); } diff --git a/src/test/java/io/github/hectorvent/floci/core/common/QueryConstraintCheckTest.java b/src/test/java/io/github/hectorvent/floci/core/common/QueryConstraintCheckTest.java index 82de104f38..9dba6babd8 100644 --- a/src/test/java/io/github/hectorvent/floci/core/common/QueryConstraintCheckTest.java +++ b/src/test/java/io/github/hectorvent/floci/core/common/QueryConstraintCheckTest.java @@ -61,8 +61,12 @@ class QueryConstraintCheckTest { "operations": {"Acquire": "AcquireRequest"}, "shapes": { "AcquireRequest": {"type": "structure", "required": ["Values"], "members": { - "Values": "valueMap", "Nested": "nestedType", "Entries": "entryList"}}, + "Values": "valueMap", "Nested": "nestedType", "Entries": "entryList", + "Replacements": "replacementMap"}}, "valueMap": {"type": "map", "key": "keyType", "value": "valueType", "max": 2}, + "replacementMap": {"type": "map", "key": "keyType", "value": "replacementType"}, + "replacementType": {"type": "structure", "required": ["Values"], "members": { + "Values": "nameList"}}, "nestedType": {"type": "structure", "members": { "Arn": "arnType", "Parameters": "nameList"}}, "entryList": {"type": "list", "member": "entryType"}, @@ -564,6 +568,34 @@ class QueryConstraintCheckTest { "Values.entry.3.key", "c", "Values.entry.3.value", "z"))); } + /** + * A map whose value is a structure names the field under {@code .member} after the key, which + * is the form AWS writes on this protocol: an AWS-validated SNS recording answers a missing + * {@code DataType} inside one as + * {@code Value null at 'messageAttributes.attr1.member.dataType'}. A scalar value stays at the + * key, as the test above has it, nothing recorded covering one here. + */ + @Test + void aStructureUnderAMapsKeyNamesItsFieldUnderMember() throws Exception { + // `keyType` is 4 characters, so the key is short enough to break nothing of its own and + // leave the field inside the entry as the only violation. + assertEquals(List.of("Value null at 'replacements.Dept.member.values' failed to satisfy" + + " constraint: Member must not be null"), + maps().violations("Acquire", params( + "Values.entry.1.key", "k", "Values.entry.1.value", "ok", + "Replacements.entry.1.key", "Dept"))); + + assertEquals(List.of("Value at 'replacements.Dept.member.values' failed to satisfy" + + " constraint: Member must have length less than or equal to 2"), + maps().violations("Acquire", params( + "Values.entry.1.key", "k", "Values.entry.1.value", "ok", + "Replacements.entry.1.key", "Dept", + "Replacements.entry.1.value.Values.member.1", "a", + "Replacements.entry.1.value.Values.member.2", "b", + "Replacements.entry.1.value.Values.member.3", "c")), + "and the list inside that structure is held to its own bounds under the same path"); + } + /** A map the request names nowhere is the required member reading as null. */ @Test void aMapNamedNowhereIsTheRequiredMemberReadingAsNull() throws Exception { diff --git a/src/test/java/io/github/hectorvent/floci/services/iam/IamRequestConstraintsIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/iam/IamRequestConstraintsIntegrationTest.java index 7c5912fd4e..1e8ae84cdc 100644 --- a/src/test/java/io/github/hectorvent/floci/services/iam/IamRequestConstraintsIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/iam/IamRequestConstraintsIntegrationTest.java @@ -348,7 +348,8 @@ class IamRequestConstraintsIntegrationTest { * deepest request this service models: {@code AcquireRole} numbers its replacement values as * entries and each entry's structure carries a list of its own. An entry the request numbered * with a key is an entry, so what the structure under it requires is answered inside it, named - * under that key, which is the answer the hand-written check this replaces already gave. + * under that key with {@code .member} after it, which is the form AWS writes for a map of + * structures on this protocol. */ @Test void aMapValuesStructureAndTheListInsideItAreRead() { @@ -358,8 +359,8 @@ class IamRequestConstraintsIntegrationTest { .when().post("/").then().statusCode(400) .body(CODE, equalTo("ValidationError")) .body(MESSAGE, equalTo("1 validation error detected: Value at" - + " 'replacementValues.Department.values' failed to satisfy constraint: Member" - + " must not be null")); + + " 'replacementValues.Department.member.values' failed to satisfy constraint:" + + " Member must not be null")); } /** diff --git a/src/test/java/io/github/hectorvent/floci/services/iam/RoleTemplateIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/iam/RoleTemplateIntegrationTest.java index 1348e1256c..d7cf18f445 100644 --- a/src/test/java/io/github/hectorvent/floci/services/iam/RoleTemplateIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/iam/RoleTemplateIntegrationTest.java @@ -176,8 +176,8 @@ class RoleTemplateIntegrationTest { .statusCode(400) .body("ErrorResponse.Error.Code", equalTo("ValidationError")) .body("ErrorResponse.Error.Message", equalTo("1 validation error detected: Value " - + "at 'replacementValues.Department.values' failed to satisfy constraint: " - + "Member must not be null")) + + "at 'replacementValues.Department.member.values' failed to satisfy " + + "constraint: Member must not be null")) .body(not(containsString("NoSuchEntity"))); } @@ -191,8 +191,8 @@ class RoleTemplateIntegrationTest { .statusCode(400) .body("ErrorResponse.Error.Code", equalTo("ValidationError")) .body("ErrorResponse.Error.Message", equalTo("1 validation error detected: Value at " - + "'replacementValues.Department.values' failed to satisfy constraint: Member " - + "must have length less than or equal to 20")); + + "'replacementValues.Department.member.values' failed to satisfy constraint: " + + "Member must have length less than or equal to 20")); acquireWithValues(20).when().post("/").then() .statusCode(404) @@ -255,8 +255,8 @@ class RoleTemplateIntegrationTest { .when().post("/").then() .statusCode(400) .body("ErrorResponse.Error.Message", equalTo("1 validation error detected: Value " - + "at 'replacementValues.Department.values' failed to satisfy constraint: " - + "Member must not be null")); + + "at 'replacementValues.Department.member.values' failed to satisfy " + + "constraint: Member must not be null")); } /** @@ -280,9 +280,9 @@ class RoleTemplateIntegrationTest { .body("ErrorResponse.Error.Code", equalTo("ValidationError")) .body("ErrorResponse.Error.Message", equalTo("3 validation errors detected: Value at " + "'replacementValues' failed to satisfy constraint: Member must have length " - + "less than or equal to 30; Value at 'replacementValues.Parameter2." + + "less than or equal to 30; Value at 'replacementValues.Parameter2.member." + "values' failed to satisfy constraint: Member must not be null; Value " - + "at 'replacementValues.Parameter10.values' failed to satisfy constraint: " - + "Member must not be null")); + + "at 'replacementValues.Parameter10.member.values' failed to satisfy " + + "constraint: Member must not be null")); } }