fix(iam): hold an account property value to what its key publishes (#9330)

PutAccountProperties stored any value the declared length admitted, so role
manager's switch took one nothing can read as a flag. The operation's own
Properties member says "the service validates each value based on the property
key's expected type. For example, boolean properties expect true or false", and
one property has its type published: role manager is "controlled by the
account-level property RoleManager/Enabled", where "a value of true enables role
manager; false disables it". Both spellings are lowercase on every page that
writes them, the guide's CLI examples, the API Reference's instruction to set
the property "to true or false", and the response in its own example.

That property now takes those two values and nothing else, answering
InvalidInput 400 with "Property <key> expects true or false: <value>", the value
as the request sent it. The sentence is this package's own, AWS publishing that
a value is validated against its key's type and nothing of what it answers when
one is not. The 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.

What is held is the pair of values rather than a type, since a type is what this
would be inventing: the pair is what AWS publishes for the property. Every other
property keeps taking any value of the declared length, no page saying what any
of them is for, which is the looser answer and the direction to be wrong in. The
key is read before the value, a value's type being the key's to say, so a
request naming an unrecognised namespace is still answered for the namespace.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-24 00:27:07 -04:00
1 parent 1056fedc22
commit b035e1d37b
4 files changed
+155 -5

No files matched your search

@@ -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".
*
* <p>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."
*
@@ -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<String, String> 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"));
}
}