From d95fc5e237736ec74babd2c954ad3308d36691f7 Mon Sep 17 00:00:00 2001 From: Daniel Stamer Date: Mon, 24 Sep 2018 16:31:02 +0200 Subject: [PATCH 1/6] fix too restrictive regex on pathpart The RegEx was too restrictive when being used with proxy variables. The \+ in {proxy+} is valid and should not throw an exception. Signed-off-by: Daniel Stamer --- packages/@aws-cdk/aws-apigateway/lib/resource.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-apigateway/lib/resource.ts b/packages/@aws-cdk/aws-apigateway/lib/resource.ts index 209e2024a8cbc..f22c0381357f8 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/resource.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/resource.ts @@ -140,7 +140,7 @@ function validateResourcePathPart(part: string) { part = part.substr(1, part.length - 2); } - if (!/^[a-zA-Z0-9\.\_\-]+$/.test(part)) { + if (!/^[a-zA-Z0-9\.\_\-]+[\+]?$/.test(part)) { throw new Error(`Resource's path part only allow a-zA-Z0-9._- and curly braces at the beginning and the end: ${part}`); } } From d39906fe49d5cf53ccbdb5f6ce9be2b1c9722552 Mon Sep 17 00:00:00 2001 From: Jan Christophersen Date: Sat, 29 Sep 2018 10:04:49 -0500 Subject: [PATCH 2/6] fix(aws-apigateway): Fix proxy resources being rejected by validation --- CHANGELOG.md | 6 ++++++ .../@aws-cdk/aws-apigateway/lib/resource.ts | 5 +++++ .../aws-apigateway/test/test.restapi.ts | 20 +++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index aad99baa7eb98..2913e127f85ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## [UNRELEASED] + +### Bug Fixes + +* **aws-apigateway:** fix validation of resources failing for proxy resource paths (`{proxy+}`) + ## [0.10.0](https://github.com/awslabs/aws-cdk/compare/v0.9.2...v0.10.0) (2018-09-27) diff --git a/packages/@aws-cdk/aws-apigateway/lib/resource.ts b/packages/@aws-cdk/aws-apigateway/lib/resource.ts index 1bab6758d3d02..10b32292cda4b 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/resource.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/resource.ts @@ -138,6 +138,11 @@ function validateResourcePathPart(part: string) { // strip {} which indicate this is a parameter if (part.startsWith('{') && part.endsWith('}')) { part = part.substr(1, part.length - 2); + + // proxy resources are allowed to end with a '+' + if (part.endsWith('+')) { + part = part.substr(0, part.length - 1); + } } if (!/^[a-zA-Z0-9\.\_\-]+$/.test(part)) { diff --git a/packages/@aws-cdk/aws-apigateway/test/test.restapi.ts b/packages/@aws-cdk/aws-apigateway/test/test.restapi.ts index a90d1bbb6c4f7..41a6b8053a96a 100644 --- a/packages/@aws-cdk/aws-apigateway/test/test.restapi.ts +++ b/packages/@aws-cdk/aws-apigateway/test/test.restapi.ts @@ -223,6 +223,26 @@ export = { test.done(); }, + '"addResource" allows configuration of proxy paths'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + const api = new apigateway.RestApi(stack, 'restapi', { + deploy: false, + cloudWatchRole: false, + restApiName: 'my-rest-api' + }); + + // WHEN + api.root.addResource('{proxy+}'); + + // THEN + expect(stack).to(haveResource('AWS::ApiGateway::Resource', { + PathPart: "{proxy+}", + ParentId: { "Fn::GetAtt": ["restapiC5611D27", "RootResourceId"] } + })); + test.done(); + }, + '"addMethod" can be used to add methods to resources'(test: Test) { // GIVEN const stack = new cdk.Stack(); From 6ee1a7851a1eddc0580329293217aaf2abfb7bba Mon Sep 17 00:00:00 2001 From: Jan Christophersen Date: Sat, 29 Sep 2018 10:32:59 -0500 Subject: [PATCH 3/6] Fix testcase for addResource --- packages/@aws-cdk/aws-apigateway/test/test.restapi.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-apigateway/test/test.restapi.ts b/packages/@aws-cdk/aws-apigateway/test/test.restapi.ts index 41a6b8053a96a..c27a4dc00efff 100644 --- a/packages/@aws-cdk/aws-apigateway/test/test.restapi.ts +++ b/packages/@aws-cdk/aws-apigateway/test/test.restapi.ts @@ -233,7 +233,8 @@ export = { }); // WHEN - api.root.addResource('{proxy+}'); + const proxy = api.root.addResource('{proxy+}'); + proxy.addMethod('ANY'); // THEN expect(stack).to(haveResource('AWS::ApiGateway::Resource', { From b026bc23cd89eb3237d217229da5c5576db272e7 Mon Sep 17 00:00:00 2001 From: Daniel Stamer Date: Mon, 1 Oct 2018 10:57:54 +0200 Subject: [PATCH 4/6] extend error message on pathpart regex check Signed-off-by: Daniel Stamer --- packages/@aws-cdk/aws-apigateway/lib/resource.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/@aws-cdk/aws-apigateway/lib/resource.ts b/packages/@aws-cdk/aws-apigateway/lib/resource.ts index 18276601e93e1..661a39e11d7ce 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/resource.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/resource.ts @@ -135,12 +135,13 @@ export class Resource extends cdk.Construct implements IRestApiResource { } function validateResourcePathPart(part: string) { - // strip {} which indicate this is a parameter - if (part.startsWith('{') && part.endsWith('}')) { - part = part.substr(1, part.length - 2); - } + // strip {} which indicate this is a parameter + if (part.startsWith('{') && part.endsWith('}')) { + part = part.substr(1, part.length - 2); + } - if (!/^[a-zA-Z0-9\.\_\-]+[\+]?$/.test(part)) { - throw new Error(`Resource's path part only allow a-zA-Z0-9._- and curly braces at the beginning and the end: ${part}`); - } + if (!/^[a-zA-Z0-9\.\_\-]+[\+]?$/.test(part)) { + throw new Error(`Resource's path part only allow [a-zA-Z0-9._-], an optional trailing '+' + and curly braces at the beginning and the end: ${part}`); + } } From 5c5f805fb8cdbb12d0fe7bd100de81a6373a7a5b Mon Sep 17 00:00:00 2001 From: Daniel Stamer Date: Mon, 1 Oct 2018 16:24:28 +0200 Subject: [PATCH 5/6] drop optional '+' from RegEx after striping it from input Signed-off-by: Daniel Stamer --- packages/@aws-cdk/aws-apigateway/lib/resource.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-apigateway/lib/resource.ts b/packages/@aws-cdk/aws-apigateway/lib/resource.ts index 7da81433f2502..59d9fd980c5a8 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/resource.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/resource.ts @@ -145,7 +145,7 @@ function validateResourcePathPart(part: string) { } } - if (!/^[a-zA-Z0-9\.\_\-]+[\+]?$/.test(part)) { + if (!/^[a-zA-Z0-9\.\_\-]+$/.test(part)) { throw new Error(`Resource's path part only allow [a-zA-Z0-9._-], an optional trailing '+' and curly braces at the beginning and the end: ${part}`); } From f41cb8f5a89e3a1783f1f3b2e8f0dfe9e6cab5ba Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Tue, 2 Oct 2018 10:17:01 +0200 Subject: [PATCH 6/6] Remove CHANGELOG update --- CHANGELOG.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2913e127f85ad..aad99baa7eb98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,3 @@ -## [UNRELEASED] - -### Bug Fixes - -* **aws-apigateway:** fix validation of resources failing for proxy resource paths (`{proxy+}`) - ## [0.10.0](https://github.com/awslabs/aws-cdk/compare/v0.9.2...v0.10.0) (2018-09-27)