|
1 | 1 | import pytest
|
2 | 2 | import regex
|
3 |
| -from django.contrib.auth.hashers import ( |
4 |
| - UNUSABLE_PASSWORD_PREFIX, |
5 |
| - UNUSABLE_PASSWORD_SUFFIX_LENGTH, |
6 |
| -) |
7 | 3 | from ellar.core.security.hashers import (
|
| 4 | + _UNUSABLE_PASSWORD_PREFIX, |
| 5 | + _UNUSABLE_PASSWORD_SUFFIX_LENGTH, |
8 | 6 | BasePasswordHasher,
|
9 | 7 | BCryptPasswordHasher,
|
10 | 8 | BCryptSHA256PasswordHasher,
|
|
19 | 17 | make_password,
|
20 | 18 | )
|
21 | 19 |
|
22 |
| -try: |
23 |
| - import bcrypt |
24 |
| -except ImportError: |
25 |
| - bcrypt = None |
26 |
| - |
27 |
| -try: |
28 |
| - import argon2 |
29 |
| -except ImportError: |
30 |
| - argon2 = None |
31 |
| - |
32 |
| -# scrypt requires OpenSSL 1.1+ |
33 |
| -try: |
34 |
| - import hashlib |
35 |
| - |
36 |
| - scrypt = hashlib.scrypt |
37 |
| -except ImportError: |
38 |
| - scrypt = None |
39 |
| - |
40 |
| - |
41 |
| -class PBKDF2SingleIterationHasher(PBKDF2PasswordHasher): |
42 |
| - iterations = 1 |
43 |
| - |
44 | 20 |
|
45 | 21 | class TestUtilsHashPass:
|
46 | 22 | def test_simple(self):
|
@@ -186,13 +162,13 @@ def test_unusable(self):
|
186 | 162 | encoded = make_password(None)
|
187 | 163 | assert (
|
188 | 164 | len(encoded)
|
189 |
| - == len(UNUSABLE_PASSWORD_PREFIX) + UNUSABLE_PASSWORD_SUFFIX_LENGTH |
| 165 | + == len(_UNUSABLE_PASSWORD_PREFIX) + _UNUSABLE_PASSWORD_SUFFIX_LENGTH |
190 | 166 | )
|
191 | 167 |
|
192 | 168 | assert is_password_usable(encoded) is False
|
193 | 169 | assert check_password(None, encoded) is False
|
194 | 170 | assert check_password(encoded, encoded) is False
|
195 |
| - assert check_password(UNUSABLE_PASSWORD_PREFIX, encoded) is False |
| 171 | + assert check_password(_UNUSABLE_PASSWORD_PREFIX, encoded) is False |
196 | 172 | assert check_password("", encoded) is False
|
197 | 173 | assert check_password("lètmein", encoded) is False
|
198 | 174 | assert check_password("lètmeinz", encoded) is False
|
@@ -313,6 +289,9 @@ def test_encode_password_required(self, hasher_class):
|
313 | 289 |
|
314 | 290 | def test_load_library_no_algorithm(self):
|
315 | 291 | class InvalidPasswordHasher(BasePasswordHasher):
|
| 292 | + def must_update(self, encoded: str) -> bool: |
| 293 | + pass |
| 294 | + |
316 | 295 | def decode(self, encoded: str) -> dict:
|
317 | 296 | pass
|
318 | 297 |
|
|
0 commit comments