Merge lp:~maxiberta/canonical-identity-provider/improve-password-validation-ascii into lp:canonical-identity-provider/release

Proposed by Maximiliano Bertacchini on 2019-10-14
Status: Merged
Approved by: Maximiliano Bertacchini on 2019-10-16
Approved revision: 1699
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: lp:~maxiberta/canonical-identity-provider/improve-password-validation-ascii
Merge into: lp:canonical-identity-provider/release
Diff against target: 82 lines (+10/-9)
3 files modified
src/api/v10/tests/test_forms.py (+2/-2)
src/identityprovider/tests/test_forms.py (+3/-5)
src/identityprovider/validators.py (+5/-2)
To merge this branch: bzr merge lp:~maxiberta/canonical-identity-provider/improve-password-validation-ascii
Reviewer Review Type Date Requested Status
Jonathan Hartley 2019-10-14 Approve on 2019-10-15
Review via email: mp+374104@code.launchpad.net

Commit message

Improve password placeholder and validation message to include the requirement of ascii encoding.

To post a comment you must log in.
Jonathan Hartley (tartley) wrote :

Looks good to me. One suggestion about wording of the error message, but approved regardless.

review: Approve
1699. By Maximiliano Bertacchini on 2019-10-16

Update invalid new password message.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/api/v10/tests/test_forms.py'
2--- src/api/v10/tests/test_forms.py 2018-10-16 21:41:53 +0000
3+++ src/api/v10/tests/test_forms.py 2019-10-16 14:01:58 +0000
4@@ -7,6 +7,7 @@
5
6 from api.v10.forms import WebserviceCreateAccountForm
7 from identityprovider.tests.utils import SSOBaseTestCase
8+from identityprovider.validators import PASSWORD_ENCODING_ERROR
9
10
11 class WebServiceCreateAccountFormTestCase(SSOBaseTestCase):
12@@ -16,8 +17,7 @@
13 'remote_ip': '127.0.0.1'}
14 form = WebserviceCreateAccountForm(data=data)
15 self.assertFalse(form.is_valid())
16- self.assertEqual(form.errors['password'][0],
17- 'Invalid characters in password')
18+ self.assertEqual(form.errors['password'], [PASSWORD_ENCODING_ERROR])
19
20 def test_default_platform(self):
21 form = WebserviceCreateAccountForm()
22
23=== modified file 'src/identityprovider/tests/test_forms.py'
24--- src/identityprovider/tests/test_forms.py 2019-06-18 20:13:31 +0000
25+++ src/identityprovider/tests/test_forms.py 2019-10-16 14:01:58 +0000
26@@ -57,7 +57,7 @@
27 from identityprovider.models.const import AccountStatus, EmailStatus
28 from identityprovider.tests import DEFAULT_USER_PASSWORD
29 from identityprovider.tests.utils import SSOBaseTestCase
30-from identityprovider.validators import BasicValidator
31+from identityprovider.validators import PASSWORD_ENCODING_ERROR, BasicValidator
32
33
34 class ValidNameTestCase(TestCase):
35@@ -261,8 +261,7 @@
36 data = {'password': u'Ñandú'}
37 form = self.get_form(data=data)
38 self.assertFalse(form.is_valid())
39- self.assertEqual(form.errors['password'][0],
40- 'Invalid characters in password')
41+ self.assertEqual(form.errors['password'], [PASSWORD_ENCODING_ERROR])
42
43 def test_short_password(self):
44 data = {'password': u'abcdef'}
45@@ -551,8 +550,7 @@
46 data = {'password': u'changüí'}
47 form = self.get_form(data=data)
48 self.assertFalse(form.is_valid())
49- self.assertEqual(form.errors['password'][0],
50- 'Invalid characters in password')
51+ self.assertEqual(form.errors['password'], [PASSWORD_ENCODING_ERROR])
52
53 def test_no_preferredemail(self):
54 # replace preferredemail property
55
56=== modified file 'src/identityprovider/validators.py'
57--- src/identityprovider/validators.py 2018-02-09 20:56:16 +0000
58+++ src/identityprovider/validators.py 2019-10-16 14:01:58 +0000
59@@ -7,10 +7,13 @@
60 from identityprovider.timeline_helpers import get_request_timing_function
61 from identityprovider.utils import password_is_blacklisted
62
63+PASSWORD_ENCODING_ERROR = _(
64+ 'Password must consist of lower or upper-case characters, digits, '
65+ 'spaces, or symbols in the ASCII encoding.')
66 PASSWORD_POLICY_ERROR = _(
67 'Password must be at least {min_length} characters long')
68 PASSWORD_POLICY_HELP_TEXT = _(
69- 'Password with at least {min_length} characters')
70+ 'Password with at least {min_length} characters (ASCII only)')
71 CANONICAL_PASSWORD_POLICY_ERROR = _(
72 "Password must consist of lower- and upper-case characters, and at "
73 "least one digit."
74@@ -62,7 +65,7 @@
75 # ascii only!
76 str(password)
77 except UnicodeEncodeError:
78- raise ValidationError(_("Invalid characters in password"))
79+ raise ValidationError(PASSWORD_ENCODING_ERROR)
80 if password is None or len(password) < self.MIN_LENGTH:
81 raise ValidationError(
82 PASSWORD_POLICY_ERROR.format(min_length=self.MIN_LENGTH))