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:
Priamo Germosen authored and GitHub committed 2026-10-07 08:03:02 -05:00
1 parent 3a8f974554
commit 5fc8b0418c
3 files changed
+62 -13

No files matched your search

+9
View File
@@ -549,6 +549,15 @@ states directly, so a request mixing namespaces is rejected whole rather than pa
Manager is the only namespace AWS names, and any well-formed key is accepted rather than only that
one, since an allowlist of one would refuse keys AWS takes.
Those two rules are not the same kind of failure, and they answer differently. The length and the
pattern are constraints the API Reference publishes on the parameter, and it defines
`ValidationError` as the common error for input that "doesn't meet the required format or
constraints", so a key that is too long or outside the pattern, and a value outside 1 to 1024, are
`ValidationError` with status 400. The `Namespace/PropertyName` rule cannot be expressed in the
published pattern, which admits a key with no slash, with several, and with a trailing one, so it is
a rule applied once the format is already satisfied: that, and a request mixing namespaces, are
`InvalidInput` with status 400, the "invalid or out-of-range value" the operation declares.
**Enabling federation twice is an error, and so is disabling it twice**, which is the asymmetry
worth noticing: `EnableOutboundWebIdentityFederation` answers `FeatureEnabled` with status 409,
while `DisableOutboundWebIdentityFederation` answers `FeatureDisabled` with status **404**. AWS
@@ -2341,11 +2341,20 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
properties.size(), namespace);
}
/** The namespace half of the key, having checked the whole key against the model. */
/**
* The namespace half of the key, having checked the whole key against the model.
*
* <p>The two rejections here are not the same kind of error. The length and the pattern are
* published constraints on the parameter, and the API Reference defines {@code ValidationError}
* as the common error for input that "doesn't meet the required format or constraints". The
* {@code Namespace/PropertyName} rule is not expressible in the published pattern, which admits
* no slash, several, and a trailing one, so it is a rule the service applies after the format
* is already satisfied: that is {@code InvalidInput}, "an invalid or out-of-range value".
*/
private String validateAccountPropertyKey(String key) {
if (key == null || key.isEmpty() || key.length() > MAX_ACCOUNT_PROPERTY_KEY_LENGTH
|| !ACCOUNT_PROPERTY_KEY_PATTERN.matcher(key).matches()) {
throw new AwsException("InvalidInput",
throw new AwsException("ValidationError",
"Value '" + key + "' at 'properties' failed to satisfy constraint: Map keys "
+ "must satisfy constraint: [Member must have length less than or "
+ "equal to " + MAX_ACCOUNT_PROPERTY_KEY_LENGTH + ", Member must "
@@ -2355,9 +2364,9 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
int separator = key.indexOf('/');
if (separator <= 0 || separator != key.lastIndexOf('/') || separator == key.length() - 1) {
throw new AwsException("InvalidInput",
"Value '" + key + "' at 'properties' failed to satisfy constraint: a key is "
+ "Namespace/PropertyName, with exactly one forward slash and neither "
+ "a leading nor a trailing one.", 400);
"The property key '" + key + "' is not Namespace/PropertyName: a key has "
+ "exactly one forward slash, and neither a leading nor a trailing "
+ "one.", 400);
}
return key.substring(0, separator);
}
@@ -2365,7 +2374,7 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
private void validateAccountPropertyValue(String key, String value) {
if (value == null || value.isEmpty()
|| value.length() > MAX_ACCOUNT_PROPERTY_VALUE_LENGTH) {
throw new AwsException("InvalidInput",
throw new AwsException("ValidationError",
"Value at 'properties." + key + "' failed to satisfy constraint: Member must "
+ "have length between 1 and " + MAX_ACCOUNT_PROPERTY_VALUE_LENGTH,
400);
@@ -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")