From 370a3d1a9a2a1a97334804f4233b54bb38d48b56 Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Fri, 27 Oct 2023 19:46:07 +0000 Subject: [PATCH] SES: list_identities() now supports the IdentityType-parameter (#6956) --- moto/ses/models.py | 6 ++++- moto/ses/responses.py | 8 ++++++- tests/test_ses/test_ses_boto3.py | 39 +++++++++++++++++++------------- 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/moto/ses/models.py b/moto/ses/models.py index 0427b4105ae2..f40c853febf7 100644 --- a/moto/ses/models.py +++ b/moto/ses/models.py @@ -182,7 +182,11 @@ def verify_domain(self, domain: str) -> None: if domain.lower() not in self.domains: self.domains.append(domain.lower()) - def list_identities(self) -> List[str]: + def list_identities(self, identity_type: str) -> List[str]: + if identity_type == "Domain": + return self.domains + if identity_type == "EmailAddress": + return self.addresses return self.domains + self.addresses def list_verified_email_addresses(self) -> List[str]: diff --git a/moto/ses/responses.py b/moto/ses/responses.py index ceef3ae19cdd..4d35dedb61e8 100644 --- a/moto/ses/responses.py +++ b/moto/ses/responses.py @@ -3,6 +3,7 @@ from moto.core.responses import BaseResponse from moto.core.utils import utcnow +from .exceptions import ValidationError from .models import ses_backends, SESBackend @@ -27,7 +28,12 @@ def verify_email_address(self) -> str: return template.render() def list_identities(self) -> str: - identities = self.backend.list_identities() + identity_type = self._get_param("IdentityType") + if identity_type not in [None, "EmailAddress", "Domain"]: + raise ValidationError( + f"Value '{identity_type}' at 'identityType' failed to satisfy constraint: Member must satisfy enum value set: [Domain, EmailAddress]" + ) + identities = self.backend.list_identities(identity_type) template = self.response_template(LIST_IDENTITIES_RESPONSE) return template.render(identities=identities) diff --git a/tests/test_ses/test_ses_boto3.py b/tests/test_ses/test_ses_boto3.py index c06408c17280..770839895236 100644 --- a/tests/test_ses/test_ses_boto3.py +++ b/tests/test_ses/test_ses_boto3.py @@ -11,13 +11,32 @@ @mock_ses -def test_verify_email_identity(): +def test_list_verified_identities(): conn = boto3.client("ses", region_name="us-east-1") conn.verify_email_identity(EmailAddress="test@example.com") - identities = conn.list_identities() - address = identities["Identities"][0] - assert address == "test@example.com" + identities = conn.list_identities()["Identities"] + assert identities == ["test@example.com"] + + conn.verify_domain_dkim(Domain="domain1.com") + conn.verify_domain_identity(Domain="domain2.com") + + identities = conn.list_identities()["Identities"] + assert identities == ["domain1.com", "domain2.com", "test@example.com"] + + identities = conn.list_identities(IdentityType="EmailAddress")["Identities"] + assert identities == ["test@example.com"] + + identities = conn.list_identities(IdentityType="Domain")["Identities"] + assert identities == ["domain1.com", "domain2.com"] + + with pytest.raises(ClientError) as exc: + conn.list_identities(IdentityType="Unknown") + err = exc.value.response["Error"] + assert ( + err["Message"] + == "Value 'Unknown' at 'identityType' failed to satisfy constraint: Member must satisfy enum value set: [Domain, EmailAddress]" + ) @mock_ses @@ -50,18 +69,6 @@ def test_verify_email_address(): assert email == "test@example.com" -@mock_ses -def test_domain_verify(): - conn = boto3.client("ses", region_name="us-east-1") - - conn.verify_domain_dkim(Domain="domain1.com") - conn.verify_domain_identity(Domain="domain2.com") - - identities = conn.list_identities() - domains = list(identities["Identities"]) - assert domains == ["domain1.com", "domain2.com"] - - @mock_ses def test_delete_identity(): conn = boto3.client("ses", region_name="us-east-1")