Skip to content

Commit 2eda01c

Browse files
committed
Add tests
Signed-off-by: Connor Avery <214469360+connoravo-nhs@users.noreply.github.com>
1 parent dbb6e4f commit 2eda01c

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

packages/cdkConstructs/tests/constructs/RestApiGateway.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,17 @@ describe("RestApiGateway with mTLS", () => {
346346

347347
describe("RestApiGateway with mTLS and stackUUID", () => {
348348
test("uses stackUUID in trust store deployment key prefix", () => {
349+
interface ManagedPolicyResource {
350+
Properties?: {
351+
PolicyDocument?: {
352+
Statement?: Array<{
353+
Action?: Array<string>
354+
Resource?: string | Array<string>
355+
}>
356+
}
357+
}
358+
}
359+
349360
const app = new App()
350361
const stack = new Stack(app, "RestApiGatewayStackWithUuid")
351362

@@ -376,6 +387,27 @@ describe("RestApiGateway with mTLS and stackUUID", () => {
376387
template.hasResourceProperties("Custom::CDKBucketDeployment", {
377388
DestinationKeyPrefix: "cpt-api/test-stack-f47ac10b-truststore"
378389
})
390+
391+
const policies = template.findResources("AWS::IAM::ManagedPolicy")
392+
const expectedTrustStoreObjectPath =
393+
"cpt-api/test-stack-f47ac10b-58cc-4372-a567-0e02b2c3d479-truststore/truststore.pem"
394+
395+
const hasExpectedTrustStorePath = Object.values(policies).some((policy) => {
396+
const statements = (policy as ManagedPolicyResource).Properties?.PolicyDocument?.Statement ?? []
397+
return statements.some((statement) => {
398+
if (!statement.Action?.includes("s3:PutObject")) {
399+
return false
400+
}
401+
402+
const resources = Array.isArray(statement.Resource)
403+
? statement.Resource
404+
: (statement.Resource ? [statement.Resource] : [])
405+
406+
return resources.some((resource) => resource.includes(expectedTrustStoreObjectPath))
407+
})
408+
})
409+
410+
expect(hasExpectedTrustStorePath).toBe(true)
379411
})
380412
})
381413

0 commit comments

Comments
 (0)