Merge pull request #2538 from edekadigital/fix-sns-subscribe-sms-validation
Fix sns.subscribe validation for sms numbers
This commit is contained in:
commit
b19abbc63e
3 changed files with 28 additions and 10 deletions
|
|
@ -29,7 +29,7 @@ from .exceptions import (
|
|||
ResourceNotFoundError,
|
||||
TagLimitExceededError,
|
||||
)
|
||||
from .utils import make_arn_for_topic, make_arn_for_subscription
|
||||
from .utils import make_arn_for_topic, make_arn_for_subscription, is_e164
|
||||
|
||||
DEFAULT_ACCOUNT_ID = 123456789012
|
||||
DEFAULT_PAGE_SIZE = 100
|
||||
|
|
@ -413,6 +413,17 @@ class SNSBackend(BaseBackend):
|
|||
setattr(topic, attribute_name, attribute_value)
|
||||
|
||||
def subscribe(self, topic_arn, endpoint, protocol):
|
||||
if protocol == "sms":
|
||||
if re.search(r"[./-]{2,}", endpoint) or re.search(
|
||||
r"(^[./-]|[./-]$)", endpoint
|
||||
):
|
||||
raise SNSInvalidParameter("Invalid SMS endpoint: {}".format(endpoint))
|
||||
|
||||
reduced_endpoint = re.sub(r"[./-]", "", endpoint)
|
||||
|
||||
if not is_e164(reduced_endpoint):
|
||||
raise SNSInvalidParameter("Invalid SMS endpoint: {}".format(endpoint))
|
||||
|
||||
# AWS doesn't create duplicates
|
||||
old_subscription = self._find_subscription(topic_arn, endpoint, protocol)
|
||||
if old_subscription:
|
||||
|
|
|
|||
|
|
@ -211,14 +211,6 @@ class SNSResponse(BaseResponse):
|
|||
protocol = self._get_param("Protocol")
|
||||
attributes = self._get_attributes()
|
||||
|
||||
if protocol == "sms" and not is_e164(endpoint):
|
||||
return (
|
||||
self._error(
|
||||
"InvalidParameter", "Phone number does not meet the E164 format"
|
||||
),
|
||||
dict(status=400),
|
||||
)
|
||||
|
||||
subscription = self.backend.subscribe(topic_arn, endpoint, protocol)
|
||||
|
||||
if attributes is not None:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue