policies/password: add invalid test case
This commit is contained in:
parent
7eed70cfe9
commit
e818416863
|
@ -50,6 +50,7 @@ class PasswordPolicy(Policy):
|
||||||
field=self.password_field,
|
field=self.password_field,
|
||||||
fields=request.context.keys(),
|
fields=request.context.keys(),
|
||||||
)
|
)
|
||||||
|
return PolicyResult(False, _("Password not set in context"))
|
||||||
password = request.context[self.password_field]
|
password = request.context[self.password_field]
|
||||||
|
|
||||||
filter_regex = []
|
filter_regex = []
|
||||||
|
|
|
@ -9,6 +9,21 @@ from authentik.policies.types import PolicyRequest, PolicyResult
|
||||||
class TestPasswordPolicy(TestCase):
|
class TestPasswordPolicy(TestCase):
|
||||||
"""Test Password Policy"""
|
"""Test Password Policy"""
|
||||||
|
|
||||||
|
def test_invalid(self):
|
||||||
|
"""Test without password"""
|
||||||
|
policy = PasswordPolicy.objects.create(
|
||||||
|
name="test_invalid",
|
||||||
|
amount_uppercase=1,
|
||||||
|
amount_lowercase=2,
|
||||||
|
amount_symbols=3,
|
||||||
|
length_min=24,
|
||||||
|
error_message="test message",
|
||||||
|
)
|
||||||
|
request = PolicyRequest(get_anonymous_user())
|
||||||
|
result: PolicyResult = policy.passes(request)
|
||||||
|
self.assertFalse(result.passing)
|
||||||
|
self.assertEqual(result.messages[0], "Password not set in context")
|
||||||
|
|
||||||
def test_false(self):
|
def test_false(self):
|
||||||
"""Failing password case"""
|
"""Failing password case"""
|
||||||
policy = PasswordPolicy.objects.create(
|
policy = PasswordPolicy.objects.create(
|
||||||
|
|
Reference in New Issue