diff --git a/docs/services/iam.md b/docs/services/iam.md index 039597880d..6c7bbac247 100644 --- a/docs/services/iam.md +++ b/docs/services/iam.md @@ -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 diff --git a/src/main/java/io/github/hectorvent/floci/services/iam/IamQueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/iam/IamQueryHandler.java index 34ef9b79bc..2d19d93489 100644 --- a/src/main/java/io/github/hectorvent/floci/services/iam/IamQueryHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/iam/IamQueryHandler.java @@ -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; diff --git a/src/main/java/io/github/hectorvent/floci/services/iam/IamService.java b/src/main/java/io/github/hectorvent/floci/services/iam/IamService.java index bd38d1078d..84eef44d6b 100644 --- a/src/main/java/io/github/hectorvent/floci/services/iam/IamService.java +++ b/src/main/java/io/github/hectorvent/floci/services/iam/IamService.java @@ -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 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 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) { diff --git a/src/main/java/io/github/hectorvent/floci/services/iam/ServiceLastAccessedService.java b/src/main/java/io/github/hectorvent/floci/services/iam/ServiceLastAccessedService.java index 1dcc40f541..670c40dd25 100644 --- a/src/main/java/io/github/hectorvent/floci/services/iam/ServiceLastAccessedService.java +++ b/src/main/java/io/github/hectorvent/floci/services/iam/ServiceLastAccessedService.java @@ -59,8 +59,9 @@ public class ServiceLastAccessedService { List 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. diff --git a/src/test/java/io/github/hectorvent/floci/services/iam/AccountPropertiesIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/iam/AccountPropertiesIntegrationTest.java index 45ab1e117e..857fbfd18b 100644 --- a/src/test/java/io/github/hectorvent/floci/services/iam/AccountPropertiesIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/iam/AccountPropertiesIntegrationTest.java @@ -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) diff --git a/src/test/java/io/github/hectorvent/floci/services/iam/ServiceLastAccessedIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/iam/ServiceLastAccessedIntegrationTest.java index a98334bcff..ac5aa980a4 100644 --- a/src/test/java/io/github/hectorvent/floci/services/iam/ServiceLastAccessedIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/iam/ServiceLastAccessedIntegrationTest.java @@ -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")); + } } diff --git a/src/test/java/io/github/hectorvent/floci/services/iam/ServiceSpecificCredentialIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/iam/ServiceSpecificCredentialIntegrationTest.java index 2e2cf452d1..f815fde783 100644 --- a/src/test/java/io/github/hectorvent/floci/services/iam/ServiceSpecificCredentialIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/iam/ServiceSpecificCredentialIntegrationTest.java @@ -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")); } /**