Skip to content

Commit 9bce0a1

Browse files
committed
Add tests for permissions on *
1 parent 27b4048 commit 9bce0a1

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { simpleGuStackForTesting } from "../../../utils/test";
33
import { GuWorkloadPolicy } from "./workload-policy";
44

55
describe("GuDeveloperPolicy", () => {
6-
test("if a single action is provided, the resulting Developer Policy resource's statement will have a single item", () => {
6+
test("if a single action is provided, the resulting Workload Policy resource's statement will have a single item", () => {
77
const stack = simpleGuStackForTesting();
88
new GuWorkloadPolicy(stack, "AllowS3GetObject", {
99
allow: [
1010
{
1111
actions: ["s3:GetObject"],
12-
resources: ["*"],
12+
resources: ["s3:///log-bucket"],
1313
},
1414
],
1515
permission: "test123",
@@ -23,12 +23,28 @@ describe("GuDeveloperPolicy", () => {
2323
{
2424
Action: "s3:GetObject",
2525
Effect: "Allow",
26-
Resource: "*",
26+
Resource: "s3:///log-bucket",
2727
},
2828
],
2929
},
3030
});
3131
});
32+
33+
test("throws an error if a wide-open permissions is requested", () => {
34+
const stack = simpleGuStackForTesting();
35+
expect(() => {
36+
new GuWorkloadPolicy(stack, "AllowS3GetObject", {
37+
allow: [
38+
{
39+
actions: ["s3:GetObject"],
40+
resources: ["*"],
41+
},
42+
],
43+
permission: "test123",
44+
});
45+
}).toThrow("Overly broad permission present, see annotations for details");
46+
});
47+
3248
test("if multiple actions are provided, the resulting Managed Policy resource's action will container all items", () => {
3349
const stack = simpleGuStackForTesting();
3450
new GuWorkloadPolicy(stack, "AllowS3GetObject", {

0 commit comments

Comments
 (0)