From 274fdae6420b06507769a05c74f53f2c9527dff1 Mon Sep 17 00:00:00 2001 From: izipris <39757826+izipris@users.noreply.github.com> Date: Tue, 5 Mar 2024 01:16:38 +0200 Subject: [PATCH] Cloudfront update_distribution - apply configuration changes (#7423) --- moto/cloudfront/models.py | 15 +----------- tests/test_cloudfront/test_cloudfront.py | 31 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/moto/cloudfront/models.py b/moto/cloudfront/models.py index d5217f317..588030408 100644 --- a/moto/cloudfront/models.py +++ b/moto/cloudfront/models.py @@ -354,20 +354,7 @@ class CloudFrontBackend(BaseBackend): raise NoSuchDistribution dist = self.distributions[_id] - if dist_config.get("Aliases", {}).get("Items") is not None: - aliases = dist_config["Aliases"]["Items"]["CNAME"] - dist.distribution_config.aliases = aliases - origin = dist_config["Origins"]["Items"]["Origin"] - dist.distribution_config.config = dist_config - dist.distribution_config.origins = ( - [Origin(o) for o in origin] - if isinstance(origin, list) - else [Origin(origin)] - ) - if dist_config.get("DefaultRootObject") is not None: - dist.distribution_config.default_root_object = dist_config[ - "DefaultRootObject" - ] + dist.distribution_config = DistributionConfig(dist_config) self.distributions[_id] = dist dist.advance() return dist, dist.location, dist.etag diff --git a/tests/test_cloudfront/test_cloudfront.py b/tests/test_cloudfront/test_cloudfront.py index 178ea583d..872a8769f 100644 --- a/tests/test_cloudfront/test_cloudfront.py +++ b/tests/test_cloudfront/test_cloudfront.py @@ -248,3 +248,34 @@ def test_update_default_root_object(): dist_config = client.get_distribution_config(Id=dist_id) assert dist_config["DistributionConfig"]["DefaultRootObject"] == "index.html" + + +@mock_aws +def test_update_distribution_applies_changes(): + client = boto3.client("cloudfront", region_name="us-east-1") + + # Create standard distribution + config = scaffold.example_distribution_config(ref="ref") + dist = client.create_distribution(DistributionConfig=config) + dist_id = dist["Distribution"]["Id"] + + # Assert that default 'Enabled' value is false + actual_dist_config = client.get_distribution(Id=dist_id)["Distribution"][ + "DistributionConfig" + ] + assert not actual_dist_config["Enabled"] + + # Update 'Enabled' value to true + get_config_response = client.get_distribution_config(Id=dist_id) + actual_dist_config = get_config_response["DistributionConfig"] + etag = get_config_response["ETag"] + actual_dist_config["Enabled"] = True + client.update_distribution( + DistributionConfig=actual_dist_config, Id=dist_id, IfMatch=etag + ) + + # Assert that 'Enabled' value is true + actual_dist_config = client.get_distribution(Id=dist_id)["Distribution"][ + "DistributionConfig" + ] + assert actual_dist_config["Enabled"]