Skip to content

Commit 0b2bf0d

Browse files
committed
chore(elasticloadbalancingv2): Add validation on application listeners for certificates on HTTP protocol
1 parent 9e3cbf6 commit 0b2bf0d

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-listener.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ export class ApplicationListener extends BaseListener implements IApplicationLis
263263
throw new ValidationError('At least one of \'port\' or \'protocol\' is required', scope);
264264
}
265265

266+
if (protocol === ApplicationProtocol.HTTP && props.certificates?.length) {
267+
throw new ValidationError('A certificate cannot be specified for HTTP listeners', scope);
268+
}
269+
266270
validateMutualAuthentication(scope, props.mutualAuthentication);
267271

268272
let advertiseTrustStoreCaNames: string | undefined;

packages/aws-cdk-lib/aws-elasticloadbalancingv2/test/alb/listener.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,23 @@ describe('tests', () => {
257257
});
258258
});
259259

260+
test('HTTP listener requires no certificate', () => {
261+
// GIVEN
262+
const stack = new cdk.Stack();
263+
const vpc = new ec2.Vpc(stack, 'Stack');
264+
const lb = new elbv2.ApplicationLoadBalancer(stack, 'LB', { vpc });
265+
266+
// WHEN
267+
const listener = lb.addListener('Listener', {
268+
port: 80,
269+
defaultTargetGroups: [new elbv2.ApplicationTargetGroup(stack, 'Group', { vpc, port: 80 })],
270+
});
271+
272+
// THEN
273+
const errors = listener.node.validate();
274+
expect(errors).toEqual(['A certificate cannot be specified for HTTP listeners']);
275+
});
276+
260277
test('Can configure targetType on TargetGroups', () => {
261278
// GIVEN
262279
const stack = new cdk.Stack();

0 commit comments

Comments
 (0)