diff --git a/docs/services/iam.md b/docs/services/iam.md index 01fb579aac..2646c9fc57 100644 --- a/docs/services/iam.md +++ b/docs/services/iam.md @@ -854,16 +854,41 @@ the shape. The length wording follows the captures of real IAM length violations bound the value broke and leaving the value itself out of the message. Either simulation action accepts only one `PermissionsBoundaryPolicyInputList` document, matching AWS's own documented limit; extra documents beyond the first are ignored. Neither evaluates a resource-based policy -(`ResourcePolicy`) or `OrderedOrganizationPolicyInputList`, and neither returns -`MatchedStatements`, `ResourceSpecificResults`, or a `PermissionsBoundaryDecisionDetail`: only the -top-level `EvalDecision` is populated, so which policy allowed an action is not reported even where -AWS names one, `PolicyInputList.1` in its own example for the principal simulator. -`ResourceHandlingOption` is accepted and read by neither action, so none of the EC2 scenarios it -names has its required resources enforced. +(`ResourcePolicy`), and neither returns `MatchedStatements`, `ResourceSpecificResults`, or a +`PermissionsBoundaryDecisionDetail`: only the top-level `EvalDecision` is populated, so which +policy allowed an action is not reported even where AWS names one, `PolicyInputList.1` in its own +example for the principal simulator. `ContextEntries.member.N.ContextKeyType` is accepted but not read; the comparison is driven entirely by the policy's own condition operator (`Bool`, `NumericEquals`, `DateEquals`, and so on), not by the declared type. +`OrderedOrganizationPolicyInputList` is read by both simulators, each member one level of an +Organizations hierarchy from the root to the account, and the levels gate the simulation the way +they gate the call it stands for: an action no level allows answers `implicitDeny`, a level that +denies it answers `explicitDeny` whatever the levels below it allow, and a level carrying no +statements is `FullAWSAccess` semantics and is skipped. A level whose document does not read as a +policy is an `InvalidInput` naming the item's position. The levels a call hands in are the whole of +the organization a simulation runs against: the SCPs the principal's own account sits under are not +applied, matching the console, which includes SCPs only when "AWS Organizations SCPs" is ticked. +One difference from AWS's simulator is known and open: AWS +documents that "the policy simulator doesn't evaluate SCPs that have global conditions", while this +walk evaluates a condition in an SCP exactly as the live evaluation does. So a simulation here can +decide a level AWS's simulator passes over, and the published sentence does not say whether what +AWS skips is the statement carrying the condition or the policy holding it. + +`ResourceHandlingOption` is read by both simulators, which hold a named scenario to the resources +it requires, "to enforce the presence of the required resources to ensure reliable simulation +results". All four published scenarios are VPC scenarios, so each needs an instance, an image, a +security group and a network interface; the `EBS` forms need a volume as well, and the `-Subnet` +forms a subnet. A resource `ResourceArns` does not name is an `InvalidInput` saying which type is +missing. +A value naming no published scenario is an `InvalidInput` as well, while a simulation that names no +scenario is left alone, since "if your simulation does not match one of the following scenarios, +then you can omit this parameter". Omitting the member is what is left alone rather than emptying +it: a value of nothing but space names no scenario, and a value carried empty is answered by the +member's declared minimum of one ahead of the operation. Both refusals are this emulator's wording: +AWS publishes the requirement but no message for breaking it. + `PolicyInputList` and `PermissionsBoundaryPolicyInputList` on `SimulatePrincipalPolicy` are read, the documents a simulation is handed beside the ones the principal holds. A `PolicyInputList` document is "an optional list of additional policy documents to include in the simulation", so each diff --git a/src/main/java/io/floci/aws/services/iam/IamPolicyEvaluator.java b/src/main/java/io/floci/aws/services/iam/IamPolicyEvaluator.java index 2c55edc6e7..29c2c7b4ee 100644 --- a/src/main/java/io/floci/aws/services/iam/IamPolicyEvaluator.java +++ b/src/main/java/io/floci/aws/services/iam/IamPolicyEvaluator.java @@ -435,11 +435,22 @@ public class IamPolicyEvaluator { List boundaryStmts = caller.boundaryPolicyDocument() == null ? null : parseAll(List.of(caller.boundaryPolicyDocument())); + // Organization levels gate a simulation the way they gate the call it stands for: the + // action must be allowed at every level and explicitly denied at none, before the input + // policies are consulted. This is the live path's own walk, so a simulation cannot answer + // differently from the request it models. + ScpWalk scp = scpWalk(caller.scpLevels(), loweredAction, resource, ctx); + if (scp.firstDeny() != null) { + return SimulationDecision.EXPLICIT_DENY; + } if (anyExplicitDeny(identityStmts, loweredAction, resource, ctx) || (sessionStmts != null && anyExplicitDeny(sessionStmts, loweredAction, resource, ctx)) || (boundaryStmts != null && anyExplicitDeny(boundaryStmts, loweredAction, resource, ctx))) { return SimulationDecision.EXPLICIT_DENY; } + if (!scp.allows()) { + return SimulationDecision.IMPLICIT_DENY; + } if (!anyExplicitAllow(identityStmts, loweredAction, resource, ctx)) { return SimulationDecision.IMPLICIT_DENY; } diff --git a/src/main/java/io/floci/aws/services/iam/IamQueryHandler.java b/src/main/java/io/floci/aws/services/iam/IamQueryHandler.java index d7e2757965..02fd441fb1 100644 --- a/src/main/java/io/floci/aws/services/iam/IamQueryHandler.java +++ b/src/main/java/io/floci/aws/services/iam/IamQueryHandler.java @@ -2190,10 +2190,20 @@ public class IamQueryHandler { PolicyExclusions exclusions = PolicyExclusions.from(params); List inputDocuments = readablePolicyInputList(params); String inputBoundary = inputBoundaryDocument(params); - CallerContext caller = withInputDocuments( - iamService.resolvePrincipalContext(policySourceArn, exclusions), inputDocuments, inputBoundary); - List actionNames = requireActionNames(params); + // SCPs enter a simulation only when the call asks for them, the way the console includes + // them only when "AWS Organizations SCPs" is ticked, so the levels the call handed in are + // the whole of the organization the simulation runs against. They are read where the other + // handed-in documents are, ahead of the lookup, so a principal that does not exist cannot + // answer for an input this operation refuses: that is the rule above, and these two inputs + // live under it as well. + List> scpLevels = organizationPolicyLevels(params); List resourceArns = extractResourceArnsOrWildcard(params); + SimulationScenarios.requireScenarioResources(params.getFirst("ResourceHandlingOption"), + resourceArns); + CallerContext caller = withInputDocuments( + iamService.resolvePrincipalContext(policySourceArn, exclusions), inputDocuments, inputBoundary) + .withScpLevels(scpLevels); + List actionNames = requireActionNames(params); // Keyed without regard to case, as the evaluator compares condition key names: a value // the call supplied has to shadow a populated one however the call spelled the key. Map> context = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); @@ -2218,12 +2228,57 @@ public class IamQueryHandler { private Response handleSimulateCustomPolicy(MultivaluedMap params) { List policyInputList = requirePolicyInputList(params); List actionNames = requireActionNames(params); + // Read before the scenario, as the principal simulation reads them, so a bad level and a + // bad scenario are answered in the same order whichever operation was called. + List> scpLevels = organizationPolicyLevels(params); List resourceArns = extractResourceArnsOrWildcard(params); + SimulationScenarios.requireScenarioResources(params.getFirst("ResourceHandlingOption"), + resourceArns); Map> context = extractContextEntries(params); - CallerContext caller = new CallerContext(policyInputList, null, inputBoundaryDocument(params)); + CallerContext caller = new CallerContext(policyInputList, null, inputBoundaryDocument(params), + scpLevels); return simulationResults("SimulateCustomPolicy", params, caller, actionNames, resourceArns, context); } + /** + * The service control policies a simulation was handed, one list per level of an + * organization. The member's reference describes both the shape and the order: "An ordered + * list of service control policies (SCPs) to include in the simulation. Each element + * represents one level of an Organizations hierarchy, from the organization root to the + * account. The simulator evaluates SCPs in the order that you provide, consistent with how + * Organizations enforces SCPs." So the levels go to the evaluator as the caller's effective + * SCPs, which is the walk a live request already takes through them, in the order the request + * wrote. How many levels there may be is the model's to say, seven on this list, and the + * declared constraints are read ahead of this. + * + *

Each document is held to being a policy document, as the documents of the other input + * lists are, and a level naming none is no level: a request that carries the member and + * nothing in it simulates with no organization above it rather than with an empty root. + */ + private List> organizationPolicyLevels(MultivaluedMap params) { + List> levels = new ArrayList<>(); + for (AwsQueryLists.IndexedMember level + : AwsQueryLists.members(params, "OrderedOrganizationPolicyInputList", null)) { + List documents = new ArrayList<>(); + for (AwsQueryLists.IndexedMember document : AwsQueryLists.members(params, + level.prefix() + ".ServiceControlPolicyInputList", null)) { + String policy = params.getFirst(document.prefix()); + if (policy == null) { + continue; + } + if (!policyEvaluator.readsAsPolicyDocument(policy)) { + throw new AwsException("InvalidInput", "Ordered organization policy input list" + + " item " + level.index() + " has invalid content", 400); + } + documents.add(policy); + } + if (!documents.isEmpty()) { + levels.add(List.copyOf(documents)); + } + } + return levels.isEmpty() ? null : List.copyOf(levels); + } + /** * The documents a principal simulation was handed beside the principal's own. * {@code PolicyInputList} is "an optional list of additional policy documents to include in diff --git a/src/main/java/io/floci/aws/services/iam/SimulationScenarios.java b/src/main/java/io/floci/aws/services/iam/SimulationScenarios.java new file mode 100644 index 0000000000..2e98f4bf65 --- /dev/null +++ b/src/main/java/io/floci/aws/services/iam/SimulationScenarios.java @@ -0,0 +1,93 @@ +package io.floci.aws.services.iam; + +import io.floci.aws.core.common.AwsArnUtils; +import io.floci.aws.core.common.AwsException; + +import java.util.List; +import java.util.Map; + +/** + * The simulation types {@code ResourceHandlingOption} names, and the resources each one has to be + * given. + * + *

The member's reference says what it is for: "Specifies the type of simulation to run. + * Different API operations that support resource-based policies require different combinations of + * resources. By specifying the type of simulation to run, you enable the policy simulator to + * enforce the presence of the required resources to ensure reliable simulation results." It then + * publishes the four scenarios and what each requires, which is what this holds: "Each of the + * Amazon EC2 scenarios requires that you specify instance, image, and security group resources. If + * your scenario includes an EBS volume, then you must specify that volume as a resource. If the + * Amazon EC2 scenario includes VPC, then you must supply the network interface resource. If it + * includes an IP subnet, then you must specify the subnet resource." + * + *

Two refusals here are this emulator's own wording. AWS publishes no sentence for a scenario + * whose resources are missing, nor for a value that names no scenario at all, and both are + * {@code InvalidInput}, the error both simulators model for "an invalid or out-of-range value + * supplied for an input parameter". The member's own length is held to the model ahead of this, + * as every declared constraint of these operations is. + */ +final class SimulationScenarios { + + /** Each published scenario and the EC2 resource types a simulation of it has to name. */ + private static final Map> REQUIRED = Map.of( + "EC2-VPC-InstanceStore", List.of("instance", "image", "security-group", + "network-interface"), + "EC2-VPC-InstanceStore-Subnet", List.of("instance", "image", "security-group", + "network-interface", "subnet"), + "EC2-VPC-EBS", List.of("instance", "image", "security-group", "network-interface", + "volume"), + "EC2-VPC-EBS-Subnet", List.of("instance", "image", "security-group", + "network-interface", "subnet", "volume")); + + private SimulationScenarios() { + } + + /** + * Holds a simulation to the resources its scenario requires, or passes a request that names no + * scenario: "If your simulation does not match one of the following scenarios, then you can + * omit this parameter." Omitting the member is what passes, not emptying it: a member the + * request carries is a value rather than a member it left out, so a value of nothing but + * spaces names no published scenario and is refused like any other value that names none. A + * member carried empty never reaches here, the declared minimum of one answering it ahead of + * this operation. + */ + static void requireScenarioResources(String option, List resourceArns) { + if (option == null) { + return; + } + List required = REQUIRED.get(option); + if (required == null) { + throw new AwsException("InvalidInput", "ResourceHandlingOption " + option + + " is not one of the simulation types this operation runs.", 400); + } + for (String type : required) { + if (!namesResourceOfType(resourceArns, type)) { + throw new AwsException("InvalidInput", "ResourceHandlingOption " + option + + " requires a resource of type " + type + " among the ResourceArns.", 400); + } + } + } + + /** Whether any resource ARN names an EC2 resource of {@code type}. */ + private static boolean namesResourceOfType(List resourceArns, String type) { + if (resourceArns == null) { + return false; + } + String prefix = type + "/"; + for (String arn : resourceArns) { + AwsArnUtils.Arn parsed; + try { + parsed = AwsArnUtils.parse(arn); + } catch (IllegalArgumentException ignored) { + // A value the parser refuses names no resource of any type, whether it was meant + // as an ARN or not, and the member that carried it is held to its shape elsewhere. + continue; + } + if ("ec2".equals(parsed.service()) && parsed.resource() != null + && parsed.resource().startsWith(prefix)) { + return true; + } + } + return false; + } +} diff --git a/src/test/java/io/floci/aws/services/iam/IamSimulateOrganizationAndScenarioIntegrationTest.java b/src/test/java/io/floci/aws/services/iam/IamSimulateOrganizationAndScenarioIntegrationTest.java new file mode 100644 index 0000000000..57fb41e13a --- /dev/null +++ b/src/test/java/io/floci/aws/services/iam/IamSimulateOrganizationAndScenarioIntegrationTest.java @@ -0,0 +1,266 @@ +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 java.util.List; + +import static io.restassured.RestAssured.given; +import static java.util.Collections.nCopies; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.equalTo; +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * The two simulation members both simulators used to answer as though they had not been sent. + * + *

{@code OrderedOrganizationPolicyInputList} is "an ordered list of service control policies + * (SCPs) to include in the simulation. Each element represents one level of an Organizations + * hierarchy, from the organization root to the account", evaluated "in the order that you provide, + * consistent with how Organizations enforces SCPs", which is what the levels do here: an action no + * level allows is denied, and one every level allows survives the walk. A simulation gates on the + * levels it was handed and on nothing else, the way the console includes SCPs only when "AWS + * Organizations SCPs" is ticked. + * + *

{@code ResourceHandlingOption} names the type of simulation, and by naming it "you enable the + * policy simulator to enforce the presence of the required resources to ensure reliable simulation + * results". So a scenario whose resources are not all named is refused rather than simulated, and + * the request that names no scenario is left alone. + * + *

Both are inputs, so both are answered where this package answers an input: ahead of the + * principal lookup, which cannot answer for a request the operation refuses. + */ +@QuarkusTest +class IamSimulateOrganizationAndScenarioIntegrationTest { + + private static final String IAM_AUTH = + "AWS4-HMAC-SHA256 Credential=test/20261115/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 CUSTOM_DECISION = "SimulateCustomPolicyResponse" + + ".SimulateCustomPolicyResult.EvaluationResults.member.EvalDecision"; + + private static final String PRINCIPAL_DECISION = "SimulatePrincipalPolicyResponse" + + ".SimulatePrincipalPolicyResult.EvaluationResults.member.EvalDecision"; + + private static final String INPUT = "PolicyInputList.member.1"; + private static final String LEVELS = "OrderedOrganizationPolicyInputList.member."; + + /** The EC2 resources the published scenarios require, as ARNs a simulation may name. */ + private static final String INSTANCE = "arn:aws:ec2:us-east-1:000000000000:instance/i-1"; + private static final String IMAGE = "arn:aws:ec2:us-east-1:000000000000:image/ami-1"; + private static final String SECURITY_GROUP = "arn:aws:ec2:us-east-1:000000000000:security-group/sg-1"; + private static final String NETWORK_INTERFACE = "arn:aws:ec2:us-east-1:000000000000:network-interface/eni-1"; + private static final String VOLUME = "arn:aws:ec2:us-east-1:000000000000:volume/vol-1"; + + /** The user the principal-side cases simulate outlives the class otherwise: the emulator is shared. */ + @RegisterExtension + final PartitionCleanup cleanup = new PartitionCleanup(); + + @Test + void anActionNoOrganizationLevelAllowsIsDeniedByTheLevelsTheCallHandedIn() { + // The input policy allows it, so what refuses it is the hierarchy above it. + RequestSpecification simulation = custom("s3:GetObject") + .formParam(LEVELS + "1.ServiceControlPolicyInputList.member.1", allow("s3:PutObject")); + + assertEquals("implicitDeny", decision(simulation, CUSTOM_DECISION)); + } + + @Test + void anActionEveryLevelAllowsSurvivesTheWalk() { + RequestSpecification simulation = custom("s3:GetObject") + .formParam(LEVELS + "1.ServiceControlPolicyInputList.member.1", allow("s3:*")) + .formParam(LEVELS + "2.ServiceControlPolicyInputList.member.1", allow("s3:GetObject")); + + assertEquals("allowed", decision(simulation, CUSTOM_DECISION)); + } + + @Test + void aLevelThatDeniesTakesTheActionWhateverTheLevelsBelowItSay() { + RequestSpecification simulation = custom("s3:GetObject") + .formParam(LEVELS + "1.ServiceControlPolicyInputList.member.1", deny("s3:GetObject")) + .formParam(LEVELS + "2.ServiceControlPolicyInputList.member.1", allow("s3:*")) + .formParam(LEVELS + "3.ServiceControlPolicyInputList.member.1", allow("s3:GetObject")); + + assertEquals("explicitDeny", decision(simulation, CUSTOM_DECISION)); + } + + @Test + void aLevelCarryingNoPolicyDocumentIsRefusedLikeAnyInputDocument() { + custom("s3:GetObject") + .formParam(LEVELS + "1.ServiceControlPolicyInputList.member.1", "{not-a-policy") + .when().post("/").then().statusCode(400) + .body(CODE, equalTo("InvalidInput")); + } + + @Test + void theLevelsGateAPrincipalSimulationTheSameWay() { + String userName = createUserAllowed("s3:GetObject"); + + assertEquals("explicitDeny", decision(simulatePrincipal(userName, "s3:GetObject") + .formParam(LEVELS + "1.ServiceControlPolicyInputList.member.1", deny("s3:GetObject")), + PRINCIPAL_DECISION)); + // The same principal, asked without the levels: the deny came from them and nowhere else. + assertEquals("allowed", decision(simulatePrincipal(userName, "s3:GetObject"), PRINCIPAL_DECISION)); + } + + @Test + void aScenarioIsHeldToTheResourcesItRequires() { + // Instance, image and security group named, network interface left out. + custom("ec2:StartInstances") + .formParam("ResourceArns.member.1", INSTANCE) + .formParam("ResourceArns.member.2", IMAGE) + .formParam("ResourceArns.member.3", SECURITY_GROUP) + .formParam("ResourceHandlingOption", "EC2-VPC-InstanceStore") + .when().post("/").then().statusCode(400) + .body(CODE, equalTo("InvalidInput")) + .body(MESSAGE, containsString("network-interface")); + } + + @Test + void aScenarioIsHeldToItsResourcesOnAPrincipalSimulationToo() { + String userName = createUserAllowed("ec2:StartInstances"); + + simulatePrincipal(userName, "ec2:StartInstances") + .formParam("ResourceHandlingOption", "EC2-VPC-EBS") + .when().post("/").then().statusCode(400) + .body(CODE, equalTo("InvalidInput")); + } + + @Test + void aScenarioWhoseResourcesAreAllNamedSimulates() { + RequestSpecification simulation = custom("ec2:StartInstances") + .formParam("ResourceArns.member.1", INSTANCE) + .formParam("ResourceArns.member.2", IMAGE) + .formParam("ResourceArns.member.3", SECURITY_GROUP) + .formParam("ResourceArns.member.4", NETWORK_INTERFACE) + .formParam("ResourceArns.member.5", VOLUME) + .formParam("ResourceHandlingOption", "EC2-VPC-EBS"); + + // One result per resource named, as every simulation answers, and the scenario is complete. + assertEquals(nCopies(5, "allowed"), decisions(simulation, CUSTOM_DECISION)); + } + + @Test + void aValueNamingNoScenarioIsRefused() { + custom("s3:GetObject") + .formParam("ResourceHandlingOption", "EC2-Classic") + .when().post("/").then().statusCode(400) + .body(CODE, equalTo("InvalidInput")); + } + + @Test + void aSimulationNamingNoScenarioIsLeftAlone() { + assertEquals("allowed", decision(custom("s3:GetObject"), CUSTOM_DECISION)); + } + + /** + * Omitting the member is what is left alone, not emptying it. A member the request carries is + * a value rather than a member it left out, so a value of nothing but space names no published + * scenario and is refused like any other value that names none. The value carried empty never + * reaches the scenario at all: the member's declared minimum of one answers it, in the layer + * that runs ahead of the operation. + */ + @Test + void aScenarioValueOfNothingButSpaceNamesNoScenario() { + custom("s3:GetObject") + .formParam("ResourceHandlingOption", " ") + .when().post("/").then().statusCode(400) + .body(CODE, equalTo("InvalidInput")); + + custom("s3:GetObject") + .formParam("ResourceHandlingOption", "") + .when().post("/").then().statusCode(400) + .body(CODE, equalTo("ValidationError")) + .body(MESSAGE, containsString("length greater than or equal to 1")); + } + + /** + * Both members are read where the handed-in documents are read, ahead of the principal lookup, + * so a request that carries one of them broken and names nobody is answered for the input it + * supplied rather than for the entity it did not find. + */ + @Test + void anUnknownPrincipalDoesNotAnswerForAnInputTheOperationRefuses() { + String absent = "simulate-levels-absent-" + System.nanoTime(); + + // Nothing else wrong with the request: the lookup is what answers it. + simulatePrincipal(absent, "s3:GetObject") + .when().post("/").then().statusCode(404) + .body(CODE, equalTo("NoSuchEntity")); + + simulatePrincipal(absent, "s3:GetObject") + .formParam(LEVELS + "1.ServiceControlPolicyInputList.member.1", "{not-a-policy") + .when().post("/").then().statusCode(400) + .body(CODE, equalTo("InvalidInput")); + + simulatePrincipal(absent, "s3:GetObject") + .formParam("ResourceHandlingOption", "EC2-Classic") + .when().post("/").then().statusCode(400) + .body(CODE, equalTo("InvalidInput")); + } + + private static RequestSpecification iam(String action) { + return given().header("Authorization", IAM_AUTH) + .formParam("Action", action) + .formParam("Version", "2010-05-08"); + } + + private static RequestSpecification custom(String actionName) { + return iam("SimulateCustomPolicy") + .formParam(INPUT, allow(actionName)) + .formParam("ActionNames.member.1", actionName); + } + + private static RequestSpecification simulatePrincipal(String userName, String actionName) { + return iam("SimulatePrincipalPolicy") + .formParam("PolicySourceArn", "arn:aws:iam::" + ACCOUNT + ":user/" + userName) + .formParam("ActionNames.member.1", actionName) + .formParam("ResourceArns.member.1", "*"); + } + + /** A user holding one inline policy that allows the action, so only the levels can refuse it. */ + private String createUserAllowed(String actionName) { + String userName = "simulate-levels-" + System.nanoTime(); + iam("CreateUser").formParam("UserName", userName).when().post("/").then().statusCode(200); + cleanup.register(() -> iam("DeleteUser").formParam("UserName", userName) + .when().post("/").then().statusCode(200)); + iam("PutUserPolicy").formParam("UserName", userName).formParam("PolicyName", "allow-it") + .formParam("PolicyDocument", allow(actionName)) + .when().post("/").then().statusCode(200); + cleanup.register(() -> iam("DeleteUserPolicy").formParam("UserName", userName) + .formParam("PolicyName", "allow-it").when().post("/").then().statusCode(200)); + return userName; + } + + private static String decision(RequestSpecification simulation, String path) { + List decisions = decisions(simulation, path); + assertEquals(1, decisions.size(), "one action and one resource answer once"); + return decisions.getFirst(); + } + + private static List decisions(RequestSpecification simulation, String path) { + return simulation.when().post("/").then().statusCode(200) + .extract().xmlPath().getList(path); + } + + private static String allow(String action) { + return document("Allow", action); + } + + private static String deny(String action) { + return document("Deny", action); + } + + private static String document(String effect, String action) { + return "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"" + effect + "\"," + + "\"Action\":\"" + action + "\",\"Resource\":\"*\"}]}"; + } +}