From dcd446e73e04e2ce4d724321247d62d52e40a42a Mon Sep 17 00:00:00 2001 From: Blake Price Date: Thu, 27 Sep 2018 13:33:38 -0700 Subject: [PATCH 1/4] Check specifically for undefined and determining of the defaultRootObject prop is set or not. --- packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts b/packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts index ad7a7bf5013c4..cd12299bb3e57 100644 --- a/packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts +++ b/packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts @@ -459,7 +459,7 @@ export class CloudFrontWebDistribution extends cdk.Construct { const distributionConfig: cloudformation.DistributionResource.DistributionConfigProperty = { comment: props.comment, enabled: true, - defaultRootObject: props.defaultRootObject || "index.html", + defaultRootObject: props.defaultRootObject !== undefined ? props.defaultRootObject : "index.html", httpVersion: props.httpVersion || HttpVersion.HTTP2, priceClass: props.priceClass || PriceClass.PriceClass100, ipv6Enabled: props.enableIpV6 || true, From 9bc22c418d41291ccad04968124de2a3e410efcd Mon Sep 17 00:00:00 2001 From: Blake Price Date: Thu, 27 Sep 2018 14:26:23 -0700 Subject: [PATCH 2/4] Update changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b1cd16c70269..cf8553db87fae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ ## [UNRELEASED] + + +### Bug Fixes + +* **aws-cloudfront:** Fix empty string defaultRootObject being replaced with the default value instead of passing the empty string to CloudFormation. Closes [#794](https://github.com/awslabs/aws-cdk/issues/794) + ### CloudFormation Changes * __@aws-cdk/cfnspec__: Updated [CloudFormation resource specification] to `v2.8.0` ([@RomainMuller] in [#767](https://github.com/awslabs/aws-cdk/pull/767)) From 92baabda025318dc7ab90c892d55a83712166ee5 Mon Sep 17 00:00:00 2001 From: Blake Price Date: Thu, 27 Sep 2018 14:49:37 -0700 Subject: [PATCH 3/4] Add testing to verify valid empty roots --- .../integ.cloudfront-empty-root.expected.json | 60 +++++++++++++++++++ .../test/integ.cloudfront-empty-root.ts | 28 +++++++++ 2 files changed, 88 insertions(+) create mode 100644 packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-empty-root.expected.json create mode 100644 packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-empty-root.ts diff --git a/packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-empty-root.expected.json b/packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-empty-root.expected.json new file mode 100644 index 0000000000000..23f5a0432ec18 --- /dev/null +++ b/packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-empty-root.expected.json @@ -0,0 +1,60 @@ +{ + "Resources": { + "AnAmazingWebsiteProbablyCFDistribution47E3983B": { + "Type": "AWS::CloudFront::Distribution", + "Properties": { + "DistributionConfig": { + "CacheBehaviors": [], + "DefaultCacheBehavior": { + "AllowedMethods": [ + "GET", + "HEAD" + ], + "CachedMethods": [ + "GET", + "HEAD" + ], + "ForwardedValues": { + "Cookies": { + "Forward": "none" + }, + "QueryString": false + }, + "TargetOriginId": "origin1", + "ViewerProtocolPolicy": "redirect-to-https" + }, + "DefaultRootObject": "", + "Enabled": true, + "HttpVersion": "http2", + "IPV6Enabled": true, + "Origins": [ + { + "CustomOriginConfig": { + "HTTPPort": 80, + "HTTPSPort": 443, + "OriginKeepaliveTimeout": 5, + "OriginProtocolPolicy": "https-only", + "OriginReadTimeout": 30, + "OriginSSLProtocols": [ + "TLSv1.2" + ] + }, + "DomainName": "brelandm.a2z.com", + "Id": "origin1", + "OriginCustomHeaders": [ + { + "HeaderName": "X-Custom-Header", + "HeaderValue": "somevalue" + } + ] + } + ], + "PriceClass": "PriceClass_100", + "ViewerCertificate": { + "CloudFrontDefaultCertificate": true + } + } + } + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-empty-root.ts b/packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-empty-root.ts new file mode 100644 index 0000000000000..5ee5ccc5d9adf --- /dev/null +++ b/packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-empty-root.ts @@ -0,0 +1,28 @@ + +import cdk = require('@aws-cdk/cdk'); +import cloudfront = require('../lib'); + +const app = new cdk.App(process.argv); + +const stack = new cdk.Stack(app, 'aws-cdk-cloudfront-custom'); + +new cloudfront.CloudFrontWebDistribution(stack, 'AnAmazingWebsiteProbably', { + originConfigs: [ + { + originHeaders: { + "X-Custom-Header": "somevalue", + }, + customOriginSource: { + domainName: "brelandm.a2z.com", + }, + behaviors: [ + { + isDefaultBehavior: true, + } + ], + } + ], + defaultRootObject: '' +}); + +process.stdout.write(app.run()); From c23230e0a0c63c828aabddb77a9ce51a6fcc66b8 Mon Sep 17 00:00:00 2001 From: Blake Price Date: Thu, 27 Sep 2018 14:26:23 -0700 Subject: [PATCH 4/4] Revert "Update changelog" This reverts commit 9bc22c418d41291ccad04968124de2a3e410efcd. --- CHANGELOG.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf8553db87fae..7b1cd16c70269 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,4 @@ ## [UNRELEASED] - - -### Bug Fixes - -* **aws-cloudfront:** Fix empty string defaultRootObject being replaced with the default value instead of passing the empty string to CloudFormation. Closes [#794](https://github.com/awslabs/aws-cdk/issues/794) - ### CloudFormation Changes * __@aws-cdk/cfnspec__: Updated [CloudFormation resource specification] to `v2.8.0` ([@RomainMuller] in [#767](https://github.com/awslabs/aws-cdk/pull/767))