SES: list_identities() now supports the IdentityType-parameter (#6956)
This commit is contained in:
parent
b844fdd4c3
commit
370a3d1a9a
@ -182,7 +182,11 @@ class SESBackend(BaseBackend):
|
|||||||
if domain.lower() not in self.domains:
|
if domain.lower() not in self.domains:
|
||||||
self.domains.append(domain.lower())
|
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
|
return self.domains + self.addresses
|
||||||
|
|
||||||
def list_verified_email_addresses(self) -> List[str]:
|
def list_verified_email_addresses(self) -> List[str]:
|
||||||
|
@ -3,6 +3,7 @@ from typing import Any, Dict, List
|
|||||||
|
|
||||||
from moto.core.responses import BaseResponse
|
from moto.core.responses import BaseResponse
|
||||||
from moto.core.utils import utcnow
|
from moto.core.utils import utcnow
|
||||||
|
from .exceptions import ValidationError
|
||||||
from .models import ses_backends, SESBackend
|
from .models import ses_backends, SESBackend
|
||||||
|
|
||||||
|
|
||||||
@ -27,7 +28,12 @@ class EmailResponse(BaseResponse):
|
|||||||
return template.render()
|
return template.render()
|
||||||
|
|
||||||
def list_identities(self) -> str:
|
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)
|
template = self.response_template(LIST_IDENTITIES_RESPONSE)
|
||||||
return template.render(identities=identities)
|
return template.render(identities=identities)
|
||||||
|
|
||||||
|
@ -11,13 +11,32 @@ from . import ses_aws_verified
|
|||||||
|
|
||||||
|
|
||||||
@mock_ses
|
@mock_ses
|
||||||
def test_verify_email_identity():
|
def test_list_verified_identities():
|
||||||
conn = boto3.client("ses", region_name="us-east-1")
|
conn = boto3.client("ses", region_name="us-east-1")
|
||||||
conn.verify_email_identity(EmailAddress="test@example.com")
|
conn.verify_email_identity(EmailAddress="test@example.com")
|
||||||
|
|
||||||
identities = conn.list_identities()
|
identities = conn.list_identities()["Identities"]
|
||||||
address = identities["Identities"][0]
|
assert identities == ["test@example.com"]
|
||||||
assert address == "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
|
@mock_ses
|
||||||
@ -50,18 +69,6 @@ def test_verify_email_address():
|
|||||||
assert email == "test@example.com"
|
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
|
@mock_ses
|
||||||
def test_delete_identity():
|
def test_delete_identity():
|
||||||
conn = boto3.client("ses", region_name="us-east-1")
|
conn = boto3.client("ses", region_name="us-east-1")
|
||||||
|
Loading…
Reference in New Issue
Block a user