From ff48188362ae034e9a1e5f79711b768fda06a0c5 Mon Sep 17 00:00:00 2001 From: Zachary Elliott Date: Wed, 19 Apr 2023 12:55:28 -0400 Subject: [PATCH] Corrects ECRClient.batch_get_image tag handling (#6230) --- moto/ecr/models.py | 2 +- tests/test_ecr/test_ecr_boto3.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/moto/ecr/models.py b/moto/ecr/models.py index e230eaa6a..ba80a78a2 100644 --- a/moto/ecr/models.py +++ b/moto/ecr/models.py @@ -624,7 +624,7 @@ class ECRBackend(BaseBackend): "imageDigest" in image_id and image.get_image_digest() == image_id["imageDigest"] ) or ( - "imageTag" in image_id and image.image_tag == image_id["imageTag"] + "imageTag" in image_id and image_id["imageTag"] in image.image_tags ): found = True response["images"].append(image.response_batch_get_image) diff --git a/tests/test_ecr/test_ecr_boto3.py b/tests/test_ecr/test_ecr_boto3.py index 1aaba3ba8..8f7deaa4b 100644 --- a/tests/test_ecr/test_ecr_boto3.py +++ b/tests/test_ecr/test_ecr_boto3.py @@ -1065,6 +1065,37 @@ def test_batch_get_image_that_doesnt_exist(): response["failures"][0]["imageId"]["imageTag"].should.equal("v5") +@mock_ecr +def test_batch_get_image_with_multiple_tags(): + client = boto3.client("ecr", region_name="us-east-1") + _ = client.create_repository(repositoryName="test_repository") + + manifest = json.dumps(_create_image_manifest()) + _ = client.put_image( + repositoryName="test_repository", + imageManifest=manifest, + imageTag="latest", + ) + + _ = client.put_image( + repositoryName="test_repository", + imageManifest=manifest, + imageTag="v1", + ) + + latest_response = client.batch_get_image( + repositoryName="test_repository", imageIds=[{"imageTag": "latest"}] + ) + + v1_response = client.batch_get_image( + repositoryName="test_repository", imageIds=[{"imageTag": "v1"}] + ) + + latest_response["images"][0]["imageManifest"].should.equal( + v1_response["images"][0]["imageManifest"] + ) + + @mock_ecr def test_batch_delete_image_by_tag(): client = boto3.client("ecr", region_name="us-east-1")