From 4f091efcce955070f9641ab59923bf6b5362175b Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Sun, 2 Jul 2023 10:04:05 +0000 Subject: [PATCH] CF:create_distribution() - fix config with single alias (#6472) --- moto/cloudfront/models.py | 2 ++ .../test_cloudfront/test_cloudfront_distributions.py | 11 ++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/moto/cloudfront/models.py b/moto/cloudfront/models.py index 5f54f0cb9..18713890c 100644 --- a/moto/cloudfront/models.py +++ b/moto/cloudfront/models.py @@ -148,6 +148,8 @@ class DistributionConfig: self.aliases = ((config.get("Aliases") or {}).get("Items") or {}).get( "CNAME" ) or [] + if isinstance(self.aliases, str): + self.aliases = [self.aliases] self.comment = config.get("Comment") or "" self.default_cache_behavior = DefaultCacheBehaviour( config["DefaultCacheBehavior"] diff --git a/tests/test_cloudfront/test_cloudfront_distributions.py b/tests/test_cloudfront/test_cloudfront_distributions.py index c35376900..962839823 100644 --- a/tests/test_cloudfront/test_cloudfront_distributions.py +++ b/tests/test_cloudfront/test_cloudfront_distributions.py @@ -287,12 +287,15 @@ def test_create_distribution_with_origins(): @pytest.mark.parametrize("qs", [True, False]) @pytest.mark.parametrize("smooth", [True, False]) @pytest.mark.parametrize("ipv6", [True, False]) -def test_create_distribution_with_additional_fields(compress, qs, smooth, ipv6): +@pytest.mark.parametrize("aliases", [["alias1", "alias2"], ["alias1"]]) +def test_create_distribution_with_additional_fields( + compress, qs, smooth, ipv6, aliases +): client = boto3.client("cloudfront", region_name="us-west-1") config = scaffold.example_distribution_config("ref") config["IsIPV6Enabled"] = ipv6 - config["Aliases"] = {"Quantity": 2, "Items": ["alias1", "alias2"]} + config["Aliases"] = {"Quantity": 2, "Items": aliases} config["DefaultCacheBehavior"]["ForwardedValues"]["Cookies"] = { "Forward": "whitelist", "WhitelistedNames": {"Quantity": 1, "Items": ["x-amz-header"]}, @@ -306,9 +309,7 @@ def test_create_distribution_with_additional_fields(compress, qs, smooth, ipv6): distribution = resp["Distribution"] distribution.should.have.key("DistributionConfig") config = distribution["DistributionConfig"] - config.should.have.key("Aliases").equals( - {"Items": ["alias1", "alias2"], "Quantity": 2} - ) + assert config["Aliases"] == {"Items": aliases, "Quantity": len(aliases)} config.should.have.key("PriceClass").equals("PriceClass_100") config.should.have.key("IsIPV6Enabled").equals(ipv6)