summaryrefslogtreecommitdiff
path: root/tests/auth_tests
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2023-01-13 09:09:58 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-01-17 11:49:15 +0100
commitb5ac6e78f838376b61f3f7dfccd66f906ad6d394 (patch)
tree3fce0b4e0d01e300b1ce39bfc48f1963442d7b0a /tests/auth_tests
parentce7b4f39e3635bfcaa2cec84d5da93c1dedcaa9c (diff)
downloaddjango-b5ac6e78f838376b61f3f7dfccd66f906ad6d394.tar.gz
Refs #33691 -- Removed django.contrib.auth.hashers.CryptPasswordHasher per deprecation timeline.
Diffstat (limited to 'tests/auth_tests')
-rw-r--r--tests/auth_tests/test_hashers.py63
1 files changed, 1 insertions, 62 deletions
diff --git a/tests/auth_tests/test_hashers.py b/tests/auth_tests/test_hashers.py
index 4d718da46a..b419b0349d 100644
--- a/tests/auth_tests/test_hashers.py
+++ b/tests/auth_tests/test_hashers.py
@@ -19,17 +19,7 @@ from django.contrib.auth.hashers import (
)
from django.test import SimpleTestCase, ignore_warnings
from django.test.utils import override_settings
-from django.utils.deprecation import RemovedInDjango50Warning, RemovedInDjango51Warning
-
-# RemovedInDjango50Warning.
-try:
- import crypt
-except ImportError:
- crypt = None
-else:
- # On some platforms (e.g. OpenBSD), crypt.crypt() always return None.
- if crypt.crypt("") is None:
- crypt = None
+from django.utils.deprecation import RemovedInDjango51Warning
try:
import bcrypt
@@ -239,57 +229,6 @@ class TestUtilsHashPass(SimpleTestCase):
with self.assertRaisesMessage(RemovedInDjango51Warning, msg):
get_hasher("unsalted_sha1")
- @ignore_warnings(category=RemovedInDjango50Warning)
- @skipUnless(crypt, "no crypt module to generate password.")
- @override_settings(
- PASSWORD_HASHERS=["django.contrib.auth.hashers.CryptPasswordHasher"]
- )
- def test_crypt(self):
- encoded = make_password("lètmei", "ab", "crypt")
- self.assertEqual(encoded, "crypt$$ab1Hv2Lg7ltQo")
- self.assertTrue(is_password_usable(encoded))
- self.assertTrue(check_password("lètmei", encoded))
- self.assertFalse(check_password("lètmeiz", encoded))
- self.assertEqual(identify_hasher(encoded).algorithm, "crypt")
- # Blank passwords
- blank_encoded = make_password("", "ab", "crypt")
- self.assertTrue(blank_encoded.startswith("crypt$"))
- self.assertTrue(is_password_usable(blank_encoded))
- self.assertTrue(check_password("", blank_encoded))
- self.assertFalse(check_password(" ", blank_encoded))
-
- @ignore_warnings(category=RemovedInDjango50Warning)
- @skipUnless(crypt, "no crypt module to generate password.")
- @override_settings(
- PASSWORD_HASHERS=["django.contrib.auth.hashers.CryptPasswordHasher"]
- )
- def test_crypt_encode_invalid_salt(self):
- hasher = get_hasher("crypt")
- msg = "salt must be of length 2."
- with self.assertRaisesMessage(ValueError, msg):
- hasher.encode("password", salt="a")
-
- @ignore_warnings(category=RemovedInDjango50Warning)
- @skipUnless(crypt, "no crypt module to generate password.")
- @override_settings(
- PASSWORD_HASHERS=["django.contrib.auth.hashers.CryptPasswordHasher"]
- )
- def test_crypt_encode_invalid_hash(self):
- hasher = get_hasher("crypt")
- msg = "hash must be provided."
- with mock.patch("crypt.crypt", return_value=None):
- with self.assertRaisesMessage(TypeError, msg):
- hasher.encode("password", salt="ab")
-
- @skipUnless(crypt, "no crypt module to generate password.")
- @override_settings(
- PASSWORD_HASHERS=["django.contrib.auth.hashers.CryptPasswordHasher"]
- )
- def test_crypt_deprecation_warning(self):
- msg = "django.contrib.auth.hashers.CryptPasswordHasher is deprecated."
- with self.assertRaisesMessage(RemovedInDjango50Warning, msg):
- get_hasher("crypt")
-
@skipUnless(bcrypt, "bcrypt not installed")
def test_bcrypt_sha256(self):
encoded = make_password("lètmein", hasher="bcrypt_sha256")