mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-06 11:23:48 -05:00
Update SMS sender validation to reject senders starting with 00
Having SMS senders that start with 00 can cause issues with Firetext due to Firetext's validation rules, so we shouldn't allow SMS senders to start with 00. Firetext treats a double 00 at the start of the senderID as an international prefix, so removes them. A sender of 00447876574016 would become 447876574016. Under Firetext's validation rules, an SMS sender of five 0s (00000) would become 4400. This is because the first 00 are removed (as the international prefix). The third 0 is seen as the start of a phone number, and becomes 44, leaving the final 00 = 4400.
This commit is contained in:
@@ -32,6 +32,7 @@ from wtforms.validators import DataRequired, Length, Optional, Regexp
|
||||
from app.main.validators import (
|
||||
Blacklist,
|
||||
CsvFileValidator,
|
||||
DoesNotStartWithDoubleZero,
|
||||
LettersNumbersAndFullStopsOnly,
|
||||
NoCommasInPlaceHolders,
|
||||
OnlyGSMCharacters,
|
||||
@@ -594,6 +595,7 @@ class ServiceSmsSenderForm(StripWhitespaceForm):
|
||||
Length(max=11, message="Enter 11 characters or fewer"),
|
||||
Length(min=3, message="Enter 3 characters or more"),
|
||||
LettersNumbersAndFullStopsOnly(),
|
||||
DoesNotStartWithDoubleZero(),
|
||||
]
|
||||
)
|
||||
is_default = BooleanField("Make this text message sender the default")
|
||||
|
||||
@@ -92,3 +92,13 @@ class LettersNumbersAndFullStopsOnly:
|
||||
def __call__(self, form, field):
|
||||
if field.data and not re.match(self.regex, field.data):
|
||||
raise ValidationError(self.message)
|
||||
|
||||
|
||||
class DoesNotStartWithDoubleZero:
|
||||
|
||||
def __init__(self, message="Can't start with 00"):
|
||||
self.message = message
|
||||
|
||||
def __call__(self, form, field):
|
||||
if field.data and field.data.startswith("00"):
|
||||
raise ValidationError(self.message)
|
||||
|
||||
@@ -217,6 +217,10 @@ def test_sms_sender_form_validation(
|
||||
form.validate()
|
||||
assert 'Enter 3 characters or more' == form.errors['sms_sender'][0]
|
||||
|
||||
form.sms_sender.data = '000'
|
||||
form.sms_sender.data = '111'
|
||||
form.validate()
|
||||
assert not form.errors
|
||||
|
||||
form.sms_sender.data = '00111222333'
|
||||
form.validate()
|
||||
assert "Can't start with 00" == form.errors['sms_sender'][0]
|
||||
|
||||
@@ -873,6 +873,7 @@ def test_incorrect_letter_contact_block_input(
|
||||
('abcdefghijkhgkg', 'Enter 11 characters or fewer'),
|
||||
(' ¯\_(ツ)_/¯ ', 'Use letters and numbers only'),
|
||||
('blood.co.uk', None),
|
||||
('00123', "Can't start with 00")
|
||||
])
|
||||
def test_incorrect_sms_sender_input(
|
||||
sms_sender_input,
|
||||
|
||||
Reference in New Issue
Block a user