-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
8b7d1c3
commit 5c05510
Showing
7 changed files
with
212 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,21 @@ def test_password_contains_username(self): | |
form.errors.get('password1')) | ||
assert User.objects.count() == 0 | ||
|
||
def test_password_contains_username_case_insensitive(self): | ||
data = { | ||
'username': 'imagine71', | ||
'email': '[email protected]', | ||
'password1': 'LetsIMAGINE71things?', | ||
'password2': 'LetsIMAGINE71things?', | ||
'full_name': 'John Lennon', | ||
} | ||
form = forms.RegisterForm(data) | ||
|
||
assert form.is_valid() is False | ||
assert (_("The password is too similar to the username.") in | ||
form.errors.get('password1')) | ||
assert User.objects.count() == 0 | ||
|
||
def test_password_contains_blank_username(self): | ||
data = { | ||
'username': '', | ||
|
@@ -81,8 +96,8 @@ def test_password_contains_email(self): | |
data = { | ||
'username': 'imagine71', | ||
'email': '[email protected]', | ||
'password1': 'Isjohnreallythebest34?', | ||
'password2': 'Isjohnreallythebest34?', | ||
'password1': 'IsJOHNreallythebest34?', | ||
'password2': 'IsJOHNreallythebest34?', | ||
'full_name': 'John Lennon', | ||
} | ||
form = forms.RegisterForm(data) | ||
|
@@ -338,8 +353,23 @@ def test_password_contains_username(self): | |
|
||
data = { | ||
'oldpassword': 'beatles4Lyfe!', | ||
'password1': 'Letsimagine71?', | ||
'password2': 'Letsimagine71?', | ||
'password1': 'Letsimagine71?1234567890', | ||
'password2': 'Letsimagine71?1234567890', | ||
} | ||
form = forms.ChangePasswordForm(user, data) | ||
|
||
assert form.is_valid() is False | ||
assert (_("The password is too similar to the username.") in | ||
form.errors.get('password1')) | ||
|
||
def test_password_contains_username_case_insensitive(self): | ||
user = UserFactory.create( | ||
password='beatles4Lyfe!', username='imagine71') | ||
|
||
data = { | ||
'oldpassword': 'beatles4Lyfe!', | ||
'password1': 'LetsIMAGINE71?1234567890', | ||
'password2': 'LetsIMAGINE71?1234567890', | ||
} | ||
form = forms.ChangePasswordForm(user, data) | ||
|
||
|
@@ -353,8 +383,8 @@ def test_password_contains_email(self): | |
|
||
data = { | ||
'oldpassword': 'beatles4Lyfe!', | ||
'password1': 'Isjohnreallythebest34?', | ||
'password2': 'Isjohnreallythebest34?', | ||
'password1': 'IsJOHNreallythebest34?', | ||
'password2': 'IsJOHNreallythebest34?', | ||
} | ||
form = forms.ChangePasswordForm(user, data) | ||
|
||
|
@@ -444,8 +474,22 @@ def test_password_contains_username(self): | |
password='beatles4Lyfe!', username='imagine71') | ||
|
||
data = { | ||
'password1': 'Letsimagine71?', | ||
'password2': 'Letsimagine71?', | ||
'password1': 'Letsimagine71?1234567890', | ||
'password2': 'Letsimagine71?1234567890', | ||
} | ||
form = forms.ResetPasswordKeyForm(data, user=user) | ||
|
||
assert form.is_valid() is False | ||
assert (_("The password is too similar to the username.") in | ||
form.errors.get('password1')) | ||
|
||
def test_password_contains_username_case_insensitive(self): | ||
user = UserFactory.create( | ||
password='beatles4Lyfe!', username='imagine71') | ||
|
||
data = { | ||
'password1': 'LetsIMAGINE71?1234567890', | ||
'password2': 'LetsIMAGINE71?1234567890', | ||
} | ||
form = forms.ResetPasswordKeyForm(data, user=user) | ||
|
||
|
@@ -458,8 +502,8 @@ def test_password_contains_email(self): | |
password='beatles4Lyfe!', email='[email protected]') | ||
|
||
data = { | ||
'password1': 'Isjohnreallythebest34?', | ||
'password2': 'Isjohnreallythebest34?', | ||
'password1': 'IsJOHNreallythebest34?', | ||
'password2': 'IsJOHNreallythebest34?', | ||
} | ||
form = forms.ResetPasswordKeyForm(data, user=user) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,6 +101,19 @@ def test_password_contains_username(self): | |
assert (_("The password is too similar to the username.") in | ||
serializer._errors['password']) | ||
|
||
def test_password_contains_username_case_insensitive(self): | ||
data = { | ||
'username': 'yoko79', | ||
'email': '[email protected]', | ||
'password': 'iloveYOKO79!', | ||
'password_repeat': 'iloveYOKO79!', | ||
'full_name': 'John Lennon', | ||
} | ||
serializer = serializers.RegistrationSerializer(data=data) | ||
assert not serializer.is_valid() | ||
assert (_("The password is too similar to the username.") in | ||
serializer._errors['password']) | ||
|
||
def test_password_contains_blank_username(self): | ||
data = { | ||
'username': '', | ||
|
@@ -287,3 +300,109 @@ def test_user_can_not_change_pw(self): | |
assert serializer.is_valid() is False | ||
assert ("The password for this user can not be changed." | ||
in serializer.errors['non_field_errors']) | ||
|
||
def test_password_contains_username(self): | ||
user = UserFactory.create( | ||
password=BASIC_TEST_DATA['password'], | ||
username='imagine71', | ||
) | ||
request = APIRequestFactory().patch('/user/imagine71', {}) | ||
force_authenticate(request, user=user) | ||
data = { | ||
'username': 'imagine71', | ||
'current_password': BASIC_TEST_DATA['password'], | ||
'new_password': 'Letsimagine71!12345', | ||
're_new_password': 'Letsimagine71!12345', | ||
} | ||
serializer = serializers.ChangePasswordSerializer( | ||
user, data=data, context={'request': Request(request)}) | ||
|
||
assert serializer.is_valid() is False | ||
assert (_("The password is too similar to the username.") | ||
in serializer._errors['new_password']) | ||
|
||
def test_password_contains_username_case_insensitive(self): | ||
user = UserFactory.create( | ||
password=BASIC_TEST_DATA['password'], | ||
username='imagine71', | ||
) | ||
request = APIRequestFactory().patch('/user/imagine71', {}) | ||
force_authenticate(request, user=user) | ||
data = { | ||
'username': 'imagine71', | ||
'current_password': BASIC_TEST_DATA['password'], | ||
'new_password': 'LetsIMAGINE71!12345', | ||
're_new_password': 'LetsIMAGINE71!12345', | ||
} | ||
serializer = serializers.ChangePasswordSerializer( | ||
user, data=data, context={'request': Request(request)}) | ||
|
||
assert serializer.is_valid() is False | ||
assert (_("The password is too similar to the username.") | ||
in serializer._errors['new_password']) | ||
|
||
def test_password_contains_email(self): | ||
user = UserFactory.create( | ||
password=BASIC_TEST_DATA['password'], | ||
email=BASIC_TEST_DATA['email'], | ||
username='imagine71!', | ||
) | ||
request = APIRequestFactory().patch('/user/imagine71', {}) | ||
force_authenticate(request, user=user) | ||
data = { | ||
'current_password': BASIC_TEST_DATA['password'], | ||
'new_password': 'JOHNisjustheBest!!', | ||
're_new_password': 'JOHNisjustheBest!!', | ||
} | ||
|
||
serializer = serializers.ChangePasswordSerializer( | ||
user, data=data, context={'request': Request(request)}) | ||
assert serializer.is_valid() is False | ||
assert (_("Passwords cannot contain your email.") | ||
in serializer._errors['new_password']) | ||
|
||
def test_password_contains_less_than_min_characters(self): | ||
user = UserFactory.create( | ||
username='imagine71', | ||
password=BASIC_TEST_DATA['password'], | ||
) | ||
request = APIRequestFactory().patch('/user/imagine71', {}) | ||
force_authenticate(request, user=user) | ||
|
||
data = { | ||
'current_password': BASIC_TEST_DATA['password'], | ||
'new_password': 'yoko<3', | ||
're_new_password': 'yoko<3', | ||
} | ||
|
||
serializer = serializers.ChangePasswordSerializer( | ||
user, data=data, context={'request': Request(request)}) | ||
|
||
assert serializer.is_valid() is False | ||
assert (_("This password is too short." | ||
" It must contain at least 10 characters.") | ||
in serializer._errors['new_password']) | ||
|
||
def test_password_does_not_meet_unique_character_requirements(self): | ||
user = UserFactory.create( | ||
username='imagine71', | ||
password=BASIC_TEST_DATA['password'], | ||
) | ||
request = APIRequestFactory().patch('/user/imagine71', {}) | ||
force_authenticate(request, user=user) | ||
|
||
data = { | ||
'current_password': BASIC_TEST_DATA['password'], | ||
'new_password': 'iloveyoko', | ||
're_new_password': 'iloveyoko', | ||
} | ||
|
||
serializer = serializers.ChangePasswordSerializer( | ||
user, data=data, context={'request': Request(request)}) | ||
|
||
assert serializer.is_valid() is False | ||
assert (_("Passwords must contain at least 3" | ||
" of the following 4 character types:\n" | ||
"lowercase characters, uppercase characters," | ||
" special characters, and/or numerical character.\n" | ||
) in serializer._errors['new_password']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters