diff --git a/docs/services/iam.md b/docs/services/iam.md index 5f5c0bf64f..8186efbbd2 100644 --- a/docs/services/iam.md +++ b/docs/services/iam.md @@ -614,21 +614,32 @@ returns `EntityAlreadyExists`; `Get`/`Update`/`DeleteLoginProfile` on a user wit wholesale replace. A password must be 1–128 characters from AWS's documented password character class, and when the account has an [account password policy](#account-password-policy) set, it is also checked against that policy's length and character-class requirements, with -`PasswordPolicyViolation` returned on either action if it doesn't comply. The password itself is never -echoed back by any of these actions, matching AWS. +`PasswordPolicyViolation` returned on either action if it doesn't comply, naming the rule the +password broke, which is also what `ChangePassword` answers for a new password. The password itself +is never echoed back by any of these actions, matching AWS. `ChangePassword` is the self-service half of `UpdateLoginProfile`. It takes no `UserName` and acts only on the user whose access key signed the request, which is what the API reference means by "the IAM user who is calling this operation", and the account root password is not affected by it. A caller with no IAM user behind its key, which is Floci's stand-in for account root credentials, is -refused with `InvalidUserType`, the error the CLI reference documents for that case. `OldPassword` -must match the stored password, and the reference publishes no error for a mismatch, so Floci -answers `InvalidParameterValue`, the common error type for a parameter value the service cannot -accept. It is checked before the new password is held to the account policy, so a caller who cannot -prove the current password learns nothing about what the policy requires. A successful change -clears `PasswordResetRequired`, which is what lets a user whose password an administrator reset -restore their own console access programmatically, and it updates the `password_last_changed` the -credential report reads. +refused with `InvalidUserType`, the error the CLI reference documents for that case. + +`OldPassword` must match the stored password, and a mismatch answers `AccessDenied` with status +403 and "Either the new password does not conform to the account password policy or the old +password was incorrect.", captured from a real account on 2026-10-31. The reference publishes no +error for a mismatch and none of the six this operation declares describes one, so the capture is +what settles it. The sentence is AWS's own and is sent as captured, naming both of the operation's +causes without saying which one refused the call. The old password is checked before the new one is +held to the account policy, so a caller who cannot prove the current password learns nothing about +what the policy requires, and a request with both halves wrong answers this. + +That the sentence names the policy half does not settle the policy half: the capture covers a wrong +old password with a conforming new one, and the API model declares `PasswordPolicyViolation` on +this operation for a password the account policy refuses, so that is what Floci answers there, +naming the rule the password broke as `CreateLoginProfile` and `UpdateLoginProfile` do. A +successful change clears `PasswordResetRequired`, which is what lets a user whose password an +administrator reset restore their own console access programmatically, and it updates the +`password_last_changed` the credential report reads. `PasswordReusePrevention` is enforced on `ChangePassword` and on `UpdateLoginProfile`, which share one history per login profile, so an administrator reset cannot put back a password a user has just @@ -712,9 +723,12 @@ matching on one does not match. IAM user or role only, not a group. It is held to the 20 characters `arnType` declares before it is resolved, so a value too short to be any ARN is a `ValidationError` with status 400 naming the length rather than an entity resolved out of whatever follows its last slash. A value that clears -20 characters and still parses as no ARN is resolved as before: the member publishes a length and -no pattern, and no source records what AWS answers for one, so inventing a refusal would be a -guess. The length wording follows the captures of real IAM length violations, naming only the +20 characters and still parses as no ARN is refused too, with `InvalidInput` and "Invalid ARN +provided in the request: ", captured from a real account on 2026-10-31 for +`arn:aws:iam:user/bob`, which this emulator used to simulate against a user named `bob`. Parsing +means the six colon-delimited segments every ARN carries, so a valid ARN naming something that is +neither a user nor a role still answers the `InvalidInput` about the entity type rather than about +the shape. The length wording follows the captures of real IAM length violations, naming only the bound the value broke and leaving the value itself out of the message. `SimulateCustomPolicy` accepts only one `PermissionsBoundaryPolicyInputList` document, matching AWS's own documented limit; extra documents beyond the first are ignored. Neither simulation action evaluates a diff --git a/docs/services/sts.md b/docs/services/sts.md index ee110745c5..f8dd85c489 100644 --- a/docs/services/sts.md +++ b/docs/services/sts.md @@ -152,12 +152,13 @@ A long-term `AKIA` key resolves through the account that holds it and a temporar the session that minted it. The ID is read against its own shape first, the 16 to 128 characters of `[\w]` the model declares, which answers `ValidationError` before any lookup. -One answer is Floci's own. The operation models no errors at all, and the reference says only that -"providing a deleted access key might return an error that the key doesn't exist", so a well-formed -ID that this emulator never issued answers `InvalidParameterValue`, the published common error -closest to that sentence. Nothing in the reference says what AWS answers for an ID it never issued, -and real access key IDs are not random the way Floci's are, so treat that one as a deviation rather -than a recorded behaviour. +An ID the account never issued answers `ValidationError` with status 400 and "Access key ID is not +valid.", a sentence carrying neither the ID nor a validation-error count. The operation models no +errors at all and the reference says only that "providing a deleted access key might return an +error that the key doesn't exist", so this answer comes from a capture from a real account on +2026-10-31, which answered an `AKIA` and an `ASIA` ID alike that way. It settles a question this +emulator had left open: AWS refuses an ID it never issued rather than reading the account out of +it, so minting IDs that carry their account would buy nothing here. ## Delegated Access Token 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 65f730d09e..e84ff55f55 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 @@ -2412,9 +2412,10 @@ public class IamQueryHandler { * {@code ValidationError} naming the length, so a value too short to be any ARN is refused on * its shape rather than resolved to whatever follows its last slash. * - *

A value that clears 20 characters and still parses as no ARN is left alone: the member - * publishes a length and no pattern, and what AWS answers for one is not recorded. An absent - * or blank value is left alone too, the resolver below reporting that one. + *

A value that clears 20 characters and still parses as no ARN is left to the resolver + * below, which refuses it as {@code InvalidInput} on a capture of its own: the member publishes + * a length and no pattern, so there is no shape to hold it to here. An absent or blank value + * is left there too, that resolver reporting it. */ private String validatedPolicySourceArn(MultivaluedMap params) { String arn = getParam(params, "PolicySourceArn"); 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 3de9c61a00..965ce73e24 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 @@ -2823,12 +2823,11 @@ public class IamService implements SessionAccountLookup, ResourceProvider { * password programmatically", which is only true if the change itself clears the state the * reset left behind. * - *

An old password that does not match is the one refusal the reference leaves unnamed: - * every error it publishes for this operation describes something else, and the error it - * documents for a caller that is not an IAM user is {@code InvalidUserType}, raised by the - * handler. The common error types are additive per action, so this answers - * {@code InvalidParameterValue}, which is the published one for a parameter value the service - * cannot accept, with the same 400 as the operation's other sender faults. + *

A mismatched old password answers {@link #passwordChangeRefused}, captured from a real + * account: the reference publishes no error for one, and none of the six this operation + * declares describes it. The error it does document for a caller that is not an IAM user is + * {@code InvalidUserType}, raised by the handler. A new password the account's policy refuses + * is the case the operation does declare an error for, and keeps it. */ public void changePassword(String userName, String oldPassword, String newPassword) { validatePassword(oldPassword, "oldPassword"); @@ -2836,9 +2835,7 @@ public class IamService implements SessionAccountLookup, ResourceProvider { synchronized (loginProfileLock) { LoginProfile profile = getLoginProfile(userName); if (!oldPassword.equals(profile.getPassword())) { - throw new AwsException("InvalidParameterValue", - "The old password supplied is not the current password for user " - + userName + ".", 400); + throw passwordChangeRefused(); } checkPasswordPolicy(newPassword, profile); recordSupersededPassword(profile); @@ -2850,11 +2847,33 @@ public class IamService implements SessionAccountLookup, ResourceProvider { LOG.infov("Changed the IAM console password of user: {0}", userName); } + /** + * What a wrong old password is refused with, captured from a real account: + * {@code AccessDenied} 403 and "Either the new password does not conform to the account + * password policy or the old password was incorrect.". The sentence is AWS's own and is sent + * as captured, naming both of the operation's causes without saying which one refused the + * call, so a caller who cannot prove the current password learns nothing about the policy + * either. + * + *

That it names the policy half does not settle the policy half. The capture covers a wrong + * old password with a conforming new one, nothing records AWS answering this for a password + * the policy refuses, and the model declares {@code PasswordPolicyViolation} on this operation + * for exactly that case, so that is what the policy half keeps until a capture says otherwise. + */ + private static AwsException passwordChangeRefused() { + return new AwsException("AccessDenied", + "Either the new password does not conform to the account password policy or the " + + "old password was incorrect.", 403); + } + /** * The account's password policy applied to a password about to be stored, and only when the * account has ever set one, matching {@link #getAccountPasswordPolicy}'s own * NoSuchEntity-by-default semantics. {@code replacing} is the profile the password is being * written over, or null when there is none to reuse a password from. + * + *

Every caller that stores a password answers it the same way, {@code ChangePassword} + * included: {@code PasswordPolicyViolation} naming the rule that failed. */ private void checkPasswordPolicy(String password, LoginProfile replacing) { getAccountPasswordPolicy().ifPresent(policy -> { @@ -5741,6 +5760,13 @@ public class IamService implements SessionAccountLookup, ResourceProvider { if (principalArn == null || principalArn.isBlank()) { throw new AwsException("ValidationError", "PolicySourceArn is required.", 400); } + // Captured from a real account: a value that clears the member's 20-character minimum and + // parses as no ARN is refused rather than resolved out of whatever follows its last slash, + // which used to simulate `arn:aws:iam:user/bob` as the user `bob`. + if (!AwsArnUtils.isArn(principalArn)) { + throw new AwsException("InvalidInput", + "Invalid ARN provided in the request: " + principalArn, 400); + } if (principalArn.contains(":user/")) { String userName = principalArn.substring(principalArn.lastIndexOf('/') + 1); List identityPolicies = withAccountGrants diff --git a/src/main/java/io/github/hectorvent/floci/services/iam/StsQueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/iam/StsQueryHandler.java index 73e8947994..d63ba2ad79 100644 --- a/src/main/java/io/github/hectorvent/floci/services/iam/StsQueryHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/iam/StsQueryHandler.java @@ -308,10 +308,12 @@ public class StsQueryHandler { * the lookup takes the key whatever state it is in, which is why it is not * {@code resolveAccountId}, the authentication path, that answers here. * - *

A key Floci does not hold is the one answer the reference leaves open. It models no error + *

A key Floci does not hold is the one answer the reference leaves open: it models no error * for it and says only that "providing a deleted access key might return an error that the key - * doesn't exist", so this answers {@code InvalidParameterValue}, the published common error - * nearest that sentence, and {@code docs/services/sts.md} records it as the deviation it is. + * doesn't exist". A capture from a real account answers {@code ValidationError} 400, "Access + * key ID is not valid.", for an {@code AKIA} and an {@code ASIA} id alike, which settles the + * shape of the operation as a refusal rather than a decode of the account out of the id. + * {@code docs/services/sts.md} carries the capture. */ private Response handleGetAccessKeyInfo(MultivaluedMap params) { Response validation = validateDeclaredConstraints("GetAccessKeyInfo", params); @@ -321,8 +323,11 @@ public class StsQueryHandler { String accessKeyId = getParam(params, "AccessKeyId"); Optional account = iamService.findAccountForAccessKeyId(accessKeyId); if (account.isEmpty()) { - return AwsQueryResponse.error("InvalidParameterValue", - "The access key " + accessKeyId + " does not exist.", AwsNamespaces.STS, 400); + // Captured from a real account against an AKIA and an ASIA id alike: AWS refuses an id + // it never issued rather than decoding the account out of it, and the refusal carries + // neither the id nor a validation-error count. + return AwsQueryResponse.error("ValidationError", + "Access key ID is not valid.", AwsNamespaces.STS, 400); } String result = new XmlBuilder().elem("Account", account.get()).build(); return Response.ok(AwsQueryResponse.envelope("GetAccessKeyInfo", AwsNamespaces.STS, result)).build(); diff --git a/src/test/java/io/github/hectorvent/floci/services/iam/IamChangePasswordIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/iam/IamChangePasswordIntegrationTest.java index 38d7f0f431..2b6109e543 100644 --- a/src/test/java/io/github/hectorvent/floci/services/iam/IamChangePasswordIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/iam/IamChangePasswordIntegrationTest.java @@ -38,6 +38,9 @@ class IamChangePasswordIntegrationTest { private static final String REGION = "us-east-1"; private static final String PASSWORD = "Sup3r$ecret!"; private static final String NEW_PASSWORD = "An0ther$ecret!"; + /** Captured: what a wrong old password is refused with, both of the causes named. */ + private static final String WRONG_OLD_PASSWORD = "Either the new password does not conform to " + + "the account password policy or the old password was incorrect."; @RegisterExtension final PartitionCleanup cleanup = new PartitionCleanup(); @@ -53,8 +56,8 @@ class IamChangePasswordIntegrationTest { // Nothing echoes a password back, so the proof the write took is the next call: the old // password is no longer the current one and the new one is. signedAs(accessKeyId, Map.of("OldPassword", PASSWORD, "NewPassword", "Th1rd$ecret!")) - .statusCode(400) - .body("ErrorResponse.Error.Code", equalTo("InvalidParameterValue")); + .statusCode(403) + .body("ErrorResponse.Error.Code", equalTo("AccessDenied")); signedAs(accessKeyId, Map.of("OldPassword", NEW_PASSWORD, "NewPassword", "Th1rd$ecret!")) .statusCode(200); } @@ -104,6 +107,12 @@ class IamChangePasswordIntegrationTest { .body("ErrorResponse.Error.Message", containsString("'oldPassword'")); } + /** + * The two halves of the refusal answer differently, which is what the capture of 2026-10-31 + * settles and what it leaves alone: a new password the account policy refuses is told which + * rule it broke, where a wrong old password gets the captured sentence, which names both + * causes without saying which one applied. + */ @Test void theNewPasswordIsHeldToTheAccountPasswordPolicy() { String accessKeyId = userWithAConsolePassword("policy"); @@ -113,7 +122,16 @@ class IamChangePasswordIntegrationTest { signedAs(accessKeyId, Map.of("OldPassword", PASSWORD, "NewPassword", "sh0rt!")) .statusCode(400) - .body("ErrorResponse.Error.Code", equalTo("PasswordPolicyViolation")); + .body("ErrorResponse.Error.Code", equalTo("PasswordPolicyViolation")) + .body("ErrorResponse.Error.Type", equalTo("Sender")) + .body("ErrorResponse.Error.Message", containsString("a minimum length of 20")); + + signedAs(accessKeyId, + Map.of("OldPassword", "N0tTheOne!", "NewPassword", "L0ngEn0ugh$ecret!!!!")) + .statusCode(403) + .body("ErrorResponse.Error.Code", equalTo("AccessDenied")) + .body("ErrorResponse.Error.Type", equalTo("Sender")) + .body("ErrorResponse.Error.Message", equalTo(WRONG_OLD_PASSWORD)); signedAs(accessKeyId, Map.of("OldPassword", PASSWORD, "NewPassword", "L0ngEn0ugh$ecret!!!!")) diff --git a/src/test/java/io/github/hectorvent/floci/services/iam/IamConcurrencyTest.java b/src/test/java/io/github/hectorvent/floci/services/iam/IamConcurrencyTest.java index 9e43f90886..fca6a17dd7 100644 --- a/src/test/java/io/github/hectorvent/floci/services/iam/IamConcurrencyTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/iam/IamConcurrencyTest.java @@ -412,7 +412,9 @@ class IamConcurrencyTest { iam.changePassword("racer", "Passw0rd$start", candidate); winners.add(candidate); } catch (AwsException e) { - if (!"InvalidParameterValue".equals(e.getErrorCode())) { + // The losers hold a password that is no longer current, which + // is what AccessDenied answers. + if (!"AccessDenied".equals(e.getErrorCode())) { unexpected.add(e.getErrorCode()); } } catch (InterruptedException e) { diff --git a/src/test/java/io/github/hectorvent/floci/services/iam/IamIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/iam/IamIntegrationTest.java index 3da8323584..849d9515e5 100644 --- a/src/test/java/io/github/hectorvent/floci/services/iam/IamIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/iam/IamIntegrationTest.java @@ -562,8 +562,8 @@ class IamIntegrationTest { * simulated against a user named after its tail. IAM answers that minimum with a * {@code ValidationError} naming the length, which is what both principal readers answer now. * - *

A value that clears 20 characters and still parses as no ARN is deliberately untouched: - * the member publishes no pattern and nothing records what AWS answers for one. + *

What AWS answers for a value that clears 20 characters and parses as no ARN is + * {@link #aPolicySourceArnThatParsesAsNoArnIsInvalidInput} below, captured since. */ @Test @Order(88) @@ -597,6 +597,46 @@ class IamIntegrationTest { .body("ErrorResponse.Error.Message", equalTo(expected)); } + /** + * The other half of the member, captured from a real account: a value long enough to clear + * {@code arnType}'s minimum and malformed enough to parse as no ARN answers + * {@code InvalidInput} quoting it, where the simulator used to resolve the user its tail + * named. The length violation above is read first, since the shape runs before the operation. + */ + @Test + @Order(89) + void aPolicySourceArnThatParsesAsNoArnIsInvalidInput() { + String malformed = "arn:aws:iam:user/simulate-user"; + + given() + .formParam("Action", "SimulatePrincipalPolicy") + .formParam("PolicySourceArn", malformed) + .formParam("ActionNames.member.1", "s3:GetObject") + .header("Authorization", + "AWS4-HMAC-SHA256 Credential=test/20260227/us-east-1/iam/aws4_request") + .when() + .post("/") + .then() + .statusCode(400) + .body("ErrorResponse.Error.Code", equalTo("InvalidInput")) + .body("ErrorResponse.Error.Type", equalTo("Sender")) + .body("ErrorResponse.Error.Message", + equalTo("Invalid ARN provided in the request: " + malformed)); + + given() + .formParam("Action", "GetContextKeysForPrincipalPolicy") + .formParam("PolicySourceArn", malformed) + .header("Authorization", + "AWS4-HMAC-SHA256 Credential=test/20260227/us-east-1/iam/aws4_request") + .when() + .post("/") + .then() + .statusCode(400) + .body("ErrorResponse.Error.Code", equalTo("InvalidInput")) + .body("ErrorResponse.Error.Message", + equalTo("Invalid ARN provided in the request: " + malformed)); + } + @Test @Order(41) void getContextKeysForPrincipalPolicyMergesAttachedAndExtraPolicies() { diff --git a/src/test/java/io/github/hectorvent/floci/services/iam/IamServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/iam/IamServiceTest.java index fa6af4343d..f46f4ba88b 100644 --- a/src/test/java/io/github/hectorvent/floci/services/iam/IamServiceTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/iam/IamServiceTest.java @@ -56,6 +56,10 @@ import static org.junit.jupiter.api.Assertions.*; class IamServiceTest { + /** Captured 2026-10-31: what a wrong old password is refused with, both causes named. */ + private static final String PASSWORD_CHANGE_REFUSAL = "Either the new password does not " + + "conform to the account password policy or the old password was incorrect."; + private IamService iamService; @BeforeEach @@ -1180,7 +1184,7 @@ class IamServiceTest { // The proof the write took is behavioural rather than a read of the stored field: the // new password is now the current one and the old one is not. iamService.changePassword("alice", "An0ther$ecret!", "Th1rd$ecret!"); - assertEquals("InvalidParameterValue", assertThrows(AwsException.class, + assertEquals("AccessDenied", assertThrows(AwsException.class, () -> iamService.changePassword("alice", "An0ther$ecret!", "F0urth$ecret!")) .getErrorCode()); } @@ -1193,8 +1197,9 @@ class IamServiceTest { AwsException ex = assertThrows(AwsException.class, () -> iamService.changePassword("alice", "N0tTheOne!", "An0ther$ecret!")); - assertEquals("InvalidParameterValue", ex.getErrorCode()); - assertEquals(400, ex.getHttpStatus()); + assertEquals("AccessDenied", ex.getErrorCode()); + assertEquals(403, ex.getHttpStatus()); + assertEquals(PASSWORD_CHANGE_REFUSAL, ex.getMessage()); // The refusal left the password alone, so the original still changes it. iamService.changePassword("alice", "Sup3r$ecret!", "An0ther$ecret!"); } @@ -1209,10 +1214,23 @@ class IamServiceTest { // Both halves of the request are wrong. A caller who cannot prove the current password is // told that and nothing about what the policy would have required. - AwsException ex = assertThrows(AwsException.class, + AwsException both = assertThrows(AwsException.class, () -> iamService.changePassword("alice", "N0tTheOne!", "short")); + assertEquals("AccessDenied", both.getErrorCode()); + assertEquals(403, both.getHttpStatus()); + assertEquals(PASSWORD_CHANGE_REFUSAL, both.getMessage()); - assertEquals("InvalidParameterValue", ex.getErrorCode()); + // The same new password on its own is refused by the policy and named the rule it + // broke, so the answer above is the order the two checks run in rather than a policy + // that had nothing to say. + AwsException policyOnly = assertThrows(AwsException.class, + () -> iamService.changePassword("alice", "Sup3r$ecret!", "short")); + assertEquals("PasswordPolicyViolation", policyOnly.getErrorCode()); + assertEquals(400, policyOnly.getHttpStatus()); + assertTrue(policyOnly.getMessage().contains("a minimum length of 12"), + policyOnly.getMessage()); + // The password is untouched by both, so the original still changes it. + iamService.changePassword("alice", "Sup3r$ecret!", "An0ther$ecret!"); } @Test @@ -1230,6 +1248,11 @@ class IamServiceTest { assertEquals("PasswordPolicyViolation", ex.getErrorCode()); assertEquals(400, ex.getHttpStatus()); + // The rule the password broke is named, the same as it is to an administrator setting it. + assertTrue(ex.getMessage().contains("a minimum length of 12"), ex.getMessage()); + assertTrue(assertThrows(AwsException.class, + () -> iamService.updateLoginProfile("alice", "short", null)) + .getMessage().contains("a minimum length of 12")); iamService.changePassword("alice", "Sup3r$ecret!", "An0ther$ecret!"); } @@ -2797,6 +2820,30 @@ class IamServiceTest { assertNotNull(iamService.resolvePrincipalContext(user.getArn())); } + /** + * Captured from a real account: a value over the member's 20-character minimum that parses as + * no ARN is refused, where this service used to take whatever followed the last slash and + * simulate against a user of that name. Both principal readers answer it, since both take the + * same member. + */ + @Test + void aPolicySourceArnThatParsesAsNoArnIsRefused() { + iamService.createUser("bob", "/"); + + for (String malformed : List.of("arn:aws:iam:user/bob", "arn:aws:iam::user/bob", + "not-an-arn-but-long-enough:user/bob")) { + AwsException ex = assertThrows(AwsException.class, + () -> iamService.resolvePrincipalContext(malformed)); + assertEquals("InvalidInput", ex.getErrorCode()); + assertEquals(400, ex.getHttpStatus()); + assertEquals("Invalid ARN provided in the request: " + malformed, ex.getMessage()); + assertEquals("InvalidInput", assertThrows(AwsException.class, + () -> iamService.resolveAttachedPrincipalContext(malformed)).getErrorCode()); + } + // The user the tail named exists, so the refusal is the parse rather than the lookup. + assertNotNull(iamService.resolvePrincipalContext("arn:aws:iam::000000000000:user/bob")); + } + @Test void simulatePrincipalPolicyRejectsUnsupportedPrincipalArnType() { AwsException ex = assertThrows(AwsException.class, diff --git a/src/test/java/io/github/hectorvent/floci/services/iam/PasswordSelfServiceGrantEnforcementIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/iam/PasswordSelfServiceGrantEnforcementIntegrationTest.java index aeeb8f0384..e0df7a6d19 100644 --- a/src/test/java/io/github/hectorvent/floci/services/iam/PasswordSelfServiceGrantEnforcementIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/iam/PasswordSelfServiceGrantEnforcementIntegrationTest.java @@ -352,13 +352,15 @@ class PasswordSelfServiceGrantEnforcementIntegrationTest { } /** - * A {@code PolicySourceArn} that names a user without being an ARN this emulator can parse is - * resolved by its trailing name, as it was before the principal keys were populated, so the - * account they carry comes from the identity that resolved rather than from the text of the - * call. + * A {@code PolicySourceArn} that names a user without being an ARN is refused rather than + * resolved by its trailing name, which is what a capture from a real account answers and what + * this class used to pin the other way: the grant is read from the identity the ARN resolves + * to, so there is nothing to resolve from a value that parses as no ARN. The same user under + * a well-formed ARN simulates as allowed, which is what says the refusal is the shape of the + * value rather than the grant. */ @Test - void aPolicySourceArnItCannotParseStillSimulates() { + void aPolicySourceArnItCannotParseIsRefused() { allowUsersToChangePassword(true); String userName = "pw-oddarn-" + suffix(); userWithAConsolePassword(userName); @@ -367,6 +369,15 @@ class PasswordSelfServiceGrantEnforcementIntegrationTest { "PolicySourceArn", "arn:aws:iam:user/" + userName, "ActionNames.member.1", "iam:ChangePassword", "ResourceArns.member.1", "arn:aws:iam::" + ACCOUNT + ":user/" + userName)) + .statusCode(400) + .body("ErrorResponse.Error.Code", equalTo("InvalidInput")) + .body("ErrorResponse.Error.Message", + equalTo("Invalid ARN provided in the request: arn:aws:iam:user/" + userName)); + + admin("SimulatePrincipalPolicy", Map.of( + "PolicySourceArn", "arn:aws:iam::" + ACCOUNT + ":user/" + userName, + "ActionNames.member.1", "iam:ChangePassword", + "ResourceArns.member.1", "arn:aws:iam::" + ACCOUNT + ":user/" + userName)) .statusCode(200) .body(decisionPath(), equalTo("allowed")); } diff --git a/src/test/java/io/github/hectorvent/floci/services/iam/StsAccessKeyInfoIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/iam/StsAccessKeyInfoIntegrationTest.java index 39b8436366..23cf9fbe16 100644 --- a/src/test/java/io/github/hectorvent/floci/services/iam/StsAccessKeyInfoIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/iam/StsAccessKeyInfoIntegrationTest.java @@ -6,6 +6,8 @@ import io.restassured.response.ValidatableResponse; import io.restassured.specification.RequestSpecification; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import java.util.Map; @@ -21,7 +23,8 @@ import static org.hamcrest.Matchers.startsWith; * errors at all. Its one explicit behaviour is what it does not do: "this operation does not * indicate the state of the access key. The key might be active, inactive, or deleted", so an * inactive key still answers its account. A key Floci does not hold is the answer the reference - * leaves open, and {@code docs/services/sts.md} carries that deviation. + * leaves open, and a capture from a real account answers it {@code ValidationError} "Access key ID + * is not valid." over both id formats, which {@code docs/services/sts.md} carries. */ @QuarkusTest class StsAccessKeyInfoIntegrationTest { @@ -98,10 +101,18 @@ class StsAccessKeyInfoIntegrationTest { containsString("Value null at 'accessKeyId'")); } - @Test - void aWellFormedKeyNobodyHoldsIsRefused() { - sts("GetAccessKeyInfo", Map.of("AccessKeyId", "AKIAABSENTKEY0000000")).statusCode(400) - .body("ErrorResponse.Error.Code", equalTo("InvalidParameterValue")); + /** + * Captured from a real account against a long-term and a temporary id alike: an id the account + * never issued is a {@code ValidationError} whose sentence names neither the id nor a + * violation count, so AWS refuses it rather than reading the account out of it. + */ + @ParameterizedTest + @ValueSource(strings = {"AKIAABSENTKEY0000000", "ASIAABSENTKEY0000000"}) + void aWellFormedKeyNobodyHoldsIsRefused(String accessKeyId) { + sts("GetAccessKeyInfo", Map.of("AccessKeyId", accessKeyId)).statusCode(400) + .body("ErrorResponse.Error.Code", equalTo("ValidationError")) + .body("ErrorResponse.Error.Type", equalTo("Sender")) + .body("ErrorResponse.Error.Message", equalTo("Access key ID is not valid.")); } private String user(String label) { diff --git a/src/test/java/io/github/hectorvent/floci/services/iam/StsQueryHandlerTest.java b/src/test/java/io/github/hectorvent/floci/services/iam/StsQueryHandlerTest.java index 2bf914c210..98ac04e8a6 100644 --- a/src/test/java/io/github/hectorvent/floci/services/iam/StsQueryHandlerTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/iam/StsQueryHandlerTest.java @@ -835,21 +835,27 @@ class StsQueryHandlerTest { verify(service, never()).resolveAccountId(anyString()); } - @Test - void getAccessKeyInfoRefusesAKeyNobodyHolds() { - // The operation models no error at all, and the page says only that a deleted key "might - // return an error that the key doesn't exist", so this is the published common error - // nearest that sentence rather than a reading. + @ParameterizedTest + @ValueSource(strings = {"AKIAABSENTKEY0000000", "ASIAABSENTKEY0000000"}) + void getAccessKeyInfoRefusesAKeyNobodyHolds(String accessKeyId) { + // The operation models no error, and the page says only that a deleted key "might return + // an error that the key doesn't exist". A capture from a real account answers both id + // formats the same way: ValidationError with a sentence that quotes neither the id nor a + // violation count, rather than an account decoded out of the id. IamService service = mock(IamService.class); when(service.findAccountForAccessKeyId(anyString())).thenReturn(Optional.empty()); MultivaluedMap params = new MultivaluedHashMap<>(); - params.add("AccessKeyId", "AKIAABSENTKEY0000000"); + params.add("AccessKeyId", accessKeyId); Response response = newHandler(service, new RegionResolver(REGION, "000000000000")) .handle("GetAccessKeyInfo", params); assertEquals(400, response.getStatus()); - assertTrue(response.getEntity().toString().contains("InvalidParameterValue")); + String body = response.getEntity().toString(); + assertTrue(body.contains("ValidationError"), body); + assertTrue(body.contains("Access key ID is not valid."), body); + assertTrue(body.contains("Sender"), body); + assertFalse(body.contains(accessKeyId), body); } @ParameterizedTest