30 lines
1.0 KiB
Python
30 lines
1.0 KiB
Python
import importlib
|
|
|
|
from cryptography.fernet import Fernet
|
|
from fastapi.testclient import TestClient
|
|
|
|
|
|
def test_enroll_verify_and_list_users(tmp_path, monkeypatch):
|
|
database = tmp_path / "test.sqlite3"
|
|
monkeypatch.setenv("SIGVERIFY_DATABASE_URL", f"sqlite:///{database.as_posix()}")
|
|
monkeypatch.setenv("SIGVERIFY_FERNET_KEY", Fernet.generate_key().decode())
|
|
module = importlib.import_module("app.main")
|
|
client = TestClient(module.app)
|
|
payload = {
|
|
"user_id": "test-user",
|
|
"t": [0, 1, 2, 3],
|
|
"x": [0, 1, 2, 3],
|
|
"y": [1, 2, 1, 0],
|
|
"p": [0.5, 0.6, 0.7, 0.5],
|
|
}
|
|
|
|
assert client.get("/").status_code == 200
|
|
assert client.post("/enroll", json=payload).status_code == 200
|
|
assert client.post("/enroll", json=payload).status_code == 200
|
|
verified = client.post("/verify", json=payload)
|
|
assert verified.status_code == 200
|
|
assert verified.json()["accepted"] is True
|
|
assert client.get("/users").json()["users"] == [
|
|
{"user_id": "test-user", "template_count": 2}
|
|
]
|