-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add tests for
GuAllowPolicy
and GuDenyPolicy
Quite simple tests to demonstrate these two helper constructs.
- Loading branch information
Showing
1 changed file
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import "@aws-cdk/assert/jest"; | ||
import "../../../utils/test/jest"; | ||
import { attachPolicyToTestRole, simpleGuStackForTesting } from "../../../utils/test"; | ||
import { GuAllowPolicy, GuDenyPolicy } from "./base-policy"; | ||
|
||
describe("GuAllowPolicy", () => { | ||
test("if a single action is provided, the resulting resource's action will be a single item", () => { | ||
const stack = simpleGuStackForTesting(); | ||
attachPolicyToTestRole( | ||
stack, | ||
new GuAllowPolicy(stack, "AllowS3GetObject", { | ||
actions: ["s3:GetObject"], | ||
resources: ["*"], | ||
}) | ||
); | ||
|
||
expect(stack).toHaveResource("AWS::IAM::Policy", { | ||
PolicyDocument: { | ||
Version: "2012-10-17", | ||
Statement: [ | ||
{ | ||
Action: "s3:GetObject", | ||
Effect: "Allow", | ||
Resource: "*", | ||
}, | ||
], | ||
}, | ||
}); | ||
}); | ||
|
||
test("if multiple actions are provided, the resulting resource's action will be an array", () => { | ||
const stack = simpleGuStackForTesting(); | ||
attachPolicyToTestRole( | ||
stack, | ||
new GuAllowPolicy(stack, "AllowS3GetObject", { | ||
actions: ["s3:GetObject", "s3:ListBucket"], | ||
resources: ["*"], | ||
}) | ||
); | ||
|
||
expect(stack).toHaveResource("AWS::IAM::Policy", { | ||
PolicyDocument: { | ||
Version: "2012-10-17", | ||
Statement: [ | ||
{ | ||
Action: ["s3:GetObject", "s3:ListBucket"], | ||
Effect: "Allow", | ||
Resource: "*", | ||
}, | ||
], | ||
}, | ||
}); | ||
}); | ||
}); | ||
|
||
describe("GuDenyPolicy", () => { | ||
test("if a single action is provided, the resulting resource's action will be a single item", () => { | ||
const stack = simpleGuStackForTesting(); | ||
attachPolicyToTestRole( | ||
stack, | ||
new GuDenyPolicy(stack, "DenyS3GetObject", { | ||
actions: ["s3:GetObject"], | ||
resources: ["*"], | ||
}) | ||
); | ||
|
||
expect(stack).toHaveResource("AWS::IAM::Policy", { | ||
PolicyDocument: { | ||
Version: "2012-10-17", | ||
Statement: [ | ||
{ | ||
Action: "s3:GetObject", | ||
Effect: "Deny", | ||
Resource: "*", | ||
}, | ||
], | ||
}, | ||
}); | ||
}); | ||
|
||
test("if multiple actions are provided, the resulting resource's action will be an array", () => { | ||
const stack = simpleGuStackForTesting(); | ||
attachPolicyToTestRole( | ||
stack, | ||
new GuDenyPolicy(stack, "DenyS3GetObject", { | ||
actions: ["s3:GetObject", "s3:ListBucket"], | ||
resources: ["*"], | ||
}) | ||
); | ||
|
||
expect(stack).toHaveResource("AWS::IAM::Policy", { | ||
PolicyDocument: { | ||
Version: "2012-10-17", | ||
Statement: [ | ||
{ | ||
Action: ["s3:GetObject", "s3:ListBucket"], | ||
Effect: "Deny", | ||
Resource: "*", | ||
}, | ||
], | ||
}, | ||
}); | ||
}); | ||
}); |