fix(iam): read the documents a request supplies, and hold each to being a policy (#8164)

`SimulatePrincipalPolicy` read neither `PolicyInputList` nor
`PermissionsBoundaryPolicyInputList`, so a caller testing a policy it has not
attached, or a boundary other than the stored one, was answered about the
principal as it stands: a decision about a question nobody asked. Both members
have published behaviour, and `SimulateCustomPolicy` already read both, the
documents being its whole input, so this is the principal simulator dropping two
of its own.

A `PolicyInputList` document is "an optional list of additional policy documents
to include in the simulation", so each is evaluated with the weight of a policy
the principal holds: an allow in one allows an action the attached policies do
not, which is what the operation's own example in the API Reference turns on, and
a deny in one stops an action they allow. A `PermissionsBoundaryPolicyInputList`
document is the boundary that simulation runs with in place of the stored one,
"if a permissions boundary is attached to an entity and you pass in a different
permissions boundary policy using this parameter, then the new permissions
boundary policy is used for the simulation", and it is the boundary when the
entity carries none, the member being "the IAM permissions boundary policy to
simulate". The one-document limit both simulators are held to is read in one
place now rather than two.

Neither document is attached to anything, so no `PolicyExclusionList` identifier
reaches either: that member names the policies "actually attached to the
principal", where these are the request's own. A simulation leaving out every
part a `PolicyType` can name therefore still carries what the request handed in,
and a boundary handed in still holds the simulation down where the stored one was
left out.

Reading a document means being able to read it, so each supplied document is held
to the grammar before anything is decided from it. Four operations take
`PolicyInputList`, the two simulators and the two context-key readers, and each
takes "the complete, valid JSON text of an IAM policy". A text that does not
parse as a JSON object, and an object carrying no `Statement`, "the main element
for a policy. This element is required.", are both refused with the modelled
`InvalidInput`, 400, naming the entry by the index the request numbered it with.
A supplied permissions boundary carries the sentence that names no entry, the
member taking one document. Without that, an unreadable document was answered as
though the request had carried nothing at all: an unreadable identity document
left an attached allow still allowing, and an unreadable boundary was worse,
becoming a ceiling that allows nothing and turning an allow into an implicit
deny.

The 500 `PolicyEvaluation` the two simulators model is not that answer. It
carries no sender fault where `InvalidInput` does, and the two context-key
readers take this same member and model no `PolicyEvaluation` at all, so one
defect on one member would otherwise be answered two ways across the four
operations that take it.

A document already stored is read as it always was: it contributes no statements
and the decision is made on the rest, because a policy the account accepted once
must not make every later call fail. The supplied documents are read ahead of the
principal lookup now, which is where this package answers an input.

Either supplied document is also held to the shape the model declares, so one
past 131072 characters is a `ValidationError` naming the member under the index
the request numbered it with. The boundary list was read by the constraint walk
already; `PolicyInputList` was carried by hand for both simulators, which only
`SimulateCustomPolicy` needs: it requires the member and answers an empty list in
its own wording, "At least one PolicyInputList member is required.", where
`SimulatePrincipalPolicy` leaves the member optional and so has nothing of its
own in front of the walk. So the generator's exemption drops that operation and
the vendored shapes are regenerated from the pinned model, which adds the one
member to `SimulatePrincipalPolicyRequest`.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-12 20:59:23 -04:00
1 parent 40ec27593e
commit 623bb15283
9 files changed
+766 -24

No files matched your search

@@ -6,6 +6,7 @@ import io.floci.aws.core.common.AwsServiceNamespaces;
import io.floci.aws.services.iam.IamPolicyEvaluator.Decision;
import io.floci.aws.services.iam.IamPolicyEvaluator.ResourceAccountRelationship;
import io.floci.aws.services.iam.IamPolicyEvaluator.ResourcePolicyDecision;
import io.floci.aws.services.iam.IamPolicyEvaluator.SimulationDecision;
import io.floci.aws.services.iam.model.CallerContext;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
@@ -1460,6 +1461,44 @@ class IamPolicyEvaluatorTest {
List.of(List.of(), List.of(ALLOW_S3_ONLY))));
}
/**
* What a request supplies has to read as a policy document: an object carrying the element the
* grammar requires of every policy, {@code Statement}, "the main element for a policy. This
* element is required." A text that does not parse, JSON that is no object, and an object
* without that element are alike no policy, which is why one sentence refuses all three.
*/
@Test
void aSuppliedDocumentReadsAsAPolicyOnlyWithTheElementTheGrammarRequires() {
assertTrue(evaluator.readsAsPolicyDocument(ALLOW_ALL));
assertTrue(evaluator.readsAsPolicyDocument("{\"Statement\":{\"Effect\":\"Allow\","
+ "\"Action\":\"*\",\"Resource\":\"*\"}}"));
assertTrue(evaluator.readsAsPolicyDocument("{\"Version\":\"2012-10-17\",\"Statement\":[]}"));
assertFalse(evaluator.readsAsPolicyDocument(MALFORMED));
assertFalse(evaluator.readsAsPolicyDocument("{not json"));
assertFalse(evaluator.readsAsPolicyDocument("[]"));
assertFalse(evaluator.readsAsPolicyDocument("7"));
assertFalse(evaluator.readsAsPolicyDocument("{}"));
assertFalse(evaluator.readsAsPolicyDocument("{\"Version\":\"2012-10-17\"}"));
assertFalse(evaluator.readsAsPolicyDocument(" "));
assertFalse(evaluator.readsAsPolicyDocument(null));
}
/**
* The reading above answers an input and nothing else. A document already stored stays as it
* was read: it contributes no statements and the decision is made on the rest, because a
* policy the account accepted once must not make every later call fail.
*/
@Test
void aStoredDocumentThatIsNoPolicyStillLeavesTheDecisionToTheRest() {
assertEquals(Decision.ALLOW,
evaluator.evaluate(List.of(MALFORMED, ALLOW_S3_ONLY), "s3:GetObject", "*"));
assertEquals(SimulationDecision.IMPLICIT_DENY, evaluator.simulatePrincipalPolicy(
CallerContext.of(List.of(MALFORMED)), "s3:GetObject", "*", Map.of()));
assertEquals(SimulationDecision.ALLOWED, evaluator.simulatePrincipalPolicy(
CallerContext.of(List.of(MALFORMED, ALLOW_S3_ONLY)), "s3:GetObject", "*", Map.of()));
}
private static String allowOnlyAction(String action) {
return "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\","
+ "\"Action\":\"" + action + "\",\"Resource\":\"*\"}]}";
@@ -0,0 +1,318 @@
package io.floci.aws.services.iam;
import io.floci.aws.testing.PartitionCleanup;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.specification.RequestSpecification;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* The two documents {@code SimulatePrincipalPolicy} takes beside the principal's own policies.
* {@code PolicyInputList} is "an optional list of additional policy documents to include in the
* simulation", and a {@code PermissionsBoundaryPolicyInputList} document stands in for the stored
* boundary: "if a permissions boundary is attached to an entity and you pass in a different
* permissions boundary policy using this parameter, then the new permissions boundary policy is
* used for the simulation".
*
* <p>Each test asks the same question twice, once with the documents and once without, since what
* these members change is the answer rather than anything stored. Neither document is attached to
* the principal, which is why the exclusion list reaches neither.
*/
@QuarkusTest
class IamSimulatePrincipalInputDocumentsIntegrationTest {
private static final String IAM_AUTH =
"AWS4-HMAC-SHA256 Credential=test/20261109/us-east-1/iam/aws4_request";
private static final String ACCOUNT = "000000000000";
private static final String CODE = "ErrorResponse.Error.Code";
private static final String MESSAGE = "ErrorResponse.Error.Message";
private static final String DECISION = "SimulatePrincipalPolicyResponse"
+ ".SimulatePrincipalPolicyResult.EvaluationResults.member.EvalDecision";
private static final String CUSTOM_DECISION = "SimulateCustomPolicyResponse"
+ ".SimulateCustomPolicyResult.EvaluationResults.member.EvalDecision";
private static final String INPUT = "PolicyInputList.member.";
private static final String BOUNDARY = "PermissionsBoundaryPolicyInputList.member.";
/** One character past the 131072 a policy document is declared with. */
private static final int PAST_THE_MAXIMUM = 131073;
/** Everything these tests create outlives the class otherwise: the emulator is shared. */
@RegisterExtension
final PartitionCleanup cleanup = new PartitionCleanup();
private static RequestSpecification iam(String action) {
return given().header("Authorization", IAM_AUTH).formParam("Action", action);
}
private static String unique(String prefix) {
return prefix + "-" + System.nanoTime();
}
private static String document(String effect, String action) {
return "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"" + effect + "\","
+ "\"Action\":\"" + action + "\",\"Resource\":\"*\"}]}";
}
private static String allow(String action) {
return document("Allow", action);
}
private static String deny(String action) {
return document("Deny", action);
}
private static String userArn(String userName) {
return "arn:aws:iam::" + ACCOUNT + ":user/" + userName;
}
private String createUser(String prefix) {
String userName = unique(prefix);
iam("CreateUser").formParam("UserName", userName).when().post("/").then().statusCode(200);
cleanup.register(() -> iam("DeleteUser").formParam("UserName", userName)
.when().post("/").then().statusCode(200));
return userName;
}
private String createPolicy(String prefix, String action) {
String arn = iam("CreatePolicy").formParam("PolicyName", unique(prefix))
.formParam("PolicyDocument", allow(action))
.when().post("/").then().statusCode(200)
.extract().xmlPath().getString("CreatePolicyResponse.CreatePolicyResult.Policy.Arn");
cleanup.register(() -> iam("DeletePolicy").formParam("PolicyArn", arn)
.when().post("/").then().statusCode(200));
return arn;
}
private String attachNewPolicy(String userName, String prefix, String action) {
String policyArn = createPolicy(prefix, action);
iam("AttachUserPolicy").formParam("UserName", userName).formParam("PolicyArn", policyArn)
.when().post("/").then().statusCode(200);
cleanup.register(() -> iam("DetachUserPolicy").formParam("UserName", userName)
.formParam("PolicyArn", policyArn).when().post("/").then().statusCode(200));
return policyArn;
}
private String putUserPolicy(String userName, String prefix, String action) {
String policyName = unique(prefix);
iam("PutUserPolicy").formParam("UserName", userName).formParam("PolicyName", policyName)
.formParam("PolicyDocument", allow(action))
.when().post("/").then().statusCode(200);
cleanup.register(() -> iam("DeleteUserPolicy").formParam("UserName", userName)
.formParam("PolicyName", policyName).when().post("/").then().statusCode(200));
return policyName;
}
private String putBoundary(String userName, String action) {
String boundaryArn = createPolicy("input-boundary", action);
iam("PutUserPermissionsBoundary").formParam("UserName", userName)
.formParam("PermissionsBoundary", boundaryArn)
.when().post("/").then().statusCode(200);
cleanup.register(() -> iam("DeleteUserPermissionsBoundary").formParam("UserName", userName)
.when().post("/").then().statusCode(200));
return boundaryArn;
}
private static RequestSpecification simulate(String userName, String action) {
return iam("SimulatePrincipalPolicy")
.formParam("PolicySourceArn", userArn(userName))
.formParam("ActionNames.member.1", action)
.formParam("ResourceArns.member.1", "*");
}
/** The same simulation with every part a {@code PolicyType} can name left out. */
private static RequestSpecification simulateWithEveryPartExcluded(String userName, String action) {
return simulate(userName, action)
.formParam("PolicyExclusionList.member.1.PolicyType", "inline")
.formParam("PolicyExclusionList.member.2.PolicyType", "aws-managed")
.formParam("PolicyExclusionList.member.3.PolicyType", "user-managed")
.formParam("PolicyExclusionList.member.4.PolicyType", "permission-boundary");
}
private static String decision(RequestSpecification request) {
return request.when().post("/").then().statusCode(200)
.extract().xmlPath().getString(DECISION);
}
/**
* AWS's own example for this operation: a user whose policies do not allow the action is
* allowed it on the strength of an input document alone.
*/
@Test
void anInputDocumentAllowsWhatThePrincipalHasNoPolicyFor() {
String user = createUser("input-allow");
assertEquals("implicitDeny", decision(simulate(user, "s3:PutObject")));
assertEquals("allowed", decision(simulate(user, "s3:PutObject")
.formParam(INPUT + "1", allow("s3:PutObject"))));
}
/** The documents are additional, so the principal's own policies still decide beside them. */
@Test
void thePrincipalsOwnPoliciesCountBesideTheDocument() {
String user = createUser("input-beside");
attachNewPolicy(user, "input-reader", "s3:GetObject");
assertEquals("allowed", decision(simulate(user, "s3:GetObject")
.formParam(INPUT + "1", allow("s3:PutObject"))));
assertEquals("allowed", decision(simulate(user, "s3:PutObject")
.formParam(INPUT + "1", allow("s3:PutObject"))));
}
/** A document is evaluated like a policy the principal holds, deny and all. */
@Test
void aDocumentsDenyStopsWhatAnAttachedPolicyAllows() {
String user = createUser("input-deny");
attachNewPolicy(user, "input-reader", "s3:GetObject");
assertEquals("allowed", decision(simulate(user, "s3:GetObject")));
assertEquals("explicitDeny", decision(simulate(user, "s3:GetObject")
.formParam(INPUT + "1", deny("s3:GetObject"))));
}
/** Every index the request numbers is read, the bare spelling and a gap among them. */
@Test
void everyDocumentTheRequestNumbersIsRead() {
String user = createUser("input-indices");
assertEquals("allowed", decision(simulate(user, "ec2:RunInstances")
.formParam(INPUT + "1", allow("s3:GetObject"))
.formParam(INPUT + "2", allow("ec2:RunInstances"))));
assertEquals("allowed", decision(simulate(user, "ec2:RunInstances")
.formParam(INPUT + "1", allow("s3:GetObject"))
.formParam(INPUT + "3", allow("ec2:RunInstances"))));
assertEquals("allowed", decision(simulate(user, "s3:PutObject")
.formParam("PolicyInputList.1", allow("s3:PutObject"))));
}
/**
* "An IAM entity can only have one permissions boundary in effect at a time": a boundary
* handed in replaces the stored one rather than joining it, so the action the stored boundary
* refused is allowed and the one it allowed is not.
*/
@Test
void aBoundaryHandedInStandsInForTheStoredOne() {
String user = createUser("input-boundary-swap");
attachNewPolicy(user, "input-reader", "s3:GetObject");
attachNewPolicy(user, "input-runner", "ec2:RunInstances");
putBoundary(user, "ec2:RunInstances");
assertEquals("implicitDeny", decision(simulate(user, "s3:GetObject")));
assertEquals("allowed", decision(simulate(user, "s3:GetObject")
.formParam(BOUNDARY + "1", allow("s3:GetObject"))));
assertEquals("implicitDeny", decision(simulate(user, "ec2:RunInstances")
.formParam(BOUNDARY + "1", allow("s3:GetObject"))));
}
/** The member is "the IAM permissions boundary policy to simulate", stored one or not. */
@Test
void aBoundaryHandedInAppliesWhenNoneIsStored() {
String user = createUser("input-boundary-only");
attachNewPolicy(user, "input-reader", "s3:GetObject");
assertEquals("allowed", decision(simulate(user, "s3:GetObject")));
assertEquals("implicitDeny", decision(simulate(user, "s3:GetObject")
.formParam(BOUNDARY + "1", allow("ec2:RunInstances"))));
assertEquals("implicitDeny", decision(simulate(user, "s3:GetObject")
.formParam("PermissionsBoundaryPolicyInputList.1", allow("ec2:RunInstances"))));
}
/**
* "You can input only one permissions boundary when you pass a policy to this operation", so
* the first document decides and the rest are left out, whichever way round they arrive.
*/
@Test
void onlyTheFirstBoundaryDocumentIsApplied() {
String user = createUser("input-boundary-first");
attachNewPolicy(user, "input-reader", "s3:GetObject");
assertEquals("allowed", decision(simulate(user, "s3:GetObject")
.formParam(BOUNDARY + "1", allow("s3:GetObject"))
.formParam(BOUNDARY + "2", allow("ec2:RunInstances"))));
assertEquals("implicitDeny", decision(simulate(user, "s3:GetObject")
.formParam(BOUNDARY + "1", allow("ec2:RunInstances"))
.formParam(BOUNDARY + "2", allow("s3:GetObject"))));
}
/** Both simulators read that one boundary document through the same reader. */
@Test
void theCustomSimulatorReadsItsBoundaryTheSameWay() {
String decision = iam("SimulateCustomPolicy")
.formParam("PolicyInputList.member.1", allow("s3:GetObject"))
.formParam("ActionNames.member.1", "s3:GetObject")
.formParam("ResourceArns.member.1", "*")
.formParam(BOUNDARY + "1", allow("ec2:RunInstances"))
.formParam(BOUNDARY + "2", allow("s3:GetObject"))
.when().post("/").then().statusCode(200)
.extract().xmlPath().getString(CUSTOM_DECISION);
assertEquals("implicitDeny", decision);
}
/**
* {@code PolicyExclusionList} names the policies "actually attached to the principal", and a
* document the request handed in is attached to nothing: a simulation that leaves out every
* part a type can name still carries it, and a boundary handed in still holds the simulation
* down even where the stored boundary was excluded.
*/
@Test
void noExclusionIdentifierReachesWhatTheRequestHandedIn() {
String user = createUser("input-exclusion");
attachNewPolicy(user, "input-reader", "s3:GetObject");
putUserPolicy(user, "input-own", "s3:GetObject");
putBoundary(user, "s3:GetObject");
assertEquals("implicitDeny", decision(simulateWithEveryPartExcluded(user, "s3:GetObject")));
assertEquals("allowed", decision(simulateWithEveryPartExcluded(user, "s3:GetObject")
.formParam(INPUT + "1", allow("s3:GetObject"))));
assertEquals("implicitDeny", decision(simulateWithEveryPartExcluded(user, "s3:GetObject")
.formParam(INPUT + "1", allow("s3:GetObject"))
.formParam(BOUNDARY + "1", allow("ec2:RunInstances"))));
}
/**
* The constraints ahead of the operation hold either document to the shape the model declares
* for a policy document, so one past the declared maximum is answered before the simulation
* runs rather than parsed into a document that matches nothing. Each is named under the index
* the request numbered it with.
*/
@Test
void eitherDocumentIsHeldToTheShapeTheModelDeclares() {
String user = createUser("input-shape");
simulate(user, "s3:GetObject")
.formParam(BOUNDARY + "1", "a".repeat(PAST_THE_MAXIMUM))
.when().post("/").then().statusCode(400)
.body(CODE, equalTo("ValidationError"))
.body(MESSAGE, containsString("permissionsBoundaryPolicyInputList.1.member"));
simulate(user, "s3:GetObject")
.formParam(INPUT + "2", "a".repeat(PAST_THE_MAXIMUM))
.when().post("/").then().statusCode(400)
.body(CODE, equalTo("ValidationError"))
.body(MESSAGE, containsString("policyInputList.2.member"));
}
/**
* The custom simulator keeps the sentence it answers an empty list with, which is why the
* member is carried by hand in the generated constraints there and read from the model here:
* it is required on that operation and optional on this one.
*/
@Test
void theCustomSimulatorKeepsItsOwnWordingForAnEmptyList() {
iam("SimulateCustomPolicy")
.formParam("ActionNames.member.1", "s3:GetObject")
.when().post("/").then().statusCode(400)
.body(CODE, equalTo("ValidationError"))
.body(MESSAGE, equalTo("At least one PolicyInputList member is required."));
}
}
@@ -0,0 +1,218 @@
package io.floci.aws.services.iam;
import io.floci.aws.testing.PartitionCleanup;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.specification.RequestSpecification;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* A policy document a request supplies has to read as one before anything is decided from it.
* Four operations take {@code PolicyInputList}, the two simulators and the two context-key
* readers, and each takes "the complete, valid JSON text of an IAM policy", so a value that is no
* policy document is an input they answer: a 400 {@code InvalidInput} naming the entry by the
* index it arrived under.
*
* <p>Two values fail that reading: one that does not parse as a JSON object, and one that parses
* as an object carrying no {@code Statement}, "the main element for a policy. This element is
* required." A supplied permissions boundary is held to the same rule under the one sentence that
* names no entry, the member carrying a single document.
*
* <p>The 500 {@code PolicyEvaluation} the simulators model is answered by neither: it carries no
* sender fault where {@code InvalidInput} does, and the context-key readers take the same member
* and model no {@code PolicyEvaluation} at all.
*/
@QuarkusTest
class IamSuppliedPolicyDocumentIntegrationTest {
private static final String IAM_AUTH =
"AWS4-HMAC-SHA256 Credential=test/20261112/us-east-1/iam/aws4_request";
private static final String ACCOUNT = "000000000000";
private static final String CODE = "ErrorResponse.Error.Code";
private static final String MESSAGE = "ErrorResponse.Error.Message";
private static final String INPUT = "PolicyInputList.member.";
private static final String BOUNDARY = "PermissionsBoundaryPolicyInputList.member.";
private static final String CUSTOM_DECISION = "SimulateCustomPolicyResponse"
+ ".SimulateCustomPolicyResult.EvaluationResults.member.EvalDecision";
private static final String PRINCIPAL_DECISION = "SimulatePrincipalPolicyResponse"
+ ".SimulatePrincipalPolicyResult.EvaluationResults.member.EvalDecision";
/** The sentence an entry of the list is refused with, carrying the index it arrived under. */
private static final String ITEM_REFUSAL = "Policy input list item %s has invalid content";
/** The sentence every other supplied document is refused with, naming no entry. */
private static final String DOCUMENT_REFUSAL = "Syntax errors in policy.";
/** Everything these tests create outlives the class otherwise: the emulator is shared. */
@RegisterExtension
final PartitionCleanup cleanup = new PartitionCleanup();
private static RequestSpecification iam(String action) {
return given().header("Authorization", IAM_AUTH).formParam("Action", action);
}
private static String unique(String prefix) {
return prefix + "-" + System.nanoTime();
}
private static String userArn(String userName) {
return "arn:aws:iam::" + ACCOUNT + ":user/" + userName;
}
private static String allow(String action) {
return "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\","
+ "\"Action\":\"" + action + "\",\"Resource\":\"*\"}]}";
}
private String createUser(String prefix) {
String userName = unique(prefix);
iam("CreateUser").formParam("UserName", userName).when().post("/").then().statusCode(200);
cleanup.register(() -> iam("DeleteUser").formParam("UserName", userName)
.when().post("/").then().statusCode(200));
return userName;
}
private static RequestSpecification simulateCustom() {
return iam("SimulateCustomPolicy")
.formParam("ActionNames.member.1", "s3:GetObject")
.formParam("ResourceArns.member.1", "*");
}
private static RequestSpecification simulatePrincipal(String policySourceArn) {
return iam("SimulatePrincipalPolicy")
.formParam("PolicySourceArn", policySourceArn)
.formParam("ActionNames.member.1", "s3:GetObject")
.formParam("ResourceArns.member.1", "*");
}
private static void expectItemRefused(RequestSpecification request, String index) {
request.when().post("/").then().statusCode(400)
.body(CODE, equalTo("InvalidInput"))
.body(MESSAGE, equalTo(ITEM_REFUSAL.formatted(index)));
}
private static void expectDocumentRefused(RequestSpecification request) {
request.when().post("/").then().statusCode(400)
.body(CODE, equalTo("InvalidInput"))
.body(MESSAGE, equalTo(DOCUMENT_REFUSAL));
}
/**
* A text that is no JSON object carries none of the top-level elements of the policy grammar,
* whether it is not JSON at all or JSON of another kind.
*/
@Test
void aDocumentThatIsNoJsonObjectIsRefusedByTheIndexItArrivedUnder() {
expectItemRefused(simulateCustom().formParam(INPUT + "1", "{not json"), "1");
expectItemRefused(simulateCustom().formParam(INPUT + "1", "[]"), "1");
expectItemRefused(simulateCustom().formParam(INPUT + "1", "7"), "1");
}
/**
* "The Statement element is the main element for a policy. This element is required.", so an
* object without it is no more a policy than a text that does not parse, and the refusal does
* not tell the two apart.
*/
@Test
void aDocumentCarryingNoStatementIsRefusedTheSameWay() {
expectItemRefused(simulateCustom().formParam(INPUT + "1", "{}"), "1");
expectItemRefused(simulateCustom()
.formParam(INPUT + "1", "{\"Version\":\"2012-10-17\"}"), "1");
}
/**
* The member carries several documents, so the refusal names which one it refused, by the
* index the request numbered it with rather than by its place among the documents read. Both
* spellings of the member are numbered the same way.
*/
@Test
void theRefusalNamesTheIndexTheRequestNumberedItWith() {
expectItemRefused(simulateCustom()
.formParam(INPUT + "1", allow("s3:GetObject"))
.formParam(INPUT + "3", "{}"), "3");
expectItemRefused(simulateCustom()
.formParam("PolicyInputList.2", "{}"), "2");
}
/**
* The rule stops at the element the grammar requires: a document carrying an empty
* {@code Statement} describes no permission, which is a policy that allows nothing rather than
* a value the operation cannot read.
*/
@Test
void aStatementElementThatGrantsNothingIsStillADocument() {
assertEquals("implicitDeny", simulateCustom()
.formParam(INPUT + "1", "{\"Version\":\"2012-10-17\",\"Statement\":[]}")
.when().post("/").then().statusCode(200)
.extract().xmlPath().getString(CUSTOM_DECISION));
}
/** The principal simulator reads the same member, so it answers the same way. */
@Test
void thePrincipalSimulatorRefusesTheSameDocuments() {
String user = createUser("supplied-document");
expectItemRefused(simulatePrincipal(userArn(user)).formParam(INPUT + "1", "{not json"), "1");
expectItemRefused(simulatePrincipal(userArn(user)).formParam(INPUT + "2", "{}"), "2");
assertEquals("allowed", simulatePrincipal(userArn(user))
.formParam(INPUT + "1", allow("s3:GetObject"))
.when().post("/").then().statusCode(200)
.extract().xmlPath().getString(PRINCIPAL_DECISION));
}
/**
* The documents are read where this package answers an input, ahead of the principal lookup,
* so a request that both hands in an unreadable document and names nobody is answered for the
* document it supplied rather than for the entity it did not find.
*/
@Test
void aSuppliedDocumentIsAnsweredAheadOfThePrincipalLookup() {
String absent = userArn(unique("supplied-absent"));
simulatePrincipal(absent).when().post("/").then().statusCode(404)
.body(CODE, equalTo("NoSuchEntity"));
expectItemRefused(simulatePrincipal(absent).formParam(INPUT + "1", "{}"), "1");
}
/**
* A supplied permissions boundary is one document, so the refusal identifies none and carries
* the sentence that names no entry.
*/
@Test
void aSuppliedBoundaryThatIsNoPolicyDocumentIsRefused() {
String user = createUser("supplied-boundary");
expectDocumentRefused(simulateCustom()
.formParam(INPUT + "1", allow("s3:GetObject"))
.formParam(BOUNDARY + "1", "{}"));
expectDocumentRefused(simulatePrincipal(userArn(user))
.formParam(BOUNDARY + "1", "{not json"));
}
/**
* Both context-key readers take the same member and model {@code InvalidInput} with no
* {@code PolicyEvaluation} at all, which is what settles the answer for the simulators too.
*/
@Test
void bothContextKeyReadersRefuseWhatTheSimulatorsDo() {
String user = createUser("supplied-context-keys");
expectItemRefused(iam("GetContextKeysForCustomPolicy")
.formParam(INPUT + "1", "{}"), "1");
expectItemRefused(iam("GetContextKeysForPrincipalPolicy")
.formParam("PolicySourceArn", userArn(user))
.formParam(INPUT + "1", "{not json"), "1");
iam("GetContextKeysForCustomPolicy")
.formParam(INPUT + "1", allow("s3:GetObject"))
.when().post("/").then().statusCode(200);
}
}