diff --git a/docs/services/iam.md b/docs/services/iam.md index 628a6b12e5..02a67aae39 100644 --- a/docs/services/iam.md +++ b/docs/services/iam.md @@ -1874,6 +1874,29 @@ mixing them even when neither is recognised, because a request names one namespa a namespace to look up; that order is also the one that leaves every request already being refused with the answer it already had. +### What a bad account property value answers + +The value is the key's business: "the service validates each value based on the property key's +expected type. For example, boolean properties expect `true` or `false`." So a value is held to +what its key publishes, after the key itself has been read, and only one property publishes +anything. Role manager is "controlled by the account-level property `RoleManager/Enabled`", where +"a value of true enables role manager; false disables it"; the API Reference says to call the +operation "with the `RoleManager/Enabled` property set to true or false", and its own example +response carries `true`. Both spellings are lowercase on every page that writes them, the guide's +two CLI examples included. + +That property takes those two values and nothing else, answering `InvalidInput` 400 with +`Property expects true or false: `, the value as the request sent it. The sentence is +this package's own: AWS publishes that a value is validated against its key's type and nothing of +what it answers when one is not. A request is refused whole, so an entry beside the bad one is not +stored either, which is how a request refused for its keys already behaves. Storing the value +instead left a flag holding something nothing can read as one, under the key AWS gives the feature. + +What is held this way is the pair of values rather than a type, because a type is the thing this +would be inventing: what AWS publishes for this property is `true` and `false`. Every other +property takes any value the declared length admits, since no page says what any of them is for, +which is the looser answer and the direction to be wrong in here. + ### Organizations Root Access | Action | Description | diff --git a/src/main/java/io/floci/aws/services/iam/IamService.java b/src/main/java/io/floci/aws/services/iam/IamService.java index 3f914cb3b4..a37e206d43 100644 --- a/src/main/java/io/floci/aws/services/iam/IamService.java +++ b/src/main/java/io/floci/aws/services/iam/IamService.java @@ -233,6 +233,25 @@ public class IamService implements SessionAccountLookup, ResourceProvider { * AWS was recorded giving at all; see {@link #putAccountProperties}. */ private static final Set ACCOUNT_PROPERTY_NAMESPACES = Set.of("RoleManager"); + /** + * The values each account property AWS publishes a type for takes, which is one property. + * + *

{@code Properties} says that "the service validates each value based on the property + * key's expected type. For example, boolean properties expect true or false", and the only + * property whose type is written down anywhere is role manager's switch: the feature is + * "controlled by the account-level property RoleManager/Enabled", where "a value of true + * enables role manager; false disables it". Both spellings are lowercase everywhere they are + * written, in the guide's two CLI examples, in the API Reference's instruction to call this + * operation "with the RoleManager/Enabled property set to true or false", and in the response + * its own example shows. + * + *

The published values are kept rather than a type, since a type is a thing this would be + * inventing: what AWS publishes for this property is the pair. A key absent from here takes + * any value the declared length admits, which is the looser answer where nothing says what the + * property is for. + */ + private static final Map> ACCOUNT_PROPERTY_VALUES = + Map.of("RoleManager/Enabled", List.of("true", "false")); /** AWS-documented bounds for the account password policy's numeric fields. */ /** * AWS's documented {@code passwordType} pattern for Create/UpdateLoginProfile: printable @@ -3737,11 +3756,16 @@ public class IamService implements SessionAccountLookup, ResourceProvider { * property as it was. Storing the property instead left the account holding a key AWS never * accepted, with the caller never told, and a later read reporting it. * - *

The two refusals are in that order, so a request naming two namespaces is answered for - * mixing them whether or not either is recognised: a request names one namespace before there - * is a namespace to look up. Which one AWS answers first is not recorded, so the order is this - * package's reading, and it is the one that leaves every request already being refused with - * the answer it already had. + *

A value is then held to what its key publishes, where its key publishes anything: "the + * service validates each value based on the property key's expected type". Only the key says + * what a value may be, so the key is read first, and a request is refused whole here as it is + * for its keys, since a property a request was refused for cannot be left stored. + * + *

The refusals are in that order, so a request naming two namespaces is answered for mixing + * them whether or not either is recognised: a request names one namespace before there is a + * namespace to look up, and a value's type before that. Which one AWS answers first is not + * recorded, so the order is this package's reading, and it is the one that leaves every + * request already being refused with the answer it already had. */ public void putAccountProperties(Map properties) { if (properties == null || properties.isEmpty()) { @@ -3765,6 +3789,17 @@ public class IamService implements SessionAccountLookup, ResourceProvider { // published and nothing says how AWS reads its case. throw new AwsException("InvalidInput", "Unsupported namespace: " + namespace, 400); } + for (Map.Entry entry : properties.entrySet()) { + List published = ACCOUNT_PROPERTY_VALUES.get(entry.getKey()); + if (published != null && !published.contains(entry.getValue())) { + // This package's own sentence: AWS publishes that a value is validated against its + // key's type and nothing of what it answers when one is not. It names the key and + // carries the value as the request sent it, as the refusals above carry theirs, + // and the values in the order every page writes them. + throw new AwsException("InvalidInput", "Property " + entry.getKey() + " expects " + + String.join(" or ", published) + ": " + entry.getValue(), 400); + } + } synchronized (accountPropertiesLock) { for (Map.Entry entry : properties.entrySet()) { accountProperties.put(entry.getKey(), entry.getValue()); diff --git a/src/test/java/io/floci/aws/services/iam/AccountPropertiesIntegrationTest.java b/src/test/java/io/floci/aws/services/iam/AccountPropertiesIntegrationTest.java index f30a36776b..fe4e14f410 100644 --- a/src/test/java/io/floci/aws/services/iam/AccountPropertiesIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/iam/AccountPropertiesIntegrationTest.java @@ -108,6 +108,68 @@ class AccountPropertiesIntegrationTest { .body(containsString("Unsupported namespace: rolemanager")); } + /** + * The one property AWS publishes a type for takes the two values it publishes and nothing else: + * role manager is "controlled by the account-level property RoleManager/Enabled", where "a + * value of true enables role manager; false disables it", and the member says "the service + * validates each value based on the property key's expected type". + * + *

The spellings are the ones every page writes, so a capitalised or numeric flag is refused + * rather than stored under a switch nothing could read. What AWS answers for such a value is + * published nowhere, so the sentence is this package's own and it is pinned here. + */ + @Test + void theOnePropertyWithAPublishedTypeTakesOnlyTheValuesItPublishes() { + for (String value : List.of("true", "false")) { + iam("PutAccountProperties") + .formParam("Properties.entry.1.key", "RoleManager/Enabled") + .formParam("Properties.entry.1.value", value) + .when().post("/").then().statusCode(200); + } + + for (String value : List.of("yes", "True", "1", "TRUE")) { + iam("PutAccountProperties") + .formParam("Properties.entry.1.key", "RoleManager/Enabled") + .formParam("Properties.entry.1.value", value) + .when().post("/").then().statusCode(400) + .body(containsString("InvalidInput")) + .body(not(containsString("ValidationError"))) + .body(containsString("Property RoleManager/Enabled expects true or false: " + value)); + } + + iam("GetAccountProperties").when().post("/").then().statusCode(200) + .body(containsString("RoleManager/Enabled")); + } + + /** + * A property whose type no page gives takes any value its declared length admits, which is the + * looser answer where nothing says what the property is for, and a request refused for the + * typed property stores neither of its entries. + */ + @Test + void aPropertyWithNoPublishedTypeTakesAnyValueAndARefusedRequestStoresNothing() { + String freeform = key("Freeform"); + + iam("PutAccountProperties") + .formParam("Properties.entry.1.key", freeform) + .formParam("Properties.entry.1.value", "whatever it likes") + .when().post("/").then().statusCode(200); + + String alongside = key("Alongside"); + + iam("PutAccountProperties") + .formParam("Properties.entry.1.key", alongside) + .formParam("Properties.entry.1.value", "stored only if the request is") + .formParam("Properties.entry.2.key", "RoleManager/Enabled") + .formParam("Properties.entry.2.value", "maybe") + .when().post("/").then().statusCode(400) + .body(containsString("Property RoleManager/Enabled expects true or false: maybe")); + + iam("GetAccountProperties").when().post("/").then().statusCode(200) + .body(containsString(freeform)) + .body(not(containsString(alongside))); + } + /** * "All keys must belong to the same namespace." * diff --git a/src/test/java/io/floci/aws/services/iam/AccountPropertiesStateTest.java b/src/test/java/io/floci/aws/services/iam/AccountPropertiesStateTest.java index bf2bd1607b..a7322cc782 100644 --- a/src/test/java/io/floci/aws/services/iam/AccountPropertiesStateTest.java +++ b/src/test/java/io/floci/aws/services/iam/AccountPropertiesStateTest.java @@ -260,4 +260,34 @@ class AccountPropertiesStateTest { assertEquals(Map.of("RoleManager/Kept", "yes"), service.getAccountProperties(), "the refused key may not have landed"); } + + /** + * A value outside what its key publishes is refused and nothing of that request is written, + * the entry beside it included: "the service validates each value based on the property key's + * expected type", and role manager's switch is the one property whose type is published, "a + * value of true enables role manager; false disables it". This is the state half of that + * refusal, which the wire test cannot see past the response. + */ + @Test + void aValueOutsideWhatItsKeyPublishesWritesNothing() { + IamService service = inMemory(ACCOUNT_A); + service.putAccountProperties(Map.of("RoleManager/Enabled", "true")); + + Map refusedRequest = new LinkedHashMap<>(); + refusedRequest.put("RoleManager/Mode", "strict"); + refusedRequest.put("RoleManager/Enabled", "maybe"); + AwsException refused = assertThrows(AwsException.class, + () -> service.putAccountProperties(refusedRequest)); + + assertEquals("InvalidInput", refused.getErrorCode()); + assertEquals(400, refused.getHttpStatus()); + assertEquals("Property RoleManager/Enabled expects true or false: maybe", + refused.getMessage()); + assertEquals(Map.of("RoleManager/Enabled", "true"), service.getAccountProperties(), + "neither entry of the refused request may have landed, and the flag keeps its value"); + + // A property with no published type takes the value as it comes. + service.putAccountProperties(Map.of("RoleManager/Mode", "strict")); + assertEquals("strict", service.getAccountProperties().get("RoleManager/Mode")); + } }