| 1 |
from allauth.mfa.internal.flows import trust |
| 2 |
from allauth.mfa.models import Authenticator |
| 3 |
|
| 4 |
|
| 5 |
def test_cookie_encoding(): |
| 6 |
pass |
| 7 |
|
| 8 |
|
| 9 |
def test_fingerprint_is_stable(user_with_totp, user_with_recovery_codes): |
| 10 |
fp = trust.create_config_fingerprint(user_with_totp) |
| 11 |
fp2 = trust.create_config_fingerprint(user_with_totp) |
| 12 |
assert fp == fp2 |
| 13 |
|
| 14 |
|
| 15 |
def test_fingerprint_changes_on_password_change(user_with_totp, password_factory): |
| 16 |
fp = trust.create_config_fingerprint(user_with_totp) |
| 17 |
user_with_totp.set_password(password_factory()) |
| 18 |
fp2 = trust.create_config_fingerprint(user_with_totp) |
| 19 |
assert fp != fp2 |
| 20 |
|
| 21 |
|
| 22 |
def test_fingerprint_changes_on_recovery_codes_change( |
| 23 |
user_with_recovery_codes, password_factory |
| 24 |
): |
| 25 |
fp = trust.create_config_fingerprint(user_with_recovery_codes) |
| 26 |
auth = Authenticator.objects.get( |
| 27 |
user=user_with_recovery_codes, type=Authenticator.Type.RECOVERY_CODES |
| 28 |
) |
| 29 |
auth.data["seed"] = password_factory() |
| 30 |
auth.save() |
| 31 |
fp2 = trust.create_config_fingerprint(user_with_recovery_codes) |
| 32 |
assert fp != fp2 |
| 33 |
|
| 34 |
|
| 35 |
def test_fingerprint_changes_on_new_authenticator(user_with_totp): |
| 36 |
fp = trust.create_config_fingerprint(user_with_totp) |
| 37 |
Authenticator.objects.create( |
| 38 |
user=user_with_totp, type=Authenticator.Type.RECOVERY_CODES, data={} |
| 39 |
) |
| 40 |
fp2 = trust.create_config_fingerprint(user_with_totp) |
| 41 |
assert fp != fp2 |
| 42 |
|
| 43 |
|
| 44 |
def test_fingerprint_changes_on_authenticator_deletion( |
| 45 |
user_with_totp, user_with_recovery_codes |
| 46 |
): |
| 47 |
fp = trust.create_config_fingerprint(user_with_totp) |
| 48 |
Authenticator.objects.filter( |
| 49 |
user=user_with_recovery_codes, type=Authenticator.Type.RECOVERY_CODES |
| 50 |
).delete() |
| 51 |
fp2 = trust.create_config_fingerprint(user_with_totp) |
| 52 |
assert fp != fp2 |