diff --git a/moto/ecr/models.py b/moto/ecr/models.py index 7457e0c43..e230eaa6a 100644 --- a/moto/ecr/models.py +++ b/moto/ecr/models.py @@ -318,6 +318,7 @@ class Image(BaseObject): response_object["imageId"]["imageTag"] = self.image_tag response_object["imageId"]["imageDigest"] = self.get_image_digest() response_object["imageManifest"] = self.image_manifest + response_object["imageManifestMediaType"] = self.image_manifest_mediatype response_object["repositoryName"] = self.repository response_object["registryId"] = self.registry_id return { diff --git a/moto/ecr/responses.py b/moto/ecr/responses.py index fb2884100..acb6a90f1 100644 --- a/moto/ecr/responses.py +++ b/moto/ecr/responses.py @@ -56,7 +56,10 @@ class ECRResponse(BaseResponse): repository_str = self._get_param("repositoryName") image_manifest = self._get_param("imageManifest") image_tag = self._get_param("imageTag") - image = self.ecr_backend.put_image(repository_str, image_manifest, image_tag) + image_manifest_media_type = self._get_param("imageManifestMediaType") + image = self.ecr_backend.put_image( + repository_str, image_manifest, image_tag, image_manifest_media_type + ) return json.dumps({"image": image.response_object}) diff --git a/tests/test_ecr/test_ecr_boto3.py b/tests/test_ecr/test_ecr_boto3.py index 31d41e28c..1aaba3ba8 100644 --- a/tests/test_ecr/test_ecr_boto3.py +++ b/tests/test_ecr/test_ecr_boto3.py @@ -350,6 +350,52 @@ def test_put_image(): response["image"]["registryId"].should.equal(ACCOUNT_ID) +@mock_ecr +def test_put_image_without_mediatype(): + client = boto3.client("ecr", region_name="us-east-1") + _ = client.create_repository(repositoryName="test_repository") + + image_manifest = _create_image_manifest() + _ = image_manifest.pop("mediaType") + + if os.environ.get("TEST_SERVER_MODE", "false").lower() == "true": + with pytest.raises(ClientError): + client.put_image( + repositoryName="test_repository", + imageManifest=json.dumps(image_manifest), + imageTag="latest", + ) + else: + error_msg = "image manifest mediatype not provided in manifest or parameter" + client.put_image.when.called_with( + repositoryName="test_repository", + imageManifest=json.dumps(image_manifest), + imageTag="latest", + ).should.throw(Exception, error_msg) + + +@mock_ecr +def test_put_image_with_imagemanifestmediatype(): + client = boto3.client("ecr", region_name="us-east-1") + _ = client.create_repository(repositoryName="test_repository") + + image_manifest = _create_image_manifest() + media_type = image_manifest.pop("mediaType") + + response = client.put_image( + repositoryName="test_repository", + imageManifest=json.dumps(image_manifest), + imageManifestMediaType=media_type, + imageTag="latest", + ) + + response["image"]["imageId"]["imageTag"].should.equal("latest") + response["image"]["imageId"]["imageDigest"].should.contain("sha") + response["image"]["repositoryName"].should.equal("test_repository") + response["image"]["imageManifestMediaType"].should.equal(media_type) + response["image"]["registryId"].should.equal(ACCOUNT_ID) + + @mock_ecr() def test_put_manifest_list(): client = boto3.client("ecr", region_name="us-east-1")