clanker / tests /test_identity.py
deucebucket's picture
M2.5: recognition-only HF login (anonymous-first, hashed ids)
2bb8b45 verified
Raw
History Blame Contribute Delete
886 Bytes
import sqlite3
from app.identity import hash_uid, RecognitionStore
def test_hash_is_stable_and_opaque():
h1 = hash_uid("hf-user-sub-123"); h2 = hash_uid("hf-user-sub-123")
assert h1 == h2 and len(h1) == 64 and "hf-user-sub-123" not in h1
def test_recognition_first_then_returning(tmp_path):
db = str(tmp_path / "soul.db"); sqlite3.connect(db).close()
s = RecognitionStore(db)
r1 = s.see("uidhash_abc")
assert r1["returning"] is False and r1["visits"] == 1
r2 = s.see("uidhash_abc")
assert r2["returning"] is True and r2["visits"] == 2
def test_store_keeps_no_username(tmp_path):
db = str(tmp_path / "soul.db"); sqlite3.connect(db).close()
s = RecognitionStore(db); s.see("uidhash_abc")
cols = [r[1] for r in sqlite3.connect(db).execute("pragma table_info(recognition)").fetchall()]
assert "username" not in cols and "name" not in cols