fix(iam): name the member without the offending value in a validation error (#6811)

IAM's constraint violations read `Value at 'roleName' failed to satisfy
constraint: Member must have length greater than or equal to 1`, with no
value beside the member, which is where the recorded messages point: the two
IAM messages in LocalStack's AWS-validated snapshot from 2025-03-06, a 2026
capture of a `UserName` over 64 characters, and the messages the Identity
Center guide lists as the ones that commonly appear in CloudTrail events.
The two captures that carry the value are from 2019 and 2024, so they read
as stale rather than as wrong when written. STS keeps the value, which its
own 2024 capture carries and which is the same split this package already
records for pattern and enum messages.

It is a reading rather than a published rule, so `docs/services/iam.md` says
so and names the captures behind it. A direct capture that shows IAM
carrying the value again moves it back in one edit.

The form is chosen in one place. `SmithyValidationErrors.Violations` writes
each sentence once and carries both forms; the statics stay the quoting one,
so every other service answers exactly what it answered before.
`IamValidationErrors` names IAM's side of the split for the handler, the
service and the service-last-accessed check, and the shared Query walk is
loaded with the form of the service reading it, IAM without the value and
STS with it.

Two messages are left alone, neither being this question: a list checked as
a whole carries the list as its value, which is what AWS does elsewhere, and
a required member the request leaves out keeps `Value null at '<member>'`,
which no capture covers in either form.

Two checks built the message by hand rather than through a helper and so are
swept here too: `GenerateOrganizationsAccessReport` and the delegation
request operations each composed the quoted value inline, which is why
neither shows up in a search for the literal form. Their entity path and
request id now assert the whole message rather than only the error code,
since asserting the code alone is what let that drift sit unnoticed.

The vendored shapes file carries 52 operations now rather than 13, so the
members the paging wave opted in answer in the shorter form as well, and the
table sweep over every paged operation asserts it that way.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-10-28 19:51:54 -05:00
1 parent 42b4bf4245
commit 6606657434
18 files changed
+332 -137

No files matched your search

@@ -345,8 +345,10 @@ class QueryConstraintCheckTest {
*/
@Test
void theVendoredIamFileLoadsAndCarriesTheOperationsTheseWavesClaim() {
QueryConstraintCheck iam =
QueryConstraintCheck.load("aws/iam-request-shapes.json", "IAM request shapes");
// Loaded in IAM's own form, naming the member with no value beside it, which is what
// IamRequestShapes passes and what DRIFT-13 settles.
QueryConstraintCheck iam = QueryConstraintCheck.load("aws/iam-request-shapes.json",
"IAM request shapes", SmithyValidationErrors.Violations.WITHOUT_VALUES);
List<String> managedPolicyFamily = List.of("AttachGroupPolicy", "AttachRolePolicy",
"AttachUserPolicy", "DetachGroupPolicy", "DetachRolePolicy", "DetachUserPolicy",
@@ -360,13 +362,13 @@ class QueryConstraintCheckTest {
operation + " resolved to no required members, so its shape did not resolve");
}
assertEquals(List.of("Value 'v1' at 'policyArn' failed to satisfy constraint: Member must"
assertEquals(List.of("Value at 'policyArn' failed to satisfy constraint: Member must"
+ " have length greater than or equal to 20"),
iam.violations("GetPolicy", params("PolicyArn", "v1")));
assertEquals(List.of(), iam.violations("GetAccountAuthorizationDetails", params()),
"every member of it is optional, so a request naming none of them breaks nothing");
assertEquals(List.of("Value 'Users' at 'filter.1.member' failed to satisfy constraint:"
assertEquals(List.of("Value at 'filter.1.member' failed to satisfy constraint:"
+ " Member must satisfy enum value set:"
+ " [User, Role, Group, LocalManagedPolicy, AWSManagedPolicy]"),
iam.violations("GetAccountAuthorizationDetails", params("Filter.member.1", "Users")),
@@ -85,4 +85,41 @@ class SmithyValidationErrorsTest {
SmithyValidationErrors.lengthOutOfRange("name", value.repeat(2), 0, 1));
}
/**
* A service's own form decides whether the offending value is quoted beside the member, which
* is the only thing the two differ in. The statics are the quoting form, so every service that
* calls them keeps the message it answered.
*/
@Test
void aServicesFormDecidesWhetherTheValueIsQuoted() {
SmithyValidationErrors.Violations quoted = SmithyValidationErrors.Violations.QUOTED;
SmithyValidationErrors.Violations without = SmithyValidationErrors.Violations.WITHOUT_VALUES;
assertEquals("Value 'ab' at 'userName' failed to satisfy constraint: "
+ "Member must have length greater than or equal to 3",
quoted.lengthOutOfRange("userName", "ab", 3, 10));
assertEquals("Value at 'userName' failed to satisfy constraint: "
+ "Member must have length greater than or equal to 3",
without.lengthOutOfRange("userName", "ab", 3, 10));
assertEquals(SmithyValidationErrors.lengthOutOfRange("userName", "ab", 3, 10),
quoted.lengthOutOfRange("userName", "ab", 3, 10));
assertEquals(SmithyValidationErrors.pattern("userName", "a b", "[a-z]+"),
quoted.pattern("userName", "a b", "[a-z]+"));
assertEquals(SmithyValidationErrors.notInEnum("Users", "filter", List.of("User")),
quoted.notInEnum("Users", "filter", List.of("User")));
assertEquals(SmithyValidationErrors.outOfRange("maxItems", 1001, 1, 1000),
quoted.outOfRange("maxItems", 1001, 1, 1000));
assertEquals("Value at 'filter' failed to satisfy constraint: "
+ "Member must satisfy enum value set: [User]",
without.notInEnum("Users", "filter", List.of("User")));
assertEquals("Value at 'maxItems' failed to satisfy constraint: "
+ "Member must have value less than or equal to 1000",
without.outOfRange("maxItems", 1001, 1, 1000));
// A value inside its bounds is no violation in either form.
assertNull(without.lengthOutOfRange("userName", "abc", 3, 10));
assertNull(without.outOfRange("maxItems", 1000, 1, 1000));
}
}
@@ -276,7 +276,12 @@ class DelegationRequestIntegrationTest {
// here too rather than with the InvalidInput these operations happen to model.
byId(PARTNER_AUTH, "GetDelegationRequest", "dr-short")
.statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("ValidationError"));
.body("ErrorResponse.Error.Code", equalTo("ValidationError"))
// The whole message, since these operations name the member with no value beside
// it, as every other IAM check does.
.body("ErrorResponse.Error.Message", equalTo("1 validation error detected: Value at"
+ " 'delegationRequestId' failed to satisfy constraint: Member must have"
+ " length greater than or equal to 16"));
}
@Test
@@ -1691,8 +1691,8 @@ class IamIntegrationTest {
.when().post("/").then()
.statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("ValidationError"))
.body("ErrorResponse.Error.Message", equalTo("1 validation error detected: Value '" + name
+ "' at 'roleName' failed to satisfy constraint: " + entry.getValue()));
.body("ErrorResponse.Error.Message", equalTo("1 validation error detected: Value at"
+ " 'roleName' failed to satisfy constraint: " + entry.getValue()));
given()
.formParam("Action", "GetRole")
@@ -1728,8 +1728,8 @@ class IamIntegrationTest {
.when().post("/").then()
.statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("ValidationError"))
.body("ErrorResponse.Error.Message", equalTo("1 validation error detected: Value ''"
+ " at 'roleName' failed to satisfy constraint: Member must have length greater than or equal to 1"));
.body("ErrorResponse.Error.Message", equalTo("1 validation error detected: Value at"
+ " 'roleName' failed to satisfy constraint: Member must have length greater than or equal to 1"));
given()
.formParam("Action", "CreateRole")
@@ -1744,7 +1744,7 @@ class IamIntegrationTest {
@Order(87)
void roleActionsRejectANameOutsideTheRoleNamePattern() {
String name = "aws:ec2-instance";
String message = "1 validation error detected: Value '" + name + "' at 'roleName' failed to satisfy"
String message = "1 validation error detected: Value at 'roleName' failed to satisfy"
+ " constraint: Member must satisfy regular expression pattern: [\\w+=,.@-]+";
Map<String, Map<String, String>> actions = new LinkedHashMap<>();
actions.put("GetRole", Map.of());
@@ -888,14 +888,14 @@ class IamListPaginationIntegrationTest {
listRequest(action, fixture, Integer.toString(min - 1), null).when().post("/").then()
.statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("ValidationError"))
.body("ErrorResponse.Error.Message", equalTo("1 validation error detected: Value '"
+ (min - 1) + "' at 'maxItems' failed to satisfy constraint: "
.body("ErrorResponse.Error.Message", equalTo("1 validation error detected: "
+ "Value at 'maxItems' failed to satisfy constraint: "
+ "Member must have value greater than or equal to " + min));
listRequest(action, fixture, Integer.toString(max + 1), null).when().post("/").then()
.statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("ValidationError"))
.body("ErrorResponse.Error.Message", equalTo("1 validation error detected: Value '"
+ (max + 1) + "' at 'maxItems' failed to satisfy constraint: "
.body("ErrorResponse.Error.Message", equalTo("1 validation error detected: "
+ "Value at 'maxItems' failed to satisfy constraint: "
+ "Member must have value less than or equal to " + max));
List<String> all = walkFrom(action, paginator, fixture, Integer.toString(max), null);
@@ -18,8 +18,9 @@ import static org.hamcrest.Matchers.not;
* #6402 settled for this package.
*
* <p>{@code AttachRolePolicy}'s {@code RoleName} is the parity case rather than a change:
* {@code IamService.validateRoleName} already answered it in this form, from the same bounds and
* the same pattern, and the message is unchanged by the model taking it over.
* {@code IamService.validateRoleName} answers it from the same bounds and the same pattern, and
* both write the message IAM writes, which names the member with no value beside it: that is
* DRIFT-13's reading, and `docs/services/iam.md` carries it.
*/
@QuarkusTest
class IamRequestConstraintsIntegrationTest {
@@ -48,9 +49,8 @@ class IamRequestConstraintsIntegrationTest {
.formParam("PolicyArn", "arn:aws:iam::1:p/ab")
.when().post("/").then().statusCode(400)
.body(CODE, equalTo("ValidationError"))
.body(MESSAGE, equalTo("1 validation error detected: Value 'arn:aws:iam::1:p/ab' at"
+ " 'policyArn' failed to satisfy constraint: Member must have length greater"
+ " than or equal to 20"))
.body(MESSAGE, equalTo("1 validation error detected: Value at 'policyArn' failed to"
+ " satisfy constraint: Member must have length greater than or equal to 20"))
.body(not(containsString("NoSuchEntity")));
// The same ARN one character longer clears the constraint and reaches the lookup.
@@ -76,7 +76,7 @@ class IamRequestConstraintsIntegrationTest {
.formParam("PolicyArn", SHORTEST_ARN)
.formParam("VersionId", "1")
.when().post("/").then().statusCode(400)
.body(MESSAGE, equalTo("1 validation error detected: Value '1' at 'versionId' failed to"
.body(MESSAGE, equalTo("1 validation error detected: Value at 'versionId' failed to"
+ " satisfy constraint: Member must satisfy regular expression pattern:"
+ " v[1-9][0-9]*(\\.[A-Za-z0-9-]*)?"));
@@ -98,10 +98,10 @@ class IamRequestConstraintsIntegrationTest {
.formParam("PolicyArn", SHORTEST_ARN)
.formParam("PolicyDocument", "")
.when().post("/").then().statusCode(400)
.body(MESSAGE, containsString("2 validation errors detected: Value '' at"
.body(MESSAGE, containsString("2 validation errors detected: Value at"
+ " 'policyDocument' failed to satisfy constraint: Member must have length"
+ " greater than or equal to 1"))
.body(MESSAGE, containsString("Value '' at 'policyDocument' failed to satisfy"
.body(MESSAGE, containsString("Value at 'policyDocument' failed to satisfy"
+ " constraint: Member must satisfy regular expression pattern:"));
}
@@ -114,10 +114,10 @@ class IamRequestConstraintsIntegrationTest {
*/
@Test
void twoBrokenMembersAreReportedTogetherInTheModelsOrder() {
String expected = "2 validation errors detected: Value '" + "a".repeat(65) + "' at"
+ " 'userName' failed to satisfy constraint: Member must have length less than"
+ " or equal to 64; Value 'short' at 'policyArn' failed to satisfy constraint:"
+ " Member must have length greater than or equal to 20";
String expected = "2 validation errors detected: Value at 'userName' failed to satisfy"
+ " constraint: Member must have length less than or equal to 64; Value at"
+ " 'policyArn' failed to satisfy constraint: Member must have length greater"
+ " than or equal to 20";
iam("AttachUserPolicy")
.formParam("UserName", "a".repeat(65))
@@ -144,9 +144,9 @@ class IamRequestConstraintsIntegrationTest {
.formParam("PolicyArn", SHORTEST_ARN)
.when().post("/").then().statusCode(400)
.body(CODE, equalTo("ValidationError"))
.body(MESSAGE, equalTo("1 validation error detected: Value 'two words' at 'roleName'"
+ " failed to satisfy constraint: Member must satisfy regular expression"
+ " pattern: [\\w+=,.@-]+"));
.body(MESSAGE, equalTo("1 validation error detected: Value at 'roleName' failed to"
+ " satisfy constraint: Member must satisfy regular expression pattern:"
+ " [\\w+=,.@-]+"));
}
/**
@@ -170,9 +170,9 @@ class IamRequestConstraintsIntegrationTest {
.formParam("PolicyArn", SHORTEST_ARN)
.when().post("/").then().statusCode(400)
.body(CODE, equalTo("ValidationError"))
.body(MESSAGE, equalTo("2 validation errors detected: Value '' at 'roleName' failed to"
.body(MESSAGE, equalTo("2 validation errors detected: Value at 'roleName' failed to"
+ " satisfy constraint: Member must have length greater than or equal to 1;"
+ " Value '' at 'roleName' failed to satisfy constraint: Member must satisfy"
+ " Value at 'roleName' failed to satisfy constraint: Member must satisfy"
+ " regular expression pattern: [\\w+=,.@-]+"));
// The same empty name on an operation this wave leaves alone, reported the older way.
@@ -180,7 +180,7 @@ class IamRequestConstraintsIntegrationTest {
.formParam("RoleName", "")
.formParam("AssumeRolePolicyDocument", TRUST_POLICY)
.when().post("/").then().statusCode(400)
.body(MESSAGE, equalTo("1 validation error detected: Value '' at 'roleName' failed to"
.body(MESSAGE, equalTo("1 validation error detected: Value at 'roleName' failed to"
+ " satisfy constraint: Member must have length greater than or equal to 1"));
}
@@ -195,7 +195,7 @@ class IamRequestConstraintsIntegrationTest {
.formParam("RoleName", " ")
.formParam("PolicyArn", SHORTEST_ARN)
.when().post("/").then().statusCode(400)
.body(MESSAGE, equalTo("1 validation error detected: Value ' ' at 'roleName' failed to"
.body(MESSAGE, equalTo("1 validation error detected: Value at 'roleName' failed to"
+ " satisfy constraint: Member must satisfy regular expression pattern:"
+ " [\\w+=,.@-]+"));
}
@@ -244,9 +244,9 @@ class IamRequestConstraintsIntegrationTest {
.formParam("Filter.member.1", "Users")
.when().post("/").then().statusCode(400)
.body(CODE, equalTo("ValidationError"))
.body(MESSAGE, equalTo("1 validation error detected: Value 'Users' at"
+ " 'filter.1.member' failed to satisfy constraint: Member must satisfy enum"
+ " value set: [User, Role, Group, LocalManagedPolicy, AWSManagedPolicy]"));
.body(MESSAGE, equalTo("1 validation error detected: Value at 'filter.1.member'"
+ " failed to satisfy constraint: Member must satisfy enum value set:"
+ " [User, Role, Group, LocalManagedPolicy, AWSManagedPolicy]"));
iam("GetAccountAuthorizationDetails")
.formParam("Filter.member.1", "User")
@@ -265,9 +265,9 @@ class IamRequestConstraintsIntegrationTest {
.formParam("Filter.member.9", "Policies")
.when().post("/").then().statusCode(400)
.body(CODE, equalTo("ValidationError"))
.body(MESSAGE, containsString("2 validation errors detected: Value 'Users' at"
.body(MESSAGE, containsString("2 validation errors detected: Value at"
+ " 'filter.2.member'"))
.body(MESSAGE, containsString("Value 'Policies' at 'filter.9.member'"));
.body(MESSAGE, containsString("Value at 'filter.9.member'"));
}
/** {@code maxItemsType} is 1 to 1000, which this operation reads nothing of today. */
@@ -277,8 +277,8 @@ class IamRequestConstraintsIntegrationTest {
.formParam("MaxItems", "1001")
.when().post("/").then().statusCode(400)
.body(CODE, equalTo("ValidationError"))
.body(MESSAGE, equalTo("1 validation error detected: Value '1001' at 'maxItems' failed"
+ " to satisfy constraint: Member must have value less than or equal to 1000"));
.body(MESSAGE, equalTo("1 validation error detected: Value at 'maxItems' failed to"
+ " satisfy constraint: Member must have value less than or equal to 1000"));
iam("GetAccountAuthorizationDetails")
.formParam("MaxItems", "1000")
@@ -289,9 +289,8 @@ class IamRequestConstraintsIntegrationTest {
.formParam("MaxItems", "9223372036854775808")
.when().post("/").then().statusCode(400)
.body(CODE, equalTo("ValidationError"))
.body(MESSAGE, equalTo("1 validation error detected: Value '9223372036854775808' at"
+ " 'maxItems' failed to satisfy constraint: Member must have value less than"
+ " or equal to 1000"));
.body(MESSAGE, equalTo("1 validation error detected: Value at 'maxItems' failed to"
+ " satisfy constraint: Member must have value less than or equal to 1000"));
}
/** A marker sent empty breaks its minimum and its pattern, and both are reported. */
@@ -301,7 +300,7 @@ class IamRequestConstraintsIntegrationTest {
.formParam("Marker", "")
.when().post("/").then().statusCode(400)
.body(CODE, equalTo("ValidationError"))
.body(MESSAGE, containsString("2 validation errors detected: Value '' at 'marker'"
.body(MESSAGE, containsString("2 validation errors detected: Value at 'marker'"
+ " failed to satisfy constraint: Member must have length greater than or"
+ " equal to 1"))
.body(MESSAGE, containsString("Member must satisfy regular expression pattern:"));
@@ -286,6 +286,12 @@ class OrganizationsAccessReportIntegrationTest {
.body("ErrorResponse.Error.Code", equalTo("AccessDenied"));
}
/**
* The whole message rather than the code alone, because the form it takes is the thing worth
* pinning: this operation names the member with no value beside it, as every other IAM check
* does, and the member that never arrived is the one place a word still stands where a value
* would.
*/
@Test
void anEntityPathTheModelRejectsIsAValidationError() {
organizationWithScpsEnabled();
@@ -293,7 +299,23 @@ class OrganizationsAccessReportIntegrationTest {
iam(MANAGEMENT_ACCOUNT, "GenerateOrganizationsAccessReport")
.formParam("EntityPath", "o-a1b2c3d4e5")
.when().post("/").then().statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("ValidationError"));
.body("ErrorResponse.Error.Code", equalTo("ValidationError"))
.body("ErrorResponse.Error.Message", equalTo("1 validation error detected: Value at"
+ " 'entityPath' failed to satisfy constraint: Member must have length"
+ " greater than or equal to 19"));
iam(MANAGEMENT_ACCOUNT, "GenerateOrganizationsAccessReport")
.formParam("EntityPath", "o-a1b2c3d4e5/x-0000/not a path")
.when().post("/").then().statusCode(400)
.body("ErrorResponse.Error.Message", equalTo("1 validation error detected: Value at"
+ " 'entityPath' failed to satisfy constraint: Member must satisfy regular"
+ " expression pattern: ^o-[0-9a-z]{10,32}\\/r-[0-9a-z]{4,32}[0-9a-z-\\/]*"));
iam(MANAGEMENT_ACCOUNT, "GenerateOrganizationsAccessReport")
.when().post("/").then().statusCode(400)
.body("ErrorResponse.Error.Message", equalTo("1 validation error detected: Value"
+ " null at 'entityPath' failed to satisfy constraint: Member must not be"
+ " null"));
}
@Test
@@ -491,7 +513,7 @@ class OrganizationsAccessReportIntegrationTest {
.statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("ValidationError"))
.body("ErrorResponse.Error.Message", equalTo(
"1 validation error detected: Value '1001' at 'maxItems' failed to satisfy "
"1 validation error detected: Value at 'maxItems' failed to satisfy "
+ "constraint: Member must have value less than or equal to 1000"));
}
}
@@ -806,7 +806,7 @@ class ServiceLastAccessedIntegrationTest {
.statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("ValidationError"))
.body("ErrorResponse.Error.Message", equalTo(
"1 validation error detected: Value '0' at 'maxItems' failed to satisfy "
"1 validation error detected: Value at 'maxItems' failed to satisfy "
+ "constraint: Member must have value greater than or equal to 1"));
}
@@ -1035,7 +1035,7 @@ class ServiceLastAccessedIntegrationTest {
// broke: an over-large MaxItems says nothing about the minimum. Asserted on the parsed
// element because the raw body escapes the quotes as &apos;.
.body("ErrorResponse.Error.Message", equalTo(
"1 validation error detected: Value '1001' at 'maxItems' failed to satisfy "
"1 validation error detected: Value at 'maxItems' failed to satisfy "
+ "constraint: Member must have value less than or equal to 1000"));
}