fix(iam): implement UpdateAccountPasswordPolicy, Get and Delete (#2616)

* fix(iam): implement UpdateAccountPasswordPolicy, Get and Delete

IAM's UpdateAccountPasswordPolicy returned UnsupportedOperation, blocking
the aws_iam_account_password_policy Terraform resource. Mirrors the
existing account-alias trio's storage shape: a single stored value per
account, replaced wholesale rather than merged on update, NoSuchEntity
from Get/Delete when nothing has ever been set.

floci-ge4

* fix(iam): reject malformed boolean values in UpdateAccountPasswordPolicy

Malformed booleans such as RequireSymbols=banana were silently coerced
to false and persisted instead of being rejected. Boolean parameters
now accept only true/false (case-insensitive) and return
ValidationError otherwise, matching the existing numeric-parameter
validation.

* fix(iam): default HardExpiry to false and reject malformed integers

HardExpiry now always appears in GetAccountPasswordPolicy and
UpdateAccountPasswordPolicy responses, defaulting to false when the
caller omits it, matching AWS's documented boolean default instead of
omitting the element entirely (a permanent Terraform diff otherwise).
MaxPasswordAge and PasswordReusePrevention keep their existing
absent-when-unset behavior.

MinimumPasswordLength now goes through a new strict integer parser
(getStrictIntParam) mirroring the existing strict boolean helper, so a
non-numeric value returns ValidationError instead of silently falling
back to the field's default and succeeding with 200.
MaxPasswordAge/PasswordReusePrevention already rejected malformed
values via getOptionalIntParam.
This commit is contained in:
Allen Sanborn authored and GitHub committed 2026-08-27 13:01:05 -04:00
1 parent 4435c62848
commit f411a316a2
7 files changed
+590 -2

No files matched your search

@@ -0,0 +1,305 @@
package io.github.hectorvent.floci.services.iam;
import io.github.hectorvent.floci.core.common.AwsQueryController;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
/**
* Integration tests for the IAM account password policy via the Query Protocol, covering the full
* HTTP stack through {@link AwsQueryController} → {@link IamQueryHandler}.
*
* <p>Ordered: the policy is a single per-account value, so these cases share state deliberately —
* missing before any update, get-after-update, wholesale replace, range rejection, delete.
*/
@QuarkusTest
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class IamAccountPasswordPolicyIntegrationTest {
// The Query-protocol controller resolves the target service from the credential scope,
// so every IAM call carries one.
private static final String IAM_CREDENTIAL =
"AWS4-HMAC-SHA256 Credential=test/20260227/us-east-1/iam/aws4_request";
@Test
@Order(1)
void getBeforeAnyUpdateIsNoSuchEntity() {
given()
.formParam("Action", "GetAccountPasswordPolicy")
.header("Authorization", IAM_CREDENTIAL)
.when()
.post("/")
.then()
.statusCode(404)
.body("ErrorResponse.Error.Code", equalTo("NoSuchEntity"));
}
@Test
@Order(2)
void deleteBeforeAnyUpdateIsNoSuchEntity() {
given()
.formParam("Action", "DeleteAccountPasswordPolicy")
.header("Authorization", IAM_CREDENTIAL)
.when()
.post("/")
.then()
.statusCode(404)
.body("ErrorResponse.Error.Code", equalTo("NoSuchEntity"));
}
@Test
@Order(3)
void updateSetsThePolicy() {
given()
.formParam("Action", "UpdateAccountPasswordPolicy")
.formParam("MinimumPasswordLength", "12")
.formParam("RequireSymbols", "true")
.formParam("RequireNumbers", "true")
.formParam("RequireUppercaseCharacters", "true")
.formParam("RequireLowercaseCharacters", "true")
.formParam("AllowUsersToChangePassword", "true")
.formParam("MaxPasswordAge", "90")
.formParam("PasswordReusePrevention", "5")
.formParam("HardExpiry", "true")
.header("Authorization", IAM_CREDENTIAL)
.when()
.post("/")
.then()
.statusCode(200)
.contentType("application/xml");
}
@Test
@Order(4)
void getReturnsThePolicyJustSet() {
given()
.formParam("Action", "GetAccountPasswordPolicy")
.header("Authorization", IAM_CREDENTIAL)
.when()
.post("/")
.then()
.statusCode(200)
.body("GetAccountPasswordPolicyResponse.GetAccountPasswordPolicyResult.PasswordPolicy."
+ "MinimumPasswordLength", equalTo("12"))
.body("GetAccountPasswordPolicyResponse.GetAccountPasswordPolicyResult.PasswordPolicy."
+ "RequireSymbols", equalTo("true"))
.body("GetAccountPasswordPolicyResponse.GetAccountPasswordPolicyResult.PasswordPolicy."
+ "RequireNumbers", equalTo("true"))
.body("GetAccountPasswordPolicyResponse.GetAccountPasswordPolicyResult.PasswordPolicy."
+ "RequireUppercaseCharacters", equalTo("true"))
.body("GetAccountPasswordPolicyResponse.GetAccountPasswordPolicyResult.PasswordPolicy."
+ "RequireLowercaseCharacters", equalTo("true"))
.body("GetAccountPasswordPolicyResponse.GetAccountPasswordPolicyResult.PasswordPolicy."
+ "AllowUsersToChangePassword", equalTo("true"))
.body("GetAccountPasswordPolicyResponse.GetAccountPasswordPolicyResult.PasswordPolicy."
+ "ExpirePasswords", equalTo("true"))
.body("GetAccountPasswordPolicyResponse.GetAccountPasswordPolicyResult.PasswordPolicy."
+ "MaxPasswordAge", equalTo("90"))
.body("GetAccountPasswordPolicyResponse.GetAccountPasswordPolicyResult.PasswordPolicy."
+ "PasswordReusePrevention", equalTo("5"))
.body("GetAccountPasswordPolicyResponse.GetAccountPasswordPolicyResult.PasswordPolicy."
+ "HardExpiry", equalTo("true"));
}
@Test
@Order(5)
void updateReplacesTheEntirePolicyRatherThanMerging() {
given()
.formParam("Action", "UpdateAccountPasswordPolicy")
.formParam("MinimumPasswordLength", "8")
.header("Authorization", IAM_CREDENTIAL)
.when()
.post("/")
.then()
.statusCode(200);
given()
.formParam("Action", "GetAccountPasswordPolicy")
.header("Authorization", IAM_CREDENTIAL)
.when()
.post("/")
.then()
.statusCode(200)
.body("GetAccountPasswordPolicyResponse.GetAccountPasswordPolicyResult.PasswordPolicy."
+ "MinimumPasswordLength", equalTo("8"))
// RequireSymbols was true from the previous update; an omitted field resets rather
// than carries over.
.body("GetAccountPasswordPolicyResponse.GetAccountPasswordPolicyResult.PasswordPolicy."
+ "RequireSymbols", equalTo("false"))
// MaxPasswordAge was set previously; omitted here it must not be echoed back at all.
.body(not(containsString("MaxPasswordAge")))
// HardExpiry was true from the previous update; omitted here it must reset to its
// AWS-documented default of false, not be echoed back as true nor omitted entirely.
.body("GetAccountPasswordPolicyResponse.GetAccountPasswordPolicyResult.PasswordPolicy."
+ "HardExpiry", equalTo("false"));
}
@Test
@Order(6)
void updateWithMinimumLengthOutOfRangeIsRejected() {
given()
.formParam("Action", "UpdateAccountPasswordPolicy")
.formParam("MinimumPasswordLength", "129")
.header("Authorization", IAM_CREDENTIAL)
.when()
.post("/")
.then()
.statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("ValidationError"));
}
@Test
@Order(6)
void updateWithMaxPasswordAgeOutOfRangeIsRejected() {
given()
.formParam("Action", "UpdateAccountPasswordPolicy")
.formParam("MaxPasswordAge", "1096")
.header("Authorization", IAM_CREDENTIAL)
.when()
.post("/")
.then()
.statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("ValidationError"));
}
@Test
@Order(6)
void updateWithPasswordReusePreventionOutOfRangeIsRejected() {
given()
.formParam("Action", "UpdateAccountPasswordPolicy")
.formParam("PasswordReusePrevention", "25")
.header("Authorization", IAM_CREDENTIAL)
.when()
.post("/")
.then()
.statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("ValidationError"));
}
@Test
@Order(6)
void updateWithMalformedRequireSymbolsIsRejected() {
given()
.formParam("Action", "UpdateAccountPasswordPolicy")
.formParam("RequireSymbols", "banana")
.header("Authorization", IAM_CREDENTIAL)
.when()
.post("/")
.then()
.statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("ValidationError"));
}
@Test
@Order(6)
void updateWithMalformedHardExpiryIsRejected() {
given()
.formParam("Action", "UpdateAccountPasswordPolicy")
.formParam("HardExpiry", "banana")
.header("Authorization", IAM_CREDENTIAL)
.when()
.post("/")
.then()
.statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("ValidationError"));
}
@Test
@Order(6)
void updateWithMalformedMinimumPasswordLengthIsRejected() {
// A non-numeric MinimumPasswordLength must be rejected outright, not silently coerced
// to the field's default (6) — that would let a caller's typo succeed with 200 while
// quietly ignoring the value they asked for.
given()
.formParam("Action", "UpdateAccountPasswordPolicy")
.formParam("MinimumPasswordLength", "abc")
.header("Authorization", IAM_CREDENTIAL)
.when()
.post("/")
.then()
.statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("ValidationError"));
}
@Test
@Order(6)
void updateWithMalformedMaxPasswordAgeIsRejected() {
given()
.formParam("Action", "UpdateAccountPasswordPolicy")
.formParam("MaxPasswordAge", "abc")
.header("Authorization", IAM_CREDENTIAL)
.when()
.post("/")
.then()
.statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("ValidationError"));
}
@Test
@Order(6)
void updateWithMalformedPasswordReusePreventionIsRejected() {
given()
.formParam("Action", "UpdateAccountPasswordPolicy")
.formParam("PasswordReusePrevention", "abc")
.header("Authorization", IAM_CREDENTIAL)
.when()
.post("/")
.then()
.statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("ValidationError"));
}
@Test
@Order(6)
void updateWithHardExpiryOmittedDefaultsToFalseInResponse() {
// HardExpiry has no "optional/absent" state on the wire — AWS documents it as a boolean
// that always defaults to false, unlike MaxPasswordAge/PasswordReusePrevention which stay
// absent when unset.
given()
.formParam("Action", "UpdateAccountPasswordPolicy")
.formParam("MinimumPasswordLength", "10")
.header("Authorization", IAM_CREDENTIAL)
.when()
.post("/")
.then()
.statusCode(200);
given()
.formParam("Action", "GetAccountPasswordPolicy")
.header("Authorization", IAM_CREDENTIAL)
.when()
.post("/")
.then()
.statusCode(200)
.body("GetAccountPasswordPolicyResponse.GetAccountPasswordPolicyResult.PasswordPolicy."
+ "HardExpiry", equalTo("false"));
}
@Test
@Order(7)
void deleteRemovesThePolicy() {
given()
.formParam("Action", "DeleteAccountPasswordPolicy")
.header("Authorization", IAM_CREDENTIAL)
.when()
.post("/")
.then()
.statusCode(200);
given()
.formParam("Action", "GetAccountPasswordPolicy")
.header("Authorization", IAM_CREDENTIAL)
.when()
.post("/")
.then()
.statusCode(404)
.body("ErrorResponse.Error.Code", equalTo("NoSuchEntity"));
}
}
@@ -320,7 +320,7 @@ class IamManagedPolicyAccountScopeTest {
new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>(),
new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>(),
new InMemoryStorage<>(),
aliases, new InMemoryStorage<>(), new InMemoryStorage<>(),
aliases, new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>(),
new RegionResolver("us-east-1", DEFAULT_ACCT), false, null);
}
}
@@ -5,6 +5,7 @@ import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.PersistentStorage;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.services.iam.model.AccessKey;
import io.github.hectorvent.floci.services.iam.model.AccountPasswordPolicy;
import io.github.hectorvent.floci.services.iam.model.IamGroup;
import io.github.hectorvent.floci.services.iam.model.IamPolicy;
import io.github.hectorvent.floci.services.iam.model.IamRole;
@@ -93,6 +94,7 @@ class IamServicePersistenceTest {
load(dir, "iam-instance-profiles.json", new TypeReference<Map<String, InstanceProfile>>() {}),
load(dir, "iam-sessions.json", new TypeReference<Map<String, SessionCredential>>() {}),
load(dir, "iam-account-aliases.json", new TypeReference<Map<String, String>>() {}),
load(dir, "iam-password-policy.json", new TypeReference<Map<String, AccountPasswordPolicy>>() {}),
load(dir, "iam-oidc-providers.json", new TypeReference<Map<String, OpenIDConnectProvider>>() {}),
load(dir, "iam-slr-deletions.json", new TypeReference<Map<String, String>>() {}),
new RegionResolver("us-east-1", "000000000000"),