mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-19 14:09:20 -04:00
allow downgradeable unicode characters in SMS templates
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
from wtforms import ValidationError
|
from wtforms import ValidationError
|
||||||
from notifications_utils.template import Template
|
from notifications_utils.template import Template
|
||||||
from notifications_utils.gsm import get_non_gsm_characters
|
from notifications_utils.gsm import get_non_gsm_compatible_characters
|
||||||
|
|
||||||
|
from app import formatted_list
|
||||||
from app.main._blacklisted_passwords import blacklisted_passwords
|
from app.main._blacklisted_passwords import blacklisted_passwords
|
||||||
from app.utils import (
|
from app.utils import (
|
||||||
Spreadsheet,
|
Spreadsheet,
|
||||||
@@ -54,8 +55,10 @@ class NoCommasInPlaceHolders:
|
|||||||
|
|
||||||
class OnlyGSMCharacters:
|
class OnlyGSMCharacters:
|
||||||
def __call__(self, form, field):
|
def __call__(self, form, field):
|
||||||
non_gsm_characters = get_non_gsm_characters(field.data)
|
non_gsm_characters = sorted(list(get_non_gsm_compatible_characters(field.data)))
|
||||||
if non_gsm_characters:
|
if non_gsm_characters:
|
||||||
raise ValidationError('The following characters are not allowed in text messages: {}'.format(
|
raise ValidationError(
|
||||||
', '.join(non_gsm_characters)
|
'You can’t use {} in text messages. They won’t show up properly on everyone’s phones.'.format(
|
||||||
))
|
formatted_list(non_gsm_characters, conjunction='or')
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import pytest
|
import pytest
|
||||||
from app.main.forms import RegisterUserForm, ServiceSmsSender
|
from app.main.forms import RegisterUserForm, ServiceSmsSender
|
||||||
from app.main.validators import ValidGovEmail, NoCommasInPlaceHolders
|
from app.main.validators import ValidGovEmail, NoCommasInPlaceHolders, OnlyGSMCharacters
|
||||||
from wtforms import ValidationError
|
from wtforms import ValidationError
|
||||||
from unittest.mock import Mock
|
from unittest.mock import Mock
|
||||||
|
|
||||||
@@ -141,6 +141,21 @@ def test_for_commas_in_placeholders(
|
|||||||
NoCommasInPlaceHolders()(None, _gen_mock_field('Hello ((name))'))
|
NoCommasInPlaceHolders()(None, _gen_mock_field('Hello ((name))'))
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('msg', ['The quick brown fox', 'Thé “quick” bröwn fox\u200B'])
|
||||||
|
def test_gsm_character_validation(client, msg):
|
||||||
|
OnlyGSMCharacters()(None, _gen_mock_field(msg))
|
||||||
|
|
||||||
|
|
||||||
|
def test_non_gsm_character_validation(client):
|
||||||
|
with pytest.raises(ValidationError) as error:
|
||||||
|
OnlyGSMCharacters()(None, _gen_mock_field('∆ abc 📲 def 📵 ghi'))
|
||||||
|
|
||||||
|
assert str(error.value) == (
|
||||||
|
'You can’t use ‘∆’, ‘📲’ or ‘📵’ in text messages. '
|
||||||
|
'They won’t show up properly on everyone’s phones.'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_sms_sender_form_validation(
|
def test_sms_sender_form_validation(
|
||||||
client,
|
client,
|
||||||
mock_get_user_by_email,
|
mock_get_user_by_email,
|
||||||
|
|||||||
Reference in New Issue
Block a user