Skip to content

Commit 7a8d129

Browse files
committed
Commit tests
1 parent 6f1edfb commit 7a8d129

1 file changed

Lines changed: 56 additions & 4 deletions

File tree

src/constructs/iam/policies/developer-policy.test.ts

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ describe("GuDeveloperPolicy", () => {
66
test("if a single action is provided, the resulting Developer Policy resource's statement will have a single item", () => {
77
const stack = simpleGuStackForTesting();
88
new GuDeveloperPolicy(stack, "AllowS3GetObject", {
9-
allow: {
10-
actions: ["s3:GetObject"],
11-
resources: ["*"],
12-
},
9+
allow: [
10+
{
11+
actions: ["s3:GetObject"],
12+
resources: ["*"]
13+
}
14+
],
15+
permission: "test123"
1316
});
1417

1518
Template.fromStack(stack).hasResourceProperties("AWS::IAM::ManagedPolicy", {
19+
Path: "/developer-policy/test123/",
1620
PolicyDocument: {
1721
Version: "2012-10-17",
1822
Statement: [
@@ -25,4 +29,52 @@ describe("GuDeveloperPolicy", () => {
2529
},
2630
});
2731
});
32+
test("if multiple actions are provided, the resulting Managed Policy resource's action will container all items", () => {
33+
const stack = simpleGuStackForTesting();
34+
new GuDeveloperPolicy(stack, "AllowS3GetObject", {
35+
allow: [
36+
{
37+
actions: ["s3:GetObject"],
38+
resources: ["arn:aws:s3:::mybucket/mypath"],
39+
},
40+
{
41+
actions: ["s3:GetObject"],
42+
resources: ["arn:aws:s3:::mybucket/myotherpath"],
43+
},
44+
],
45+
deny: [
46+
{
47+
actions: ["s3:GetObject"],
48+
resources: ["arn:aws:s3:::mybucket/mypath/butnotthispath"],
49+
},
50+
],
51+
permission: "test321",
52+
description: "testtesttest",
53+
});
54+
55+
Template.fromStack(stack).hasResourceProperties("AWS::IAM::ManagedPolicy", {
56+
Description: "testtesttest",
57+
Path: "/developer-policy/test321/",
58+
PolicyDocument: {
59+
Version: "2012-10-17",
60+
Statement: [
61+
{
62+
Action: "s3:GetObject",
63+
Effect: "Allow",
64+
Resource: "arn:aws:s3:::mybucket/mypath",
65+
},
66+
{
67+
Action: "s3:GetObject",
68+
Effect: "Allow",
69+
Resource: "arn:aws:s3:::mybucket/myotherpath",
70+
},
71+
{
72+
Action: "s3:GetObject",
73+
Effect: "Deny",
74+
Resource: "arn:aws:s3:::mybucket/mypath/butnotthispath",
75+
},
76+
],
77+
},
78+
});
79+
});
2880
});

0 commit comments

Comments
 (0)