mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -05:00
feat(sts): dispatch GetAccessKeyInfo, the account an access key id belongs to (#6121)
GetAccessKeyInfo answered UnsupportedOperation 400. It takes one member and answers one: "when you pass an access key ID to this operation, it returns the ID of the AWS account to which the keys belong", and it models no errors at all, so the whole operation is that lookup plus the shape of its input. The lookup is not the one authentication uses. resolveAccountId takes only an active long-term key and a live session, because that is what a request may be signed with, where this operation is explicit about the opposite: "this operation does not indicate the state of the access key. The key might be active, inactive, or deleted". So findAccountForAccessKeyId answers from what is stored whatever state it is in, a long-term key through the account that holds it and an ASIA key through the session that minted it, which is the split the page draws between AKIA as "long-term credentials for an IAM user or the AWS account root user" and ASIA as "temporary credentials that are created using AWS STS operations". Both long-term lookups read one scan now, the authentication one keeping the Active filter over what the new one answers whole, so the guard and the scan are written once. The id is read against accessKeyIdType first, 16 to 128 characters of [\w], which the reference glosses as "any upper- or lowercase letter or digit", so a malformed id answers for its own shape rather than for a key that could not exist. The violation is rendered the way the one recorded IAM rendering Floci already follows renders it, the member in lower camel case and the offending value quoted beside it; the older STS operations name the parameter as written instead, which is drift of its own rather than something to copy here. An absent member and a present empty one are different answers as well: only the absent one reads as null, where AccessKeyId= is a value that fails the minimum and is quoted as the empty string it is, which is what IAM answers for an empty RoleName over this same wire. One answer is chosen rather than read. The operation models no error for a key that is not there, and the page says only that "providing a deleted access key might return an error that the key doesn't exist", so a well-formed id this emulator never issued answers InvalidParameterValue, the published common error closest to that sentence. docs/services/sts.md records it as a deviation rather than a recorded behaviour, since nothing says what AWS answers for an id it never issued. Enforcement is untouched on purpose. The "No permissions are required" note appears on GetCallerIdentity and GetSessionToken and on no other page in the reference, and sts:GetAccessKeyInfo is in the service authorization reference, so this one is authorized like any other action rather than exempted the way GetCallerIdentity is. Ten tests. Five over the wire: a long-term key answering the account that holds it, an inactive key still answering it, a session key answering the account its session belongs to, four shapes refused ahead of any lookup, and a well-formed id nobody holds. Five on the handler: the account answered and the authentication path not consulted, the absent, short, long and malformed ids, a present blank id read as a value rather than an absence, and the refusal for a key the service does not hold. Docs carry the action, a section on what it does and does not say about the key, and the matrix row at 9.
This commit is contained in:
1 parent
f731951c53
commit
4eea01741f
6 files changed
+364
-6
No files matched your search
@@ -24,7 +24,7 @@ Operation counts are exact. For dispatch-table services (Query and JSON 1.1) eac
|
||||
| [API Gateway v1](api-gateway.md) | `/restapis/...` | REST JSON | 80 |
|
||||
| [API Gateway v2](api-gateway.md#v2) | `/v2/apis/...` | REST JSON | 53 + data-plane |
|
||||
| [IAM](iam.md) | `POST /` with `Action=` param | Query | 176 |
|
||||
| [STS](sts.md) | `POST /` with `Action=` param | Query | 8 |
|
||||
| [STS](sts.md) | `POST /` with `Action=` param | Query | 9 |
|
||||
| [AWS Sign-In](iam.md#aws-sign-in-login-credentials) | `/v1/authorize`, `/v1/token` | REST JSON | 2 |
|
||||
| [Organizations](organizations.md) | `POST /` + `X-Amz-Target: AWSOrganizationsV20161128.*` | JSON 1.1 | 56 |
|
||||
| [Cognito](cognito.md) | `POST /` + `X-Amz-Target: AWSCognitoIdentityProviderService.*` | JSON 1.1 | 90 |
|
||||
|
||||
@@ -14,6 +14,23 @@
|
||||
| `GetFederationToken` | Get temporary credentials for a federated user |
|
||||
| `DecodeAuthorizationMessage` | Decode an encoded authorization failure message |
|
||||
| `GetDelegatedAccessToken` | Exchange a delegation request's trade-in token for temporary credentials |
|
||||
| `GetAccessKeyInfo` | Returns the account an access key ID belongs to |
|
||||
|
||||
## Access Key Info
|
||||
|
||||
`GetAccessKeyInfo` answers the account an access key ID belongs to, and nothing about the key
|
||||
itself: AWS states that the operation "does not indicate the state of the access key. The key might
|
||||
be active, inactive, or deleted", so an inactive key answers its account the same as an active one.
|
||||
A long-term `AKIA` key resolves through the account that holds it and a temporary `ASIA` key through
|
||||
the session that minted it. The ID is read against its own shape first, 16 to 128 characters of
|
||||
`[\w]`, 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.
|
||||
|
||||
## Delegated Access Token
|
||||
|
||||
|
||||
@@ -4515,18 +4515,49 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
|
||||
*/
|
||||
public record OwnedSecretKey(String secretAccessKey, String accountId) {}
|
||||
|
||||
/**
|
||||
* The account that owns an access key id, in whatever state the key is, which is the lookup STS
|
||||
* GetAccessKeyInfo answers from: "This operation does not indicate the state of the access key.
|
||||
* The key might be active, inactive, or deleted." {@link #resolveAccountId} is the other
|
||||
* question, the one authentication asks, and it takes only an active key and a live session.
|
||||
*/
|
||||
public Optional<String> findAccountForAccessKeyId(String accessKeyId) {
|
||||
if (accessKeyId == null || accessKeyId.isBlank()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
if (!isTemporaryAccessKey(accessKeyId)) {
|
||||
return accessKeyInAnyAccount(accessKeyId)
|
||||
.map(AccountAwareStorageBackend.AccountEntry::accountId);
|
||||
}
|
||||
return storedSessionAnyAccount(accessKeyId)
|
||||
.map(session -> AwsArnUtils.accountOrDefault(session.getRoleArn(), session.getOriginAccountId()))
|
||||
.filter(account -> !account.isBlank());
|
||||
}
|
||||
|
||||
/** The long-term key with this id from whichever account holds it, Active or not. */
|
||||
private Optional<AccountAwareStorageBackend.AccountEntry<AccessKey>> accessKeyInAnyAccount(
|
||||
String accessKeyId) {
|
||||
return longTermKeysInAnyAccount(accessKeyId).stream().findFirst();
|
||||
}
|
||||
|
||||
/** The active long-term key with this ID, from whichever account owns it. */
|
||||
private Optional<AccountAwareStorageBackend.AccountEntry<AccessKey>> activeAccessKeyInAnyAccount(
|
||||
String accessKeyId) {
|
||||
if (accessKeyId == null || isTemporaryAccessKey(accessKeyId)
|
||||
|| !(accessKeys instanceof AccountAwareStorageBackend<AccessKey> aware)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return aware.scanAllAccountEntries(accessKeyId::equals).stream()
|
||||
return longTermKeysInAnyAccount(accessKeyId).stream()
|
||||
.filter(entry -> "Active".equals(entry.value().getStatus()))
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
/** Every long-term key stored under this id, across accounts, in whatever state. */
|
||||
private List<AccountAwareStorageBackend.AccountEntry<AccessKey>> longTermKeysInAnyAccount(
|
||||
String accessKeyId) {
|
||||
if (accessKeyId == null || isTemporaryAccessKey(accessKeyId)
|
||||
|| !(accessKeys instanceof AccountAwareStorageBackend<AccessKey> aware)) {
|
||||
return List.of();
|
||||
}
|
||||
return aware.scanAllAccountEntries(accessKeyId::equals);
|
||||
}
|
||||
|
||||
private Optional<String> activeAccessKeySecret(String accessKeyId) {
|
||||
return accessKeys.get(accessKeyId)
|
||||
.filter(accessKey -> "Active".equals(accessKey.getStatus()))
|
||||
|
||||
@@ -11,6 +11,7 @@ import io.github.hectorvent.floci.core.common.IamConditionContextResolver;
|
||||
import io.github.hectorvent.floci.core.common.IamEnforcementFilter;
|
||||
import io.github.hectorvent.floci.core.common.OidcIssuerKeyLookup;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
|
||||
import io.github.hectorvent.floci.core.common.WebIdentityToken;
|
||||
import io.github.hectorvent.floci.core.common.WebIdentityTokenVerifier;
|
||||
import io.github.hectorvent.floci.core.common.XmlBuilder;
|
||||
@@ -35,6 +36,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Query-protocol handler for STS (Security Token Service) actions.
|
||||
@@ -44,6 +46,11 @@ import java.util.concurrent.ThreadLocalRandom;
|
||||
@ApplicationScoped
|
||||
public class StsQueryHandler {
|
||||
|
||||
/** accessKeyIdType, the only member GetAccessKeyInfo takes: 16 to 128 characters of {@code [\w]}. */
|
||||
private static final Pattern ACCESS_KEY_ID_PATTERN = Pattern.compile("[\\w]*");
|
||||
private static final int ACCESS_KEY_ID_MIN_LENGTH = 16;
|
||||
private static final int ACCESS_KEY_ID_MAX_LENGTH = 128;
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(StsQueryHandler.class);
|
||||
private static final String CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
private static final String STS_AUDIENCE = "sts.amazonaws.com"; // partition-literal: web-identity audience; no source outside the commercial partition (P9)
|
||||
@@ -113,6 +120,7 @@ public class StsQueryHandler {
|
||||
return switch (action) {
|
||||
case "AssumeRole" -> handleAssumeRole(params);
|
||||
case "GetCallerIdentity" -> handleGetCallerIdentity(params);
|
||||
case "GetAccessKeyInfo" -> handleGetAccessKeyInfo(params);
|
||||
case "GetSessionToken" -> handleGetSessionToken(params);
|
||||
case "AssumeRoleWithWebIdentity" -> handleAssumeRoleWithWebIdentity(params);
|
||||
case "AssumeRoleWithSAML" -> handleAssumeRoleWithSAML(params);
|
||||
@@ -258,6 +266,70 @@ public class StsQueryHandler {
|
||||
return Response.ok(AwsQueryResponse.envelope("GetCallerIdentity", AwsNamespaces.STS, result)).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* The account an access key id belongs to. AWS answers one member and models no errors at all,
|
||||
* and the page is explicit that the key's state is not part of the answer: "This operation does
|
||||
* not indicate the state of the access key. The key might be active, inactive, or deleted." So
|
||||
* the lookup takes the key whatever state it is in, which is why it is not
|
||||
* {@code resolveAccountId}, the authentication path, that answers here.
|
||||
*
|
||||
* <p>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.
|
||||
*/
|
||||
private Response handleGetAccessKeyInfo(MultivaluedMap<String, String> params) {
|
||||
Response validation = validateAccessKeyId(params);
|
||||
if (validation != null) {
|
||||
return validation;
|
||||
}
|
||||
String accessKeyId = getParam(params, "AccessKeyId");
|
||||
Optional<String> account = iamService.findAccountForAccessKeyId(accessKeyId);
|
||||
if (account.isEmpty()) {
|
||||
return AwsQueryResponse.error("InvalidParameterValue",
|
||||
"The access key " + accessKeyId + " does not exist.", AwsNamespaces.STS, 400);
|
||||
}
|
||||
String result = new XmlBuilder().elem("Account", account.get()).build();
|
||||
return Response.ok(AwsQueryResponse.envelope("GetAccessKeyInfo", AwsNamespaces.STS, result)).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* accessKeyIdType: required, 16 to 128 characters of {@code [\w]*}, which the reference
|
||||
* describes as "any upper- or lowercase letter or digit". Read before the lookup, so a
|
||||
* malformed id answers for its shape rather than for a key that could not exist.
|
||||
*
|
||||
* <p>An absent member and a present empty one are different answers: only the absent one is
|
||||
* "Member must not be null", where {@code AccessKeyId=} is a value that fails the minimum. That
|
||||
* is what IAM answers for an empty {@code RoleName} on this same wire.
|
||||
*
|
||||
* <p>The member is named the way AWS names it in a constraint message, lower camel case, and
|
||||
* the offending value is quoted beside it, which is what the one recorded rendering Floci
|
||||
* follows elsewhere does: {@link IamService} reads {@code roleName} that way, and so does this
|
||||
* handler's own {@code DurationSeconds} check. The older STS operations name the parameter as
|
||||
* written instead, which is a drift of its own rather than something to copy here.
|
||||
*/
|
||||
private Response validateAccessKeyId(MultivaluedMap<String, String> params) {
|
||||
String accessKeyId = params.getFirst("AccessKeyId");
|
||||
String constraint;
|
||||
if (accessKeyId == null) {
|
||||
constraint = "Member must not be null";
|
||||
} else if (accessKeyId.length() < ACCESS_KEY_ID_MIN_LENGTH) {
|
||||
constraint = "Member must have length greater than or equal to " + ACCESS_KEY_ID_MIN_LENGTH;
|
||||
} else if (accessKeyId.length() > ACCESS_KEY_ID_MAX_LENGTH) {
|
||||
constraint = "Member must have length less than or equal to " + ACCESS_KEY_ID_MAX_LENGTH;
|
||||
} else if (!ACCESS_KEY_ID_PATTERN.matcher(accessKeyId).matches()) {
|
||||
constraint = "Member must satisfy regular expression pattern: "
|
||||
+ ACCESS_KEY_ID_PATTERN.pattern();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
String value = accessKeyId == null ? "null" : "'" + accessKeyId + "'";
|
||||
return AwsQueryResponse.error("ValidationError",
|
||||
SmithyValidationErrors.message(List.of("Value " + value
|
||||
+ " at 'accessKeyId' failed to satisfy constraint: " + constraint)),
|
||||
AwsNamespaces.STS, 400);
|
||||
}
|
||||
|
||||
private Response handleGetSessionToken(MultivaluedMap<String, String> params) {
|
||||
if (IamService.isTemporaryAccessKey(callerAccessKeyId())) {
|
||||
return AwsQueryResponse.error("AccessDenied", "Cannot call GetSessionToken with session credentials",
|
||||
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
package io.github.hectorvent.floci.services.iam;
|
||||
|
||||
import io.github.hectorvent.floci.testing.PartitionCleanup;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
/**
|
||||
* {@code GetAccessKeyInfo} over the wire.
|
||||
*
|
||||
* <p>The operation answers one member, the account an access key id belongs to, and models no
|
||||
* 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.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class StsAccessKeyInfoIntegrationTest {
|
||||
|
||||
private static final String ACCOUNT = "000000000941";
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String RESULT = "GetAccessKeyInfoResponse.GetAccessKeyInfoResult";
|
||||
|
||||
@RegisterExtension
|
||||
final PartitionCleanup cleanup = new PartitionCleanup();
|
||||
|
||||
@Test
|
||||
void aLongTermKeyAnswersTheAccountThatHoldsIt() {
|
||||
String userName = user("holder");
|
||||
String accessKeyId = accessKeyFor(userName);
|
||||
|
||||
sts("GetAccessKeyInfo", Map.of("AccessKeyId", accessKeyId)).statusCode(200)
|
||||
.body(RESULT + ".Account", equalTo(ACCOUNT));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anInactiveKeyStillAnswersItsAccount() {
|
||||
// "This operation does not indicate the state of the access key. The key might be active,
|
||||
// inactive, or deleted", so the status is not a reason to refuse.
|
||||
String userName = user("inactive");
|
||||
String accessKeyId = accessKeyFor(userName);
|
||||
|
||||
iam("UpdateAccessKey", Map.of("UserName", userName, "AccessKeyId", accessKeyId,
|
||||
"Status", "Inactive")).statusCode(200);
|
||||
|
||||
sts("GetAccessKeyInfo", Map.of("AccessKeyId", accessKeyId)).statusCode(200)
|
||||
.body(RESULT + ".Account", equalTo(ACCOUNT));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aSessionKeyAnswersTheAccountItsSessionBelongsTo() {
|
||||
// "Access key IDs beginning with ASIA are temporary credentials that are created using
|
||||
// STS operations", and they resolve through the session rather than the key store.
|
||||
String sessionKeyId = sts("GetSessionToken", Map.of()).statusCode(200)
|
||||
.body("GetSessionTokenResponse.GetSessionTokenResult.Credentials.AccessKeyId",
|
||||
startsWith("ASIA"))
|
||||
.extract().path("GetSessionTokenResponse.GetSessionTokenResult.Credentials.AccessKeyId");
|
||||
|
||||
sts("GetAccessKeyInfo", Map.of("AccessKeyId", sessionKeyId)).statusCode(200)
|
||||
.body(RESULT + ".Account", equalTo(ACCOUNT));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anIdOutsideTheShapeIsReadBeforeAnyLookup() {
|
||||
sts("GetAccessKeyInfo", Map.of("AccessKeyId", "AKIASHORT")).statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("ValidationError"))
|
||||
.body("ErrorResponse.Error.Message",
|
||||
equalTo("1 validation error detected: Value 'AKIASHORT' at 'accessKeyId' "
|
||||
+ "failed to satisfy constraint: Member must have length greater "
|
||||
+ "than or equal to 16"));
|
||||
|
||||
sts("GetAccessKeyInfo", Map.of("AccessKeyId", "AKIA-NOT-A-VALID-KEY-ID")).statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("ValidationError"))
|
||||
.body("ErrorResponse.Error.Message",
|
||||
containsString("Member must satisfy regular expression pattern"));
|
||||
|
||||
// A member sent empty is a value that fails the minimum, where an absent one is the
|
||||
// refusal that names it null, which is the pair IAM already answers for RoleName here.
|
||||
sts("GetAccessKeyInfo", Map.of("AccessKeyId", "")).statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("ValidationError"))
|
||||
.body("ErrorResponse.Error.Message",
|
||||
equalTo("1 validation error detected: Value '' at 'accessKeyId' failed to "
|
||||
+ "satisfy constraint: Member must have length greater than or "
|
||||
+ "equal to 16"));
|
||||
|
||||
sts("GetAccessKeyInfo", Map.of()).statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("ValidationError"))
|
||||
.body("ErrorResponse.Error.Message",
|
||||
containsString("Value null at 'accessKeyId'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aWellFormedKeyNobodyHoldsIsRefused() {
|
||||
sts("GetAccessKeyInfo", Map.of("AccessKeyId", "AKIAABSENTKEY0000000")).statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("InvalidParameterValue"));
|
||||
}
|
||||
|
||||
private String user(String label) {
|
||||
String userName = "access-key-info-" + label;
|
||||
iam("CreateUser", Map.of("UserName", userName)).statusCode(200);
|
||||
cleanup.register(() -> iam("DeleteUser", Map.of("UserName", userName)).statusCode(200));
|
||||
return userName;
|
||||
}
|
||||
|
||||
private String accessKeyFor(String userName) {
|
||||
String accessKeyId = iam("CreateAccessKey", Map.of("UserName", userName)).statusCode(200)
|
||||
.extract().path("CreateAccessKeyResponse.CreateAccessKeyResult.AccessKey.AccessKeyId");
|
||||
cleanup.register(() -> iam("DeleteAccessKey",
|
||||
Map.of("UserName", userName, "AccessKeyId", accessKeyId)).statusCode(200));
|
||||
return accessKeyId;
|
||||
}
|
||||
|
||||
private static ValidatableResponse iam(String action, Map<String, String> params) {
|
||||
return call(action, "iam", "2010-05-08", params);
|
||||
}
|
||||
|
||||
private static ValidatableResponse sts(String action, Map<String, String> params) {
|
||||
return call(action, "sts", "2011-06-15", params);
|
||||
}
|
||||
|
||||
private static ValidatableResponse call(String action, String service, String version,
|
||||
Map<String, String> params) {
|
||||
RequestSpecification spec = given()
|
||||
.header("Authorization", "AWS4-HMAC-SHA256 Credential=" + ACCOUNT
|
||||
+ "/20261019/" + REGION + "/" + service + "/aws4_request, "
|
||||
+ "SignedHeaders=host, Signature=abc")
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", action)
|
||||
.formParam("Version", version);
|
||||
params.forEach(spec::formParam);
|
||||
return spec.when().post("/").then();
|
||||
}
|
||||
}
|
||||
@@ -514,6 +514,102 @@ class StsQueryHandlerTest {
|
||||
PartitionMatrix.assertGlobalArnIn(partitionCase, arn);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAccessKeyInfoAnswersTheAccountThatHoldsTheKey() {
|
||||
IamService service = mock(IamService.class);
|
||||
when(service.findAccountForAccessKeyId("AKIAIOSFODNN7EXAMPLE"))
|
||||
.thenReturn(Optional.of("111122223333"));
|
||||
MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
|
||||
params.add("AccessKeyId", "AKIAIOSFODNN7EXAMPLE");
|
||||
|
||||
Response response = newHandler(service, new RegionResolver(REGION, "000000000000"))
|
||||
.handle("GetAccessKeyInfo", params);
|
||||
|
||||
assertEquals(200, response.getStatus());
|
||||
String body = (String) response.getEntity();
|
||||
assertTrue(body.contains("<GetAccessKeyInfoResponse"), body);
|
||||
assertTrue(body.contains("<Account>111122223333</Account>"), body);
|
||||
// The lookup is the state-independent one, not the authentication path.
|
||||
verify(service).findAccountForAccessKeyId("AKIAIOSFODNN7EXAMPLE");
|
||||
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.
|
||||
IamService service = mock(IamService.class);
|
||||
when(service.findAccountForAccessKeyId(anyString())).thenReturn(Optional.empty());
|
||||
MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
|
||||
params.add("AccessKeyId", "AKIAABSENTKEY0000000");
|
||||
|
||||
Response response = newHandler(service, new RegionResolver(REGION, "000000000000"))
|
||||
.handle("GetAccessKeyInfo", params);
|
||||
|
||||
assertEquals(400, response.getStatus());
|
||||
assertTrue(response.getEntity().toString().contains("<Code>InvalidParameterValue</Code>"));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"-, Value null at 'accessKeyId' failed to satisfy constraint: Member must not be null",
|
||||
"AKIATOOSHORT, Value 'AKIATOOSHORT' at 'accessKeyId' failed to satisfy constraint: "
|
||||
+ "Member must have length greater than or equal to 16",
|
||||
"AKIA-NOT-A-VALID-KEY-ID, Member must satisfy regular expression pattern",
|
||||
})
|
||||
void getAccessKeyInfoReadsTheIdsShapeBeforeAnyLookup(String accessKeyId, String expected) {
|
||||
IamService service = mock(IamService.class);
|
||||
MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
|
||||
if (!"-".equals(accessKeyId)) {
|
||||
params.add("AccessKeyId", accessKeyId);
|
||||
}
|
||||
|
||||
Response response = newHandler(service, new RegionResolver(REGION, "000000000000"))
|
||||
.handle("GetAccessKeyInfo", params);
|
||||
|
||||
assertEquals(400, response.getStatus());
|
||||
// The Query error body escapes the apostrophes the message quotes the member with.
|
||||
String body = ((String) response.getEntity()).replace("'", "'");
|
||||
assertTrue(body.contains("<Code>ValidationError</Code>"), body);
|
||||
assertTrue(body.contains(expected), body);
|
||||
verifyNoInteractions(service);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"", " "})
|
||||
void getAccessKeyInfoReadsAPresentBlankIdAsAValue(String accessKeyId) {
|
||||
// Present and empty is a value, not an absence: it fails the minimum and is quoted in the
|
||||
// message, which is what IAM answers for an empty RoleName over this same wire.
|
||||
IamService service = mock(IamService.class);
|
||||
MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
|
||||
params.add("AccessKeyId", accessKeyId);
|
||||
|
||||
Response response = newHandler(service, new RegionResolver(REGION, "000000000000"))
|
||||
.handle("GetAccessKeyInfo", params);
|
||||
|
||||
assertEquals(400, response.getStatus());
|
||||
String body = ((String) response.getEntity()).replace("'", "'");
|
||||
assertTrue(body.contains("Value '" + accessKeyId + "' at 'accessKeyId' failed to satisfy "
|
||||
+ "constraint: Member must have length greater than or equal to 16"), body);
|
||||
verifyNoInteractions(service);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAccessKeyInfoRefusesAnIdPastTheMaximum() {
|
||||
IamService service = mock(IamService.class);
|
||||
MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
|
||||
params.add("AccessKeyId", "A".repeat(129));
|
||||
|
||||
Response response = newHandler(service, new RegionResolver(REGION, "000000000000"))
|
||||
.handle("GetAccessKeyInfo", params);
|
||||
|
||||
assertEquals(400, response.getStatus());
|
||||
assertTrue(response.getEntity().toString()
|
||||
.contains("Member must have length less than or equal to 128"));
|
||||
verifyNoInteractions(service);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("io.github.hectorvent.floci.testing.PartitionMatrix#cases")
|
||||
void getFederationTokenMintsTheFederatedUserArnInTheDeploymentsPartition(PartitionCase partitionCase) {
|
||||
|
||||
Reference in new issue
Block a user