mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(iam): separate a constraint failure from an invalid value in PutAccountProperties (#5240)
The key pattern and length checks answered InvalidInput while carrying the "failed to satisfy constraint" wording that every other constraint check in IamService pairs with ValidationError. The model declares InvalidInputException on the operation and says nothing about which code a pattern miss produces, so the two had drifted apart with nothing to settle them. The API Reference settles it in Common Error Types rather than the operation's own error table. ValidationError is a common error for every action, defined as "The input doesn't meet the required format or constraints", 400. InvalidInput, the one the operation declares, is "an invalid or out-of-range value was supplied for an input parameter". PutAccountProperties publishes a Key Pattern of ^[A-Za-z][A-Za-z0-9/_-]*$, a key length of 1 to 50 and a value length of 1 to 1024, and the model declares all three on accountPropertyKeyType and accountPropertyValueType. Violating a published pattern or length is a format failure; a value that satisfies them and is still wrong is not. So it is a split rather than a rename. The key pattern and length, and the value length, are now ValidationError and keep the constraint wording, which was already right for them. The Namespace/PropertyName rule stays InvalidInput: the published pattern admits a key with no slash, with several, and with a trailing one, so that rule only applies once the format is already good. Its message drops the constraint wording and reads as prose, since that wording is what made the pair look inconsistent. The same-namespace rule is unchanged. aMalformedKeyIsRejected asserted one code for seven keys that fall on both sides of that line, so it splits in two, each asserting its own code and the absence of the other. As written it could not tell a pattern failure from the slash rule. Not touched, though the same reading would question it: createServiceLinkedRole answers InvalidInput for a check that is exactly the declared constraint on AWSServiceName. Its message is prose rather than the front-end format, there is no recording either way, and CreateServiceLinkedRole's error table is structured identically to this one, so it proves nothing. Left alone rather than changed on inference. Refs #5177
This commit is contained in:
1 parent
3a8f974554
commit
5fc8b0418c
3 files changed
+62
-13
No files matched your search
+38
-7
@@ -75,16 +75,47 @@ class AccountPropertiesIntegrationTest {
|
||||
.body(not(containsString(second + "/Beta")));
|
||||
}
|
||||
|
||||
/** The key is Namespace/PropertyName: exactly one slash, not at either end. */
|
||||
/**
|
||||
* A key can be wrong in two ways that AWS reports differently, so they get a test each rather
|
||||
* than one list asserting the same code for both.
|
||||
*
|
||||
* <p>These keys violate the published pattern {@code ^[A-Za-z][A-Za-z0-9/_-]*$}, either by
|
||||
* starting with something other than a letter or by carrying a character outside the class.
|
||||
* That is a format failure, which the API Reference gives to the common
|
||||
* {@code ValidationError}.
|
||||
*/
|
||||
@Test
|
||||
void aMalformedKeyIsRejected() {
|
||||
for (String key : List.of("NoSlash", "/LeadingSlash", "Trailing/", "Two/Slashes/Here",
|
||||
"1StartsWithADigit", "Has Space/Prop", "Ns/Prop!")) {
|
||||
void aKeyOutsideThePublishedPatternIsAValidationError() {
|
||||
for (String key : List.of("/LeadingSlash", "1StartsWithADigit", "Has Space/Prop",
|
||||
"Ns/Prop!")) {
|
||||
iam("PutAccountProperties")
|
||||
.formParam("Properties.entry.1.key", key)
|
||||
.formParam("Properties.entry.1.value", "x")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("InvalidInput"));
|
||||
.body(containsString("ValidationError"))
|
||||
.body(not(containsString("InvalidInput")))
|
||||
.body(containsString("failed to satisfy constraint"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* These three satisfy the published pattern, which admits no slash, several, and a trailing
|
||||
* one, and fail only the Namespace/PropertyName rule. The service applies that after the
|
||||
* format is already good, so it is {@code InvalidInput} rather than a constraint failure.
|
||||
*/
|
||||
@Test
|
||||
void aKeyThatIsNotNamespaceSlashPropertyIsInvalidInput() {
|
||||
for (String key : List.of("NoSlash", "Trailing/", "Two/Slashes/Here")) {
|
||||
iam("PutAccountProperties")
|
||||
.formParam("Properties.entry.1.key", key)
|
||||
.formParam("Properties.entry.1.value", "x")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("InvalidInput"))
|
||||
.body(not(containsString("ValidationError")))
|
||||
// The wording matters as much as the code here: carrying the constraint phrasing
|
||||
// on an InvalidInput is the mismatch this split exists to remove.
|
||||
.body(containsString("is not Namespace/PropertyName"))
|
||||
.body(not(containsString("failed to satisfy constraint")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,13 +126,13 @@ class AccountPropertiesIntegrationTest {
|
||||
iam("PutAccountProperties")
|
||||
.formParam("Properties.entry.1.key", ns + "/" + "P".repeat(60))
|
||||
.formParam("Properties.entry.1.value", "x")
|
||||
.when().post("/").then().statusCode(400).body(containsString("InvalidInput"));
|
||||
.when().post("/").then().statusCode(400).body(containsString("ValidationError"));
|
||||
|
||||
// valueLength is 1 to 1024.
|
||||
iam("PutAccountProperties")
|
||||
.formParam("Properties.entry.1.key", ns + "/TooLongValue")
|
||||
.formParam("Properties.entry.1.value", "v".repeat(1025))
|
||||
.when().post("/").then().statusCode(400).body(containsString("InvalidInput"));
|
||||
.when().post("/").then().statusCode(400).body(containsString("ValidationError"));
|
||||
|
||||
// And the top of the range is accepted, so the bound is not off by one.
|
||||
iam("PutAccountProperties")
|
||||
|
||||
Reference in new issue
Block a user