mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(iam): open every ValidationError with the count AWS puts on it (#5280)
hectorvent asked on #5240 whether the account-property constraint messages should carry the "1 validation error detected: " prefix that #5239's two recorded messages have, noting there is no recording for PutAccountProperties itself. There is evidence, just not on that operation. Across the AWS-validated snapshots for IAM, CloudWatch and SNS, every recorded constraint message opens with the count: six of six. The prefix is the envelope the front end puts on a validation report, not a property of the member being validated, and SNS settles the part the question turned on, because two of its recordings are map members and both carry it: 1 validation error detected: Value null at 'attributes' failed to satisfy constraint: Member must not be null 1 validation error detected: Value null at 'messageAttributes.attr1.member.dataType' failed to satisfy constraint: Member must not be null The first of those is this change's absent-map case almost verbatim, down to "Value null at '<map>'". Looking for that turned up something wider than the question. IamQueryHandler's requireParam, which every required member in the service is read through, emitted its message without the prefix, while StsQueryHandler's validateRequired in the same package and TagDispatcher in core.common both already carry it on the identical sentence. IAM was the outlier, so one line fixes all 28 call sites. The five messages here are the four on the account-properties path and that one. Each was probed by reverting it on its own, and each fails only the tests that cover it. Three more constraint reports were still opening without the count, so the title did not hold when it was written: the ListPolicies scope enum, the GenerateServiceLastAccessedDetails granularity enum, and optionalInt. No test pinned any of their text, which is how they survived a change that touched every other one. A fourth, the CredentialAgeDays range check, survived a sweep for that phrase because its message builds "failed to " and "satisfy constraint" as separate literals, so the phrase never appears contiguously in the source. The sweep now joins adjacent literals before matching, which finds that one and no others. optionalInt is reachable only through CredentialAgeDays on CreateServiceSpecificCredential, so its case sits beside the test that already exercises that path and asserted only the error code. Two things deliberately left as they are. No snapshot in any service records a map *key* constraint, so the "Map keys must satisfy constraint: [...]" tail is a reasonable shape rather than an attested one, and the same goes for how a string-valued map spells its value path. The prefix is the attested part and the only part this changes. Not touched either: CloudWatch's recorded enum message names both the offending value and the permitted set, where IAM's omits both. That they differ is the point, and it is why #5239 changed only IAM's rendering. Refs #5240
This commit is contained in:
1 parent
9c2db353f1
commit
88d429a968
7 files changed
+94
-27
No files matched your search
@@ -558,6 +558,13 @@ published pattern, which admits a key with no slash, with several, and with a tr
|
||||
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.
|
||||
|
||||
Each `ValidationError` here opens with "1 validation error detected: ", which is the envelope the
|
||||
IAM front end puts on a constraint report rather than anything specific to this operation. Every
|
||||
such message recorded against AWS carries it, including on map members: SNS's recordings show
|
||||
`Value null at 'attributes'` and `Value null at 'messageAttributes.attr1.member.dataType'` both
|
||||
prefixed. What is not recorded anywhere is how AWS spells a map *key* constraint, so the
|
||||
"Map keys must satisfy constraint" tail is a reasonable shape rather than an attested one.
|
||||
|
||||
**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
|
||||
|
||||
@@ -903,9 +903,9 @@ public class IamQueryHandler {
|
||||
return Integer.valueOf(raw.trim());
|
||||
} catch (NumberFormatException e) {
|
||||
throw new AwsException("ValidationError",
|
||||
"Value '" + raw + "' at '" + Character.toLowerCase(name.charAt(0))
|
||||
+ name.substring(1) + "' failed to satisfy constraint: Member must be "
|
||||
+ "an integer", 400);
|
||||
"1 validation error detected: Value '" + raw + "' at '"
|
||||
+ Character.toLowerCase(name.charAt(0)) + name.substring(1)
|
||||
+ "' failed to satisfy constraint: Member must be an integer", 400);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2913,7 +2913,8 @@ public class IamQueryHandler {
|
||||
String value = params.getFirst(name);
|
||||
if (value == null || value.isBlank()) {
|
||||
throw new AwsException("ValidationError",
|
||||
"Value null at '" + Character.toLowerCase(name.charAt(0)) + name.substring(1)
|
||||
"1 validation error detected: Value null at '"
|
||||
+ Character.toLowerCase(name.charAt(0)) + name.substring(1)
|
||||
+ "' failed to satisfy constraint: Member must not be null", 400);
|
||||
}
|
||||
return value;
|
||||
|
||||
@@ -1419,8 +1419,9 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
|
||||
&& !"AWS".equalsIgnoreCase(scope)
|
||||
&& !"Local".equalsIgnoreCase(scope)) {
|
||||
throw new AwsException("ValidationError",
|
||||
"Value '" + scope + "' at 'scope' failed to satisfy constraint: "
|
||||
+ "Member must satisfy enum value set: [All, AWS, Local]", 400);
|
||||
"1 validation error detected: Value '" + scope + "' at 'scope' failed to "
|
||||
+ "satisfy constraint: Member must satisfy enum value set: "
|
||||
+ "[All, AWS, Local]", 400);
|
||||
}
|
||||
String prefix = pathPrefix != null ? pathPrefix : "/";
|
||||
boolean blankScope = scope == null || scope.isBlank();
|
||||
@@ -2327,8 +2328,8 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
|
||||
public void putAccountProperties(Map<String, String> properties) {
|
||||
if (properties == null || properties.isEmpty()) {
|
||||
throw new AwsException("ValidationError",
|
||||
"Value null at 'properties' failed to satisfy constraint: Member must not be "
|
||||
+ "null", 400);
|
||||
"1 validation error detected: Value null at 'properties' failed to "
|
||||
+ "satisfy constraint: Member must not be null", 400);
|
||||
}
|
||||
String namespace = null;
|
||||
for (Map.Entry<String, String> entry : properties.entrySet()) {
|
||||
@@ -2365,7 +2366,8 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
|
||||
if (key == null || key.isEmpty() || key.length() > MAX_ACCOUNT_PROPERTY_KEY_LENGTH
|
||||
|| !ACCOUNT_PROPERTY_KEY_PATTERN.matcher(key).matches()) {
|
||||
throw new AwsException("ValidationError",
|
||||
"Value '" + key + "' at 'properties' failed to satisfy constraint: Map keys "
|
||||
"1 validation error detected: 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 "
|
||||
+ "satisfy regular expression pattern: "
|
||||
@@ -2385,9 +2387,9 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
|
||||
if (value == null || value.isEmpty()
|
||||
|| value.length() > MAX_ACCOUNT_PROPERTY_VALUE_LENGTH) {
|
||||
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);
|
||||
"1 validation error detected: Value at 'properties." + key + "' failed to "
|
||||
+ "satisfy constraint: Member must have length between 1 and "
|
||||
+ MAX_ACCOUNT_PROPERTY_VALUE_LENGTH, 400);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2396,8 +2398,9 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
|
||||
if (globalEndpointTokenVersion == null
|
||||
|| !GLOBAL_ENDPOINT_TOKEN_VERSIONS.contains(globalEndpointTokenVersion)) {
|
||||
throw new AwsException("ValidationError",
|
||||
"Value '" + globalEndpointTokenVersion + "' at 'globalEndpointTokenVersion' "
|
||||
+ "failed to satisfy constraint: Member must satisfy enum value set: ["
|
||||
"1 validation error detected: Value '" + globalEndpointTokenVersion
|
||||
+ "' at 'globalEndpointTokenVersion' failed to satisfy constraint: "
|
||||
+ "Member must satisfy enum value set: ["
|
||||
+ String.join(", ", GLOBAL_ENDPOINT_TOKEN_VERSIONS) + "]", 400);
|
||||
}
|
||||
stsPreferences.put(STS_PREFERENCES_KEY, globalEndpointTokenVersion);
|
||||
@@ -3095,10 +3098,10 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
|
||||
if (credentialAgeDays < MIN_CREDENTIAL_AGE_DAYS
|
||||
|| credentialAgeDays > MAX_CREDENTIAL_AGE_DAYS) {
|
||||
throw new AwsException("ValidationError",
|
||||
"Value '" + credentialAgeDays + "' at 'credentialAgeDays' failed to "
|
||||
+ "satisfy constraint: Member must be between "
|
||||
+ MIN_CREDENTIAL_AGE_DAYS + " and " + MAX_CREDENTIAL_AGE_DAYS,
|
||||
400);
|
||||
"1 validation error detected: Value '" + credentialAgeDays
|
||||
+ "' at 'credentialAgeDays' failed to satisfy constraint: "
|
||||
+ "Member must be between " + MIN_CREDENTIAL_AGE_DAYS + " and "
|
||||
+ MAX_CREDENTIAL_AGE_DAYS, 400);
|
||||
}
|
||||
}
|
||||
synchronized (serviceCredentialLock) {
|
||||
|
||||
+3
-2
@@ -59,8 +59,9 @@ public class ServiceLastAccessedService {
|
||||
List<ServiceLastAccessedEntity> entities) {
|
||||
if (granularity != null && !GRANULARITIES.contains(granularity)) {
|
||||
throw new AwsException("ValidationError",
|
||||
"Value '" + granularity + "' at 'granularity' failed to satisfy constraint: "
|
||||
+ "Member must satisfy enum value set: [SERVICE_LEVEL, ACTION_LEVEL]", 400);
|
||||
"1 validation error detected: Value '" + granularity + "' at 'granularity' "
|
||||
+ "failed to satisfy constraint: Member must satisfy enum value set: "
|
||||
+ "[SERVICE_LEVEL, ACTION_LEVEL]", 400);
|
||||
}
|
||||
Instant now = Instant.now();
|
||||
// jobIDType is min 36 / max 36, which is exactly a UUID string.
|
||||
|
||||
+20
-5
@@ -94,7 +94,8 @@ class AccountPropertiesIntegrationTest {
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("ValidationError"))
|
||||
.body(not(containsString("InvalidInput")))
|
||||
.body(containsString("failed to satisfy constraint"));
|
||||
.body(containsString("failed to satisfy constraint"))
|
||||
.body(containsString("1 validation error detected"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,13 +127,17 @@ 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("ValidationError"));
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("ValidationError"))
|
||||
.body(containsString("1 validation error detected"));
|
||||
|
||||
// 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("ValidationError"));
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("ValidationError"))
|
||||
.body(containsString("1 validation error detected"));
|
||||
|
||||
// And the top of the range is accepted, so the bound is not off by one.
|
||||
iam("PutAccountProperties")
|
||||
@@ -144,7 +149,16 @@ class AccountPropertiesIntegrationTest {
|
||||
@Test
|
||||
void anAbsentPropertiesMapIsRejected() {
|
||||
iam("PutAccountProperties").when().post("/").then().statusCode(400)
|
||||
.body(containsString("ValidationError"));
|
||||
.body(containsString("ValidationError"))
|
||||
// Recorded against AWS on SNS's own map member, down to the phrasing:
|
||||
// "1 validation error detected: Value null at 'attributes' failed to satisfy
|
||||
// constraint: Member must not be null".
|
||||
.body(containsString("1 validation error detected"))
|
||||
// The apostrophes around the member name come back XML-escaped, so the assertion
|
||||
// stops at the parts that survive escaping.
|
||||
.body(containsString("Value null at "))
|
||||
.body(containsString("properties"))
|
||||
.body(containsString("Member must not be null"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -159,7 +173,8 @@ class AccountPropertiesIntegrationTest {
|
||||
iam("SetSecurityTokenServicePreferences")
|
||||
.formParam("GlobalEndpointTokenVersion", version)
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("ValidationError"));
|
||||
.body(containsString("ValidationError"))
|
||||
.body(containsString("1 validation error detected"));
|
||||
}
|
||||
|
||||
iam("SetSecurityTokenServicePreferences").when().post("/").then().statusCode(400)
|
||||
|
||||
+28
@@ -1081,4 +1081,32 @@ class ServiceLastAccessedIntegrationTest {
|
||||
.statusCode(200)
|
||||
.body(containsString("ListPoliciesGrantingServiceAccessResponse"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Two of the three constraint reports that were still opening without the count. The third,
|
||||
* {@code optionalInt}, is reached only through CredentialAgeDays and is pinned beside the test
|
||||
* that already exercises it. None of their text was pinned before, which is why they survived
|
||||
* a change that touched every other one.
|
||||
*/
|
||||
@Test
|
||||
void theRemainingEnumReportsAlsoOpenWithTheCount() {
|
||||
// GenerateServiceLastAccessedDetails: the Granularity enum. The ARN has to resolve first,
|
||||
// because the handler looks the target up before the granularity is checked, so a
|
||||
// nonexistent one answers NoSuchEntity and never reaches it.
|
||||
String arn = createUser("granularity-" + suffix());
|
||||
iam("GenerateServiceLastAccessedDetails")
|
||||
.formParam("Arn", arn)
|
||||
.formParam("Granularity", "HOURLY")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("ValidationError"))
|
||||
.body(containsString("1 validation error detected"))
|
||||
.body(containsString("Member must satisfy enum value set"));
|
||||
|
||||
// ListPolicies: the Scope enum.
|
||||
iam("ListPolicies").formParam("Scope", "Everything")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("ValidationError"))
|
||||
.body(containsString("1 validation error detected"))
|
||||
.body(containsString("Member must satisfy enum value set"));
|
||||
}
|
||||
}
|
||||
+14
-2
@@ -202,6 +202,10 @@ class ServiceSpecificCredentialIntegrationTest {
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("ValidationError"))
|
||||
.body(containsString("credentialAgeDays"))
|
||||
// optionalInt's report is the last IAM constraint message that was opening
|
||||
// without the count, and this is the only path that reaches it.
|
||||
.body(containsString("1 validation error detected"))
|
||||
.body(containsString("Member must be an integer"))
|
||||
.body(not(containsString("ExpirationDate")));
|
||||
}
|
||||
}
|
||||
@@ -216,7 +220,11 @@ class ServiceSpecificCredentialIntegrationTest {
|
||||
.formParam("CredentialAgeDays", days)
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("ValidationError"))
|
||||
.body(containsString("credentialAgeDays"));
|
||||
.body(containsString("credentialAgeDays"))
|
||||
// The range report builds its message across two string literals, so a sweep
|
||||
// for the phrase missed it while every other one was prefixed.
|
||||
.body(containsString("1 validation error detected"))
|
||||
.body(containsString("Member must be between"));
|
||||
}
|
||||
|
||||
// And both ends of the range are accepted, so the bounds are not off by one.
|
||||
@@ -600,7 +608,11 @@ class ServiceSpecificCredentialIntegrationTest {
|
||||
iam("DeleteServiceSpecificCredential").formParam("UserName", userName)
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("ValidationError"))
|
||||
.body(containsString("serviceSpecificCredentialId"));
|
||||
.body(containsString("serviceSpecificCredentialId"))
|
||||
// requireParam serves every required IAM member, so this is the one place the
|
||||
// counted prefix on an absent-member message is worth pinning.
|
||||
.body(containsString("1 validation error detected"))
|
||||
.body(containsString("Member must not be null"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user