Skip to content

Commit

Permalink
SES: list_identities() now supports the IdentityType-parameter (#6956)
Browse files Browse the repository at this point in the history
  • Loading branch information
bblommers authored Oct 27, 2023
1 parent b844fdd commit 370a3d1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 18 deletions.
6 changes: 5 additions & 1 deletion moto/ses/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
8 changes: 7 additions & 1 deletion moto/ses/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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)

Expand Down
39 changes: 23 additions & 16 deletions tests/test_ses/test_ses_boto3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]")

identities = conn.list_identities()
address = identities["Identities"][0]
assert address == "[email protected]"
identities = conn.list_identities()["Identities"]
assert identities == ["[email protected]"]

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", "[email protected]"]

identities = conn.list_identities(IdentityType="EmailAddress")["Identities"]
assert identities == ["[email protected]"]

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
Expand Down Expand Up @@ -50,18 +69,6 @@ def test_verify_email_address():
assert email == "[email protected]"


@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")
Expand Down

0 comments on commit 370a3d1

Please sign in to comment.