-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(signup): add password validation
- Loading branch information
Showing
5 changed files
with
50 additions
and
36 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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
from django.test import TestCase | ||
|
||
from utils.validators import MISSING_SPECIAL_CHAR_ERROR | ||
|
||
valid_payload = { | ||
"first_name": "John", | ||
"last_name": "Doe", | ||
|
@@ -101,35 +103,6 @@ def test_strong_password_are_accepted(self): | |
errors=[], | ||
) | ||
|
||
def test_password_do_not_contain_user_info(self): | ||
payload_without_password = { | ||
"first_name": "John", | ||
"last_name": "Doe", | ||
"email": "[email protected]", | ||
"organism": "Commune", | ||
"function": "Maire", | ||
} | ||
|
||
bad_password_payloads = [ | ||
{"password1": "JohnDoe!", "password2": "JohnDoe!"}, | ||
{"password1": "John!", "password2": "John!"}, | ||
{"password1": "Doe!", "password2": "Doe!"}, | ||
{"password1": "Commune!", "password2": "Commune!"}, | ||
{"password1": "Maire!", "password2": "Maire!"}, | ||
{"password1": "CommuneMaire!", "password2": "CommuneMaire!"}, | ||
] | ||
|
||
for bad_password_payload in bad_password_payloads: | ||
with self.subTest(bad_password_payload=bad_password_payload): | ||
data = {**payload_without_password, **bad_password_payload} | ||
response = self.client.post(path=form_url, data=data) | ||
self.assertFormError( | ||
response=response, | ||
form="form", | ||
field="password1", | ||
errors="Le mot de passe ne doit pas contenir vos informations personnelles.", | ||
) | ||
|
||
def test_password_do_not_contain_common_password(self): | ||
password_payload = { | ||
"password1": "password!", | ||
|
@@ -138,11 +111,12 @@ def test_password_do_not_contain_common_password(self): | |
|
||
data = {**valid_payload, **password_payload} | ||
response = self.client.post(path=form_url, data=data) | ||
|
||
self.assertFormError( | ||
response=response, | ||
form="form", | ||
field="password1", | ||
errors="Le mot de passe est trop commun.", | ||
errors="Ce mot de passe est trop courant.", | ||
) | ||
|
||
def test_password_minimum_length(self): | ||
|
@@ -157,7 +131,7 @@ def test_password_minimum_length(self): | |
response=response, | ||
form="form", | ||
field="password1", | ||
errors="Le mot de passe doit contenir au moins 8 caractères.", | ||
errors="Ce mot de passe est trop court. Il doit contenir au minimum 8 caractères.", | ||
) | ||
|
||
def test_password_contains_special_chars(self): | ||
|
@@ -172,5 +146,5 @@ def test_password_contains_special_chars(self): | |
response=response, | ||
form="form", | ||
field="password1", | ||
errors="Le mot de passe doit contenir au moins un caractère spécial.", | ||
errors=MISSING_SPECIAL_CHAR_ERROR, | ||
) |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from django.core.exceptions import ValidationError | ||
from django.test import TestCase | ||
|
||
from .validators import ContainsSpecialCharacterValidator | ||
|
||
|
||
class TestValidators(TestCase): | ||
def test_contains_special_character_validator_with_invalid_password(self) -> None: | ||
validator = ContainsSpecialCharacterValidator() | ||
with self.assertRaises(ValidationError): | ||
validator.validate(password="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