Skip to content

Commit

Permalink
feat: check millisec order clientKeepAlive
Browse files Browse the repository at this point in the history
  • Loading branch information
badmintoncryer committed Mar 15, 2024
1 parent 94ac577 commit 2a58a0f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ export class ApplicationLoadBalancer extends BaseLoadBalancer implements IApplic
if (props.dropInvalidHeaderFields) {this.setAttribute('routing.http.drop_invalid_header_fields.enabled', 'true'); }
if (props.desyncMitigationMode !== undefined) {this.setAttribute('routing.http.desync_mitigation_mode', props.desyncMitigationMode); }
if (props.clientKeepAlive !== undefined) {
const clientKeepAliveInMillis = props.clientKeepAlive.toMilliseconds();
if (clientKeepAliveInMillis < 1000) {
throw new Error(`\'clientKeepAlive\' must be between 60 and 604800 seconds. Got: ${clientKeepAliveInMillis} milliseconds`);
}

const clientKeepAliveInSeconds = props.clientKeepAlive.toSeconds();
if (clientKeepAliveInSeconds < 60 || clientKeepAliveInSeconds > 604800) {
throw new Error(`\'clientKeepAlive\' must be between 60 and 604800 seconds. Got: ${clientKeepAliveInSeconds} seconds`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe('tests', () => {
});
});

test.each([59, 604801])('throw error for invalid clientKeepAlive', (duration) => {
test.each([59, 604801])('throw error for invalid clientKeepAlive in seconds', (duration) => {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'Stack');
Expand All @@ -126,6 +126,20 @@ describe('tests', () => {
}).toThrow(`\'clientKeepAlive\' must be between 60 and 604800 seconds. Got: ${duration} seconds`);
});

test('throw errer for invalid clientKeepAlive in milliseconds', () => {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'Stack');

// THEN
expect(() => {
new elbv2.ApplicationLoadBalancer(stack, 'LB', {
vpc,
clientKeepAlive: cdk.Duration.millis(100),
});
}).toThrow('\'clientKeepAlive\' must be between 60 and 604800 seconds. Got: 100 milliseconds');
});

describe('Desync mitigation mode', () => {
test('Defensive', () => {
// GIVEN
Expand Down

0 comments on commit 2a58a0f

Please sign in to comment.