Skip to content

Commit f2e9325

Browse files
committed
fix: protect against enabling csoc with no destination
1 parent c7d714d commit f2e9325

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

packages/cdkConstructs/src/constructs/RestApiGateway.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ export class RestApiGateway extends Construct {
4444
public constructor(scope: Construct, id: string, props: RestApiGatewayProps) {
4545
super(scope, id)
4646

47+
if (props.forwardCsocLogs && props.csocApiGatewayDestination === "") {
48+
throw new Error("csocApiGatewayDestination must be provided when forwardCsocLogs is true")
49+
}
50+
4751
// Imports
4852
const cloudWatchLogsKmsKey = Key.fromKeyArn(
4953
this, "cloudWatchLogsKmsKey", Fn.importValue("account-resources:CloudwatchLogsKmsKeyArn"))

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,3 +327,28 @@ describe("RestApiGateway with mTLS", () => {
327327
expect(domainName.Properties.MutualTlsAuthentication.TruststoreUri).toBeDefined()
328328
})
329329
})
330+
331+
describe("RestApiGateway validation errors", () => {
332+
test("throws when forwardCsocLogs is true and csocApiGatewayDestination is empty string", () => {
333+
const app = new App()
334+
const stack = new Stack(app, "ValidationStack1")
335+
const testPolicy = new ManagedPolicy(stack, "TestPolicy", {
336+
description: "test execution policy",
337+
statements: [
338+
new PolicyStatement({
339+
actions: ["lambda:InvokeFunction"],
340+
resources: ["arn:aws:lambda:eu-west-2:123456789012:function:test-function"]
341+
})
342+
]
343+
})
344+
345+
expect(() => new RestApiGateway(stack, "TestApiGateway", {
346+
stackName: "test-stack",
347+
logRetentionInDays: 30,
348+
mutualTlsTrustStoreKey: undefined,
349+
forwardCsocLogs: true,
350+
csocApiGatewayDestination: "",
351+
executionPolicies: [testPolicy]
352+
})).toThrow("csocApiGatewayDestination must be provided when forwardCsocLogs is true")
353+
})
354+
})

0 commit comments

Comments
 (0)