Skip to content

Commit

Permalink
fix(apigatewayv2): http api - disallow empty string as domain name (#…
Browse files Browse the repository at this point in the history
…16044)

Currently, empty strings are allowed for custom domain name values despite other tools such as the AWS CLI not allowing empty string values. This effort brings the `DomainName` construct up to date with other tooling.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
samtwil authored Aug 24, 2021
1 parent 1be373c commit 9c39bcb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/@aws-cdk/aws-apigatewayv2/lib/common/domain-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ export class DomainName extends Resource implements IDomainName {
constructor(scope: Construct, id: string, props: DomainNameProps) {
super(scope, id);

if (props.domainName === '') {
throw new Error('empty string for domainName not allowed');
}

const domainNameProps: CfnDomainNameProps = {
domainName: props.domainName,
domainNameConfigurations: [
Expand Down
16 changes: 16 additions & 0 deletions packages/@aws-cdk/aws-apigatewayv2/test/http/domain-name.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ describe('DomainName', () => {
});
});

test('throws when domainName is empty string', () => {
// GIVEN
const stack = new Stack();

// WHEN
const t = () => {
new DomainName(stack, 'DomainName', {
domainName: '',
certificate: Certificate.fromCertificateArn(stack, 'cert', certArn),
});
};

// THEN
expect(t).toThrow(/empty string for domainName not allowed/);
});

test('import domain name correctly', () => {
// GIVEN
const stack = new Stack();
Expand Down

0 comments on commit 9c39bcb

Please sign in to comment.