Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

Commit 918a19e

Browse files
authored
fix(aws-cloudfront): handle bucket names with dots correctly (#1844)
1 parent d47e537 commit 918a19e

File tree

4 files changed

+477
-1
lines changed

4 files changed

+477
-1
lines changed

packages/serverless-components/aws-cloudfront/__tests__/__snapshots__/s3-origin.test.ts.snap

Lines changed: 354 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,360 @@ Object {
447447
}
448448
`;
449449

450+
exports[`S3 origins when origin is outside of us-east-1 and contains dots should use the origin's host at the DomainName 1`] = `
451+
Object {
452+
"DistributionConfigWithTags": Object {
453+
"DistributionConfig": Object {
454+
"Aliases": Object {
455+
"Items": Array [],
456+
"Quantity": 0,
457+
},
458+
"CacheBehaviors": Object {
459+
"Items": Array [],
460+
"Quantity": 0,
461+
},
462+
"CallerReference": "1566599541192",
463+
"Comment": "",
464+
"CustomErrorResponses": Object {
465+
"Items": Array [],
466+
"Quantity": 0,
467+
},
468+
"DefaultCacheBehavior": Object {
469+
"AllowedMethods": Object {
470+
"CachedMethods": Object {
471+
"Items": Array [
472+
"HEAD",
473+
"GET",
474+
],
475+
"Quantity": 2,
476+
},
477+
"Items": Array [
478+
"HEAD",
479+
"GET",
480+
],
481+
"Quantity": 2,
482+
},
483+
"Compress": false,
484+
"DefaultTTL": 86400,
485+
"FieldLevelEncryptionId": "",
486+
"ForwardedValues": Object {
487+
"Cookies": Object {
488+
"Forward": "none",
489+
},
490+
"Headers": Object {
491+
"Items": Array [],
492+
"Quantity": 0,
493+
},
494+
"QueryString": false,
495+
"QueryStringCacheKeys": Object {
496+
"Items": Array [],
497+
"Quantity": 0,
498+
},
499+
},
500+
"LambdaFunctionAssociations": Object {
501+
"Items": Array [],
502+
"Quantity": 0,
503+
},
504+
"MaxTTL": 31536000,
505+
"MinTTL": 0,
506+
"SmoothStreaming": false,
507+
"TargetOriginId": "mybucket.with.dots",
508+
"TrustedSigners": Object {
509+
"Enabled": false,
510+
"Items": Array [],
511+
"Quantity": 0,
512+
},
513+
"ViewerProtocolPolicy": "redirect-to-https",
514+
},
515+
"Enabled": true,
516+
"HttpVersion": "http2",
517+
"Origins": Object {
518+
"Items": Array [
519+
Object {
520+
"CustomHeaders": Object {
521+
"Items": Array [],
522+
"Quantity": 0,
523+
},
524+
"DomainName": "mybucket.with.dots.s3.eu-west-1.amazonaws.com",
525+
"Id": "mybucket.with.dots",
526+
"OriginPath": "",
527+
"S3OriginConfig": Object {
528+
"OriginAccessIdentity": "",
529+
},
530+
},
531+
],
532+
"Quantity": 1,
533+
},
534+
"PriceClass": "PriceClass_All",
535+
},
536+
"Tags": Object {
537+
"Items": Array [],
538+
},
539+
},
540+
}
541+
`;
542+
543+
exports[`S3 origins when origin is outside of us-east-1 and contains dots updates distribution 1`] = `
544+
Object {
545+
"DistributionConfig": Object {
546+
"CacheBehaviors": Object {
547+
"Items": Array [],
548+
"Quantity": 0,
549+
},
550+
"Comment": "",
551+
"CustomErrorResponses": Object {
552+
"Items": Array [],
553+
"Quantity": 0,
554+
},
555+
"DefaultCacheBehavior": Object {
556+
"AllowedMethods": Object {
557+
"CachedMethods": Object {
558+
"Items": Array [
559+
"HEAD",
560+
"GET",
561+
],
562+
"Quantity": 2,
563+
},
564+
"Items": Array [
565+
"HEAD",
566+
"GET",
567+
],
568+
"Quantity": 2,
569+
},
570+
"Compress": false,
571+
"DefaultTTL": 86400,
572+
"FieldLevelEncryptionId": "",
573+
"ForwardedValues": Object {
574+
"Cookies": Object {
575+
"Forward": "none",
576+
},
577+
"Headers": Object {
578+
"Items": Array [],
579+
"Quantity": 0,
580+
},
581+
"QueryString": false,
582+
"QueryStringCacheKeys": Object {
583+
"Items": Array [],
584+
"Quantity": 0,
585+
},
586+
},
587+
"LambdaFunctionAssociations": Object {
588+
"Items": Array [],
589+
"Quantity": 0,
590+
},
591+
"MaxTTL": 31536000,
592+
"MinTTL": 0,
593+
"SmoothStreaming": false,
594+
"TargetOriginId": "anotherbucket",
595+
"TrustedSigners": Object {
596+
"Enabled": false,
597+
"Items": Array [],
598+
"Quantity": 0,
599+
},
600+
"ViewerProtocolPolicy": "redirect-to-https",
601+
},
602+
"Enabled": true,
603+
"Origins": Object {
604+
"Items": Array [
605+
Object {
606+
"CustomHeaders": Object {
607+
"Items": Array [],
608+
"Quantity": 0,
609+
},
610+
"DomainName": "anotherbucket.s3.eu-west-1.amazonaws.com",
611+
"Id": "anotherbucket",
612+
"OriginPath": "",
613+
"S3OriginConfig": Object {
614+
"OriginAccessIdentity": "",
615+
},
616+
},
617+
],
618+
"Quantity": 1,
619+
},
620+
"PriceClass": "PriceClass_All",
621+
},
622+
"Id": "distributionwithS3origin",
623+
"IfMatch": "etag",
624+
}
625+
`;
626+
627+
exports[`S3 origins when origin is outside of us-east-1 and contains s3 and dots should use the origin's host at the DomainName 1`] = `
628+
Object {
629+
"DistributionConfigWithTags": Object {
630+
"DistributionConfig": Object {
631+
"Aliases": Object {
632+
"Items": Array [],
633+
"Quantity": 0,
634+
},
635+
"CacheBehaviors": Object {
636+
"Items": Array [],
637+
"Quantity": 0,
638+
},
639+
"CallerReference": "1566599541192",
640+
"Comment": "",
641+
"CustomErrorResponses": Object {
642+
"Items": Array [],
643+
"Quantity": 0,
644+
},
645+
"DefaultCacheBehavior": Object {
646+
"AllowedMethods": Object {
647+
"CachedMethods": Object {
648+
"Items": Array [
649+
"HEAD",
650+
"GET",
651+
],
652+
"Quantity": 2,
653+
},
654+
"Items": Array [
655+
"HEAD",
656+
"GET",
657+
],
658+
"Quantity": 2,
659+
},
660+
"Compress": false,
661+
"DefaultTTL": 86400,
662+
"FieldLevelEncryptionId": "",
663+
"ForwardedValues": Object {
664+
"Cookies": Object {
665+
"Forward": "none",
666+
},
667+
"Headers": Object {
668+
"Items": Array [],
669+
"Quantity": 0,
670+
},
671+
"QueryString": false,
672+
"QueryStringCacheKeys": Object {
673+
"Items": Array [],
674+
"Quantity": 0,
675+
},
676+
},
677+
"LambdaFunctionAssociations": Object {
678+
"Items": Array [],
679+
"Quantity": 0,
680+
},
681+
"MaxTTL": 31536000,
682+
"MinTTL": 0,
683+
"SmoothStreaming": false,
684+
"TargetOriginId": "mybucket.s3.s3",
685+
"TrustedSigners": Object {
686+
"Enabled": false,
687+
"Items": Array [],
688+
"Quantity": 0,
689+
},
690+
"ViewerProtocolPolicy": "redirect-to-https",
691+
},
692+
"Enabled": true,
693+
"HttpVersion": "http2",
694+
"Origins": Object {
695+
"Items": Array [
696+
Object {
697+
"CustomHeaders": Object {
698+
"Items": Array [],
699+
"Quantity": 0,
700+
},
701+
"DomainName": "mybucket.s3.s3.s3.eu-west-1.amazonaws.com",
702+
"Id": "mybucket.s3.s3",
703+
"OriginPath": "",
704+
"S3OriginConfig": Object {
705+
"OriginAccessIdentity": "",
706+
},
707+
},
708+
],
709+
"Quantity": 1,
710+
},
711+
"PriceClass": "PriceClass_All",
712+
},
713+
"Tags": Object {
714+
"Items": Array [],
715+
},
716+
},
717+
}
718+
`;
719+
720+
exports[`S3 origins when origin is outside of us-east-1 and contains s3 and dots updates distribution 1`] = `
721+
Object {
722+
"DistributionConfig": Object {
723+
"CacheBehaviors": Object {
724+
"Items": Array [],
725+
"Quantity": 0,
726+
},
727+
"Comment": "",
728+
"CustomErrorResponses": Object {
729+
"Items": Array [],
730+
"Quantity": 0,
731+
},
732+
"DefaultCacheBehavior": Object {
733+
"AllowedMethods": Object {
734+
"CachedMethods": Object {
735+
"Items": Array [
736+
"HEAD",
737+
"GET",
738+
],
739+
"Quantity": 2,
740+
},
741+
"Items": Array [
742+
"HEAD",
743+
"GET",
744+
],
745+
"Quantity": 2,
746+
},
747+
"Compress": false,
748+
"DefaultTTL": 86400,
749+
"FieldLevelEncryptionId": "",
750+
"ForwardedValues": Object {
751+
"Cookies": Object {
752+
"Forward": "none",
753+
},
754+
"Headers": Object {
755+
"Items": Array [],
756+
"Quantity": 0,
757+
},
758+
"QueryString": false,
759+
"QueryStringCacheKeys": Object {
760+
"Items": Array [],
761+
"Quantity": 0,
762+
},
763+
},
764+
"LambdaFunctionAssociations": Object {
765+
"Items": Array [],
766+
"Quantity": 0,
767+
},
768+
"MaxTTL": 31536000,
769+
"MinTTL": 0,
770+
"SmoothStreaming": false,
771+
"TargetOriginId": "anotherbucket",
772+
"TrustedSigners": Object {
773+
"Enabled": false,
774+
"Items": Array [],
775+
"Quantity": 0,
776+
},
777+
"ViewerProtocolPolicy": "redirect-to-https",
778+
},
779+
"Enabled": true,
780+
"Origins": Object {
781+
"Items": Array [
782+
Object {
783+
"CustomHeaders": Object {
784+
"Items": Array [],
785+
"Quantity": 0,
786+
},
787+
"DomainName": "anotherbucket.s3.eu-west-1.amazonaws.com",
788+
"Id": "anotherbucket",
789+
"OriginPath": "",
790+
"S3OriginConfig": Object {
791+
"OriginAccessIdentity": "",
792+
},
793+
},
794+
],
795+
"Quantity": 1,
796+
},
797+
"PriceClass": "PriceClass_All",
798+
},
799+
"Id": "distributionwithS3origin",
800+
"IfMatch": "etag",
801+
}
802+
`;
803+
450804
exports[`S3 origins when origin is outside of us-east-1 should use the origin's host at the DomainName 1`] = `
451805
Object {
452806
"DistributionConfigWithTags": Object {

0 commit comments

Comments
 (0)