Skip to content

Commit

Permalink
fix(apigateway): Explicitly test for undefined instead of falsey for …
Browse files Browse the repository at this point in the history
…stage default options (#20868)

Fixes #20860

Default options for throttling burst and rate limits could be interpreted incorrectly as undefined if they were set to zero. 

----

### All Submissions:

* [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
flemjame-at-amazon authored Jun 27, 2022
1 parent 2ec0fb8 commit b368a31
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-apigateway/lib/stage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ export class Stage extends Resource implements IStage {
};

// if any of them are defined, add an entry for '/*/*'.
const hasCommonOptions = Object.keys(commonMethodOptions).map(v => (commonMethodOptions as any)[v]).filter(x => x).length > 0;
const hasCommonOptions = Object.keys(commonMethodOptions).map(v => (commonMethodOptions as any)[v]).filter(x => x !== undefined).length > 0;
if (hasCommonOptions) {
settings.push(renderEntry('/*/*', commonMethodOptions));
}
Expand Down
27 changes: 27 additions & 0 deletions packages/@aws-cdk/aws-apigateway/test/stage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Template } from '@aws-cdk/assertions';
import * as logs from '@aws-cdk/aws-logs';
import * as cdk from '@aws-cdk/core';
import * as apigateway from '../lib';
import { ApiDefinition } from '../lib';

describe('stage', () => {
test('minimal setup', () => {
Expand Down Expand Up @@ -396,4 +397,30 @@ describe('stage', () => {
accessLogFormat: testFormat,
})).toThrow(/Access log format is specified without a destination/);
});

test('default throttling settings', () => {
// GIVEN
const stack = new cdk.Stack();
new apigateway.SpecRestApi(stack, 'testapi', {
apiDefinition: ApiDefinition.fromInline({
openapi: '3.0.2',
}),
deployOptions: {
throttlingBurstLimit: 0,
throttlingRateLimit: 0,
metricsEnabled: false,
},
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Stage', {
MethodSettings: [{
DataTraceEnabled: false,
HttpMethod: '*',
ResourcePath: '/*',
ThrottlingBurstLimit: 0,
ThrottlingRateLimit: 0,
}],
});
});
});

0 comments on commit b368a31

Please sign in to comment.