test: Fix validation tests.
Make them resilient to the default changing where it makes sense.
This commit is contained in:
@@ -136,7 +136,7 @@ class ActivationEmailTests(EmailTemplateTagMixin, CacheIsolationTestCase):
|
||||
params = {
|
||||
'username': 'test_user',
|
||||
'email': 'test_user@example.com',
|
||||
'password': 'edx',
|
||||
'password': 'long_password',
|
||||
'name': 'Test User',
|
||||
'honor_code': True,
|
||||
'terms_of_service': True
|
||||
|
||||
@@ -45,6 +45,11 @@ class PasswordPolicyValidatorsTestCase(unittest.TestCase):
|
||||
validate_password(password, user)
|
||||
assert msg in ' '.join(cm.value.messages)
|
||||
|
||||
@override_settings(AUTH_PASSWORD_VALIDATORS=[
|
||||
create_validator_config(
|
||||
'common.djangoapps.util.password_policy_validators.MinimumLengthValidator', {'min_length': 4}
|
||||
)
|
||||
])
|
||||
def test_unicode_password(self):
|
||||
""" Tests that validate_password enforces unicode """
|
||||
unicode_str = '𤭮'
|
||||
@@ -55,12 +60,17 @@ class PasswordPolicyValidatorsTestCase(unittest.TestCase):
|
||||
assert len(unicode_str) == 1
|
||||
|
||||
# Test length check
|
||||
self.validation_errors_checker(byte_str, 'This password is too short. It must contain at least 2 characters.')
|
||||
self.validation_errors_checker(byte_str + byte_str, None)
|
||||
self.validation_errors_checker(byte_str, 'This password is too short. It must contain at least 4 characters.')
|
||||
self.validation_errors_checker(byte_str * 4, None)
|
||||
|
||||
# Test badly encoded password
|
||||
self.validation_errors_checker(b'\xff\xff', 'Invalid password.')
|
||||
|
||||
@override_settings(AUTH_PASSWORD_VALIDATORS=[
|
||||
create_validator_config(
|
||||
'common.djangoapps.util.password_policy_validators.MinimumLengthValidator', {'min_length': 4}
|
||||
)
|
||||
])
|
||||
def test_password_unicode_normalization(self):
|
||||
""" Tests that validate_password normalizes passwords """
|
||||
# s ̣ ̇ (s with combining dot below and combining dot above)
|
||||
@@ -70,7 +80,7 @@ class PasswordPolicyValidatorsTestCase(unittest.TestCase):
|
||||
# When we normalize we expect the not_normalized password to fail
|
||||
# because it should be normalized to '\u1E69' -> ṩ
|
||||
self.validation_errors_checker(not_normalized_password,
|
||||
'This password is too short. It must contain at least 2 characters.')
|
||||
'This password is too short. It must contain at least 4 characters.')
|
||||
|
||||
@data(
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.MinimumLengthValidator', {'min_length': 2})], # lint-amnesty, pylint: disable=line-too-long
|
||||
|
||||
@@ -2689,20 +2689,30 @@ class RegistrationValidationViewTests(test_utils.ApiTestCase, OpenEdxEventsTestM
|
||||
{"username": str(USERNAME_INVALID_CHARS_ASCII)}
|
||||
)
|
||||
|
||||
@override_settings(AUTH_PASSWORD_VALIDATORS=[
|
||||
create_validator_config(
|
||||
'common.djangoapps.util.password_policy_validators.MinimumLengthValidator', {'min_length': 4}
|
||||
)
|
||||
])
|
||||
def test_password_empty_validation_decision(self):
|
||||
# 2 is the default setting for minimum length found in lms/envs/common.py
|
||||
# under AUTH_PASSWORD_VALIDATORS.MinimumLengthValidator
|
||||
msg = 'This password is too short. It must contain at least 2 characters.'
|
||||
msg = 'This password is too short. It must contain at least 4 characters.'
|
||||
self.assertValidationDecision(
|
||||
{'password': ''},
|
||||
{"password": msg}
|
||||
)
|
||||
|
||||
@override_settings(AUTH_PASSWORD_VALIDATORS=[
|
||||
create_validator_config(
|
||||
'common.djangoapps.util.password_policy_validators.MinimumLengthValidator', {'min_length': 4}
|
||||
)
|
||||
])
|
||||
def test_password_bad_min_length_validation_decision(self):
|
||||
password = 'p'
|
||||
# 2 is the default setting for minimum length found in lms/envs/common.py
|
||||
# under AUTH_PASSWORD_VALIDATORS.MinimumLengthValidator
|
||||
msg = 'This password is too short. It must contain at least 2 characters.'
|
||||
msg = 'This password is too short. It must contain at least 4 characters.'
|
||||
self.assertValidationDecision(
|
||||
{'password': password},
|
||||
{"password": msg}
|
||||
|
||||
Reference in New Issue
Block a user