Aynkhn's picture
Deploy FaceVision to Hugging Face Spaces
0fd3d47 verified
Raw History Blame Contribute Delete
1.14 kB
"""Key comparison behaviour."""
from __future__ import annotations
from app.core.security import _keys_match
class TestKeysMatch:
def test_identical_keys_match(self):
assert _keys_match("secret", "secret") is True
def test_different_keys_do_not_match(self):
assert _keys_match("secret", "other") is False
def test_none_does_not_match(self):
assert _keys_match(None, "secret") is False
def test_empty_string_does_not_match(self):
assert _keys_match("", "secret") is False
def test_empty_expected_never_matches(self):
"""An unset server-side key must not turn into an open door."""
assert _keys_match("anything", "") is False
def test_non_ascii_key_returns_false_without_raising(self):
"""compare_digest raises on non-ASCII str; encoding first prevents a 500."""
assert _keys_match("kéy-wîth-ünicode", "secret") is False
def test_non_ascii_on_both_sides_still_compares(self):
assert _keys_match("pässwort", "pässwort") is True
def test_prefix_does_not_match(self):
assert _keys_match("sec", "secret") is False