From 8a0ad1ebe313a4f4fca6e9068c06ee400d15b8a4 Mon Sep 17 00:00:00 2001 From: Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> Date: Wed, 16 Apr 2025 15:44:00 -0300 Subject: Refs #35959 -- Added render_password_as_hash auth template tag for password rendering. --- tests/auth_tests/test_forms.py | 23 ++++++++++++++++++++++ tests/auth_tests/test_templatetags.py | 37 +++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 tests/auth_tests/test_templatetags.py (limited to 'tests') diff --git a/tests/auth_tests/test_forms.py b/tests/auth_tests/test_forms.py index 0f8b48286a..df91f100f5 100644 --- a/tests/auth_tests/test_forms.py +++ b/tests/auth_tests/test_forms.py @@ -1445,6 +1445,29 @@ class ReadOnlyPasswordHashTest(SimpleTestCase): "", ) + def test_render_no_password(self): + widget = ReadOnlyPasswordHashWidget() + self.assertHTMLEqual( + widget.render("name", None, {}), + "
No password set.
" + 'Set password' + "
" + "Invalid password format or unknown hashing algorithm." + '
algorithm: pbkdf2_sha256 " + "iterations: 100000 " + "salt: a6Pucb****** " + "hash: WmCkn9**************************************" + "
" + ) + self.assertEqual(render_password_as_hash(value), hashed_html) + + def test_invalid_password(self): + expected = ( + "Invalid password format or unknown hashing algorithm." + "
" + ) + for value in ["pbkdf2_sh", "md5$password", "invalid", "testhash$password"]: + with self.subTest(value=value): + self.assertEqual(render_password_as_hash(value), expected) + + def test_no_password(self): + expected = "No password set.
" + for value in ["", None, make_password(None)]: + with self.subTest(value=value): + self.assertEqual(render_password_as_hash(value), expected) -- cgit v1.3