From 62033d0a42b699ea75cb9699af2899566004859c Mon Sep 17 00:00:00 2001 From: eloymg Date: Wed, 14 Sep 2022 12:08:26 +0200 Subject: [PATCH] CloudFront: Bug distribution with tags (#5467) --- IMPLEMENTATION_COVERAGE.md | 4 ++-- moto/cloudfront/responses.py | 2 ++ .../test_cloudfront/test_cloudfront_dist_tags.py | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/IMPLEMENTATION_COVERAGE.md b/IMPLEMENTATION_COVERAGE.md index 3aee1ba81..6e097633f 100644 --- a/IMPLEMENTATION_COVERAGE.md +++ b/IMPLEMENTATION_COVERAGE.md @@ -613,7 +613,7 @@ - [ ] create_cache_policy - [ ] create_cloud_front_origin_access_identity - [X] create_distribution -- [ ] create_distribution_with_tags +- [X] create_distribution_with_tags - [ ] create_field_level_encryption_config - [ ] create_field_level_encryption_profile - [ ] create_function @@ -6465,4 +6465,4 @@ - workspaces - workspaces-web - xray - \ No newline at end of file + diff --git a/moto/cloudfront/responses.py b/moto/cloudfront/responses.py index 803bd2ec8..2e6148e87 100644 --- a/moto/cloudfront/responses.py +++ b/moto/cloudfront/responses.py @@ -41,6 +41,8 @@ class CloudFrontResponse(BaseResponse): if "DistributionConfigWithTags" in params: config = params.get("DistributionConfigWithTags") tags = (config.get("Tags", {}).get("Items") or {}).get("Tag", []) + if not isinstance(tags, list): + tags = [tags] else: config = params tags = [] diff --git a/tests/test_cloudfront/test_cloudfront_dist_tags.py b/tests/test_cloudfront/test_cloudfront_dist_tags.py index 40b314f2e..75f3627a6 100644 --- a/tests/test_cloudfront/test_cloudfront_dist_tags.py +++ b/tests/test_cloudfront/test_cloudfront_dist_tags.py @@ -19,3 +19,19 @@ def test_create_distribution_with_tags(): resp["Tags"].should.have.key("Items").length_of(2) resp["Tags"]["Items"].should.contain({"Key": "k1", "Value": "v1"}) resp["Tags"]["Items"].should.contain({"Key": "k2", "Value": "v2"}) + + +@mock_cloudfront +def test_create_distribution_with_tags_only_one_tag(): + client = boto3.client("cloudfront", region_name="us-west-1") + config = scaffold.example_distribution_config("ref") + tags = {"Items": [{"Key": "k1", "Value": "v1"}]} + config = {"DistributionConfig": config, "Tags": tags} + + resp = client.create_distribution_with_tags(DistributionConfigWithTags=config) + resp.should.have.key("Distribution") + + resp = client.list_tags_for_resource(Resource=resp["Distribution"]["ARN"]) + resp.should.have.key("Tags") + resp["Tags"].should.have.key("Items").length_of(1) + resp["Tags"]["Items"].should.contain({"Key": "k1", "Value": "v1"})