mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-11 10:28:41 -04:00
109526520: Use Regex validator to test the code is 5 digits.
This commit is contained in:
+3
-2
@@ -20,6 +20,7 @@ class LoginForm(Form):
|
|||||||
|
|
||||||
gov_uk_email = "(^[^@^\\s]+@[^@^\\.^\\s]+(\\.[^@^\\.^\\s]*)*.gov.uk)"
|
gov_uk_email = "(^[^@^\\s]+@[^@^\\.^\\s]+(\\.[^@^\\.^\\s]*)*.gov.uk)"
|
||||||
mobile_number = "^\\+44[\\d]{10}$"
|
mobile_number = "^\\+44[\\d]{10}$"
|
||||||
|
verify_code = "[\\d]{5}$"
|
||||||
|
|
||||||
|
|
||||||
class RegisterUserForm(Form):
|
class RegisterUserForm(Form):
|
||||||
@@ -43,10 +44,10 @@ class RegisterUserForm(Form):
|
|||||||
class VerifyForm(Form):
|
class VerifyForm(Form):
|
||||||
sms_code = StringField("Text message confirmation code",
|
sms_code = StringField("Text message confirmation code",
|
||||||
validators=[DataRequired(message='SMS code can not be empty'),
|
validators=[DataRequired(message='SMS code can not be empty'),
|
||||||
Length(min=5, max=5, message='Code must be 5 digits')])
|
Regexp(regex=verify_code, message='Code must be 5 digits')])
|
||||||
email_code = StringField("Email confirmation code",
|
email_code = StringField("Email confirmation code",
|
||||||
validators=[DataRequired(message='Email code can not be empty'),
|
validators=[DataRequired(message='Email code can not be empty'),
|
||||||
Length(min=5, max=5, message='Code must be 5 digits')])
|
Regexp(regex=verify_code, message='Code must be 5 digits')])
|
||||||
|
|
||||||
def validate_email_code(self, a):
|
def validate_email_code(self, a):
|
||||||
if self.email_code.data is not None:
|
if self.email_code.data is not None:
|
||||||
|
|||||||
@@ -107,8 +107,28 @@ def test_should_return_400_when_email_code_has_letter(notifications_admin, notif
|
|||||||
response = client.post('/verify',
|
response = client.post('/verify',
|
||||||
data={'sms_code': '23456',
|
data={'sms_code': '23456',
|
||||||
'email_code': 'abcde'})
|
'email_code': 'abcde'})
|
||||||
|
data = response.get_data(as_text=True)
|
||||||
assert response.status_code == 400
|
assert response.status_code == 400
|
||||||
assert 'Code does not match' in response.get_data(as_text=True)
|
assert 'email_code' in data
|
||||||
|
assert 'Code does not match' in data
|
||||||
|
assert 'Code must be 5 digits' in data
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_return_400_when_sms_code_is_too_short(notifications_admin, notifications_admin_db):
|
||||||
|
with notifications_admin.test_client() as client:
|
||||||
|
with client.session_transaction() as session:
|
||||||
|
user = _create_test_user()
|
||||||
|
session['user_id'] = user.id
|
||||||
|
session['sms_code'] = hashpw('23456')
|
||||||
|
session['email_code'] = hashpw('23456')
|
||||||
|
response = client.post('/verify',
|
||||||
|
data={'sms_code': '2345',
|
||||||
|
'email_code': '23456'})
|
||||||
|
assert response.status_code == 400
|
||||||
|
data = response.get_data(as_text=True)
|
||||||
|
assert 'sms_code' in data
|
||||||
|
assert 'Code must be 5 digits' in data
|
||||||
|
assert 'Code does not match' in data
|
||||||
|
|
||||||
|
|
||||||
def test_should_return_302_when_email_code_starts_with_zero(notifications_admin, notifications_admin_db):
|
def test_should_return_302_when_email_code_starts_with_zero(notifications_admin, notifications_admin_db):
|
||||||
|
|||||||
Reference in New Issue
Block a user