From 61b990c6f391b8dae36aeaa9fc40bb4729880124 Mon Sep 17 00:00:00 2001 From: Nicholas Law Date: Tue, 1 Dec 2020 16:32:47 +1100 Subject: [PATCH 1/5] Allow API Gateway base path URLs to accept capital case characters --- packages/@aws-cdk/aws-apigateway/lib/base-path-mapping.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-apigateway/lib/base-path-mapping.ts b/packages/@aws-cdk/aws-apigateway/lib/base-path-mapping.ts index 17fa52ee7005c..d87fe8536f099 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/base-path-mapping.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/base-path-mapping.ts @@ -48,7 +48,7 @@ export class BasePathMapping extends Resource { super(scope, id); if (props.basePath && !Token.isUnresolved(props.basePath)) { - if (!props.basePath.match(/^[a-z0-9$_.+!*'()-]+$/)) { + if (!props.basePath.match(/^[a-zA-Z0-9$_.+!*'()-]+$/)) { throw new Error(`A base path may only contain letters, numbers, and one of "$-_.+!*'()", received: ${props.basePath}`); } } From db123f51769faf9548b6d5aecce9feb2a3906c89 Mon Sep 17 00:00:00 2001 From: Nicholas Law Date: Tue, 1 Dec 2020 16:33:10 +1100 Subject: [PATCH 2/5] Add tests for base path mappings --- .../test/base-path-mapping.test.ts | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 packages/@aws-cdk/aws-apigateway/test/base-path-mapping.test.ts diff --git a/packages/@aws-cdk/aws-apigateway/test/base-path-mapping.test.ts b/packages/@aws-cdk/aws-apigateway/test/base-path-mapping.test.ts new file mode 100644 index 0000000000000..b9b6626fe1250 --- /dev/null +++ b/packages/@aws-cdk/aws-apigateway/test/base-path-mapping.test.ts @@ -0,0 +1,83 @@ +import '@aws-cdk/assert/jest'; +import * as acm from '@aws-cdk/aws-certificatemanager'; +import * as cdk from '@aws-cdk/core'; +import * as apigw from '../lib'; + +describe('BasePathMapping', () => { + test('default setup', () => { + // GIVEN + const stack = new cdk.Stack(); + const api = new apigw.RestApi(stack, 'MyApi'); + api.root.addMethod('GET'); // api must have atleast one method. + const domain = new apigw.DomainName(stack, 'MyDomain', { + domainName: 'example.com', + certificate: acm.Certificate.fromCertificateArn(stack, 'cert', 'arn:aws:acm:us-east-1:1111111:certificate/11-3336f1-44483d-adc7-9cd375c5169d'), + endpointType: apigw.EndpointType.REGIONAL, + }); + + // WHEN + new apigw.BasePathMapping(stack, 'MyBasePath', { + restApi: api, + domainName: domain, + }); + + // THEN + expect(stack).toHaveResource('AWS::ApiGateway::BasePathMapping', { + DomainName: { Ref: 'MyDomainE4943FBC' }, + RestApiId: { Ref: 'MyApi49610EDF' }, + }); + }); + + test('specify basePath property', () => { + // GIVEN + const stack = new cdk.Stack(); + const api = new apigw.RestApi(stack, 'MyApi'); + api.root.addMethod('GET'); // api must have atleast one method. + const domain = new apigw.DomainName(stack, 'MyDomain', { + domainName: 'example.com', + certificate: acm.Certificate.fromCertificateArn(stack, 'cert', 'arn:aws:acm:us-east-1:1111111:certificate/11-3336f1-44483d-adc7-9cd375c5169d'), + endpointType: apigw.EndpointType.REGIONAL, + }); + + // WHEN + new apigw.BasePathMapping(stack, 'MyBasePath', { + restApi: api, + domainName: domain, + basePath: 'My_B45E-P4th', + }); + + // THEN + expect(stack).toHaveResourceLike('AWS::ApiGateway::BasePathMapping', { + BasePath: 'My_B45E-P4th', + }); + }); + + test('specify stage property', () => { + // GIVEN + const stack = new cdk.Stack(); + const api = new apigw.RestApi(stack, 'MyApi'); + api.root.addMethod('GET'); // api must have atleast one method. + const domain = new apigw.DomainName(stack, 'MyDomain', { + domainName: 'example.com', + certificate: acm.Certificate.fromCertificateArn(stack, 'cert', 'arn:aws:acm:us-east-1:1111111:certificate/11-3336f1-44483d-adc7-9cd375c5169d'), + endpointType: apigw.EndpointType.REGIONAL, + }); + const stage = new apigw.Stage(stack, 'MyStage', { + deployment: new apigw.Deployment(stack, 'MyDeplouyment', { + api, + }), + }); + + // WHEN + new apigw.BasePathMapping(stack, 'MyBasePathMapping', { + restApi: api, + domainName: domain, + stage, + }); + + // THEN + expect(stack).toHaveResourceLike('AWS::ApiGateway::BasePathMapping', { + Stage: { Ref: 'MyStage572B0482' }, + }); + }); +}); From 515f3a282cc15e4306fce07ee4684fd14d456ed9 Mon Sep 17 00:00:00 2001 From: Nicholas Law Date: Wed, 9 Dec 2020 10:35:48 +1100 Subject: [PATCH 3/5] Add test for invalid base path property --- .../test/base-path-mapping.test.ts | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/packages/@aws-cdk/aws-apigateway/test/base-path-mapping.test.ts b/packages/@aws-cdk/aws-apigateway/test/base-path-mapping.test.ts index b9b6626fe1250..49c88145833ff 100644 --- a/packages/@aws-cdk/aws-apigateway/test/base-path-mapping.test.ts +++ b/packages/@aws-cdk/aws-apigateway/test/base-path-mapping.test.ts @@ -52,6 +52,30 @@ describe('BasePathMapping', () => { }); }); + test('throw error for invalid basePath property', () => { + // GIVEN + const stack = new cdk.Stack(); + const api = new apigw.RestApi(stack, 'MyApi'); + api.root.addMethod('GET'); // api must have atleast one method. + const domain = new apigw.DomainName(stack, 'MyDomain', { + domainName: 'example.com', + certificate: acm.Certificate.fromCertificateArn(stack, 'cert', 'arn:aws:acm:us-east-1:1111111:certificate/11-3336f1-44483d-adc7-9cd375c5169d'), + endpointType: apigw.EndpointType.REGIONAL, + }); + + // WHEN + const invalidBasePath = '/invalid-/base-path'; + + // THEN + expect(() => { + new apigw.BasePathMapping(stack, 'MyBasePath', { + restApi: api, + domainName: domain, + basePath: invalidBasePath, + }); + }).toThrowError(`A base path may only contain letters, numbers, and one of "$-_.+!*'()", received: ${invalidBasePath}`); + }); + test('specify stage property', () => { // GIVEN const stack = new cdk.Stack(); From fbdbf7abe65dc7ce51562d9118d55c41fb333999 Mon Sep 17 00:00:00 2001 From: Niranjan Jayakar Date: Wed, 9 Dec 2020 11:18:17 +0000 Subject: [PATCH 4/5] Update packages/@aws-cdk/aws-apigateway/test/base-path-mapping.test.ts --- packages/@aws-cdk/aws-apigateway/test/base-path-mapping.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-apigateway/test/base-path-mapping.test.ts b/packages/@aws-cdk/aws-apigateway/test/base-path-mapping.test.ts index 49c88145833ff..dd4ff49c01a8c 100644 --- a/packages/@aws-cdk/aws-apigateway/test/base-path-mapping.test.ts +++ b/packages/@aws-cdk/aws-apigateway/test/base-path-mapping.test.ts @@ -73,7 +73,7 @@ describe('BasePathMapping', () => { domainName: domain, basePath: invalidBasePath, }); - }).toThrowError(`A base path may only contain letters, numbers, and one of "$-_.+!*'()", received: ${invalidBasePath}`); + }).toThrowError(/base path may only only contain/); }); test('specify stage property', () => { From 3568931789b7b03ade0ea104d08cfa158bc0ea7a Mon Sep 17 00:00:00 2001 From: Niranjan Jayakar Date: Wed, 9 Dec 2020 13:56:38 +0000 Subject: [PATCH 5/5] Update packages/@aws-cdk/aws-apigateway/test/base-path-mapping.test.ts --- packages/@aws-cdk/aws-apigateway/test/base-path-mapping.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-apigateway/test/base-path-mapping.test.ts b/packages/@aws-cdk/aws-apigateway/test/base-path-mapping.test.ts index dd4ff49c01a8c..49dc8e50759f8 100644 --- a/packages/@aws-cdk/aws-apigateway/test/base-path-mapping.test.ts +++ b/packages/@aws-cdk/aws-apigateway/test/base-path-mapping.test.ts @@ -73,7 +73,7 @@ describe('BasePathMapping', () => { domainName: domain, basePath: invalidBasePath, }); - }).toThrowError(/base path may only only contain/); + }).toThrowError(/base path may only contain/); }); test('specify stage property', () => {