Add fingerprint management commands and API

This commit is contained in:
thePR0M3TH3AN
2025-07-09 15:30:36 -04:00
parent 34a551ba29
commit 13501561c8
6 changed files with 155 additions and 0 deletions

View File

@@ -109,3 +109,35 @@ def test_update_config_secret_mode(client):
assert res.status_code == 200
assert res.json() == {"status": "ok"}
assert called["val"] is True
def test_fingerprint_endpoints(client):
cl, token = client
calls = {}
api._pm.add_new_fingerprint = lambda: calls.setdefault("add", True)
api._pm.fingerprint_manager.remove_fingerprint = lambda fp: calls.setdefault(
"remove", fp
)
api._pm.select_fingerprint = lambda fp: calls.setdefault("select", fp)
headers = {"Authorization": f"Bearer {token}"}
res = cl.post("/api/v1/fingerprint", headers=headers)
assert res.status_code == 200
assert res.json() == {"status": "ok"}
assert calls.get("add") is True
res = cl.delete("/api/v1/fingerprint/abc", headers=headers)
assert res.status_code == 200
assert res.json() == {"status": "deleted"}
assert calls.get("remove") == "abc"
res = cl.post(
"/api/v1/fingerprint/select",
json={"fingerprint": "xyz"},
headers=headers,
)
assert res.status_code == 200
assert res.json() == {"status": "ok"}
assert calls.get("select") == "xyz"

View File

@@ -105,6 +105,54 @@ def test_fingerprint_list(monkeypatch):
assert "a" in result.stdout and "b" in result.stdout
def test_fingerprint_add(monkeypatch):
called = {}
def add():
called["add"] = True
pm = SimpleNamespace(
add_new_fingerprint=add,
select_fingerprint=lambda fp: None,
fingerprint_manager=SimpleNamespace(),
)
monkeypatch.setattr(cli, "PasswordManager", lambda: pm)
result = runner.invoke(app, ["fingerprint", "add"])
assert result.exit_code == 0
assert called.get("add") is True
def test_fingerprint_remove(monkeypatch):
called = {}
def remove(fp):
called["fp"] = fp
pm = SimpleNamespace(
fingerprint_manager=SimpleNamespace(remove_fingerprint=remove),
select_fingerprint=lambda fp: None,
)
monkeypatch.setattr(cli, "PasswordManager", lambda: pm)
result = runner.invoke(app, ["fingerprint", "remove", "abc"])
assert result.exit_code == 0
assert called.get("fp") == "abc"
def test_fingerprint_switch(monkeypatch):
called = {}
def switch(fp):
called["fp"] = fp
pm = SimpleNamespace(
select_fingerprint=switch, fingerprint_manager=SimpleNamespace()
)
monkeypatch.setattr(cli, "PasswordManager", lambda: pm)
result = runner.invoke(app, ["fingerprint", "switch", "def"])
assert result.exit_code == 0
assert called.get("fp") == "def"
def test_config_get(monkeypatch):
pm = SimpleNamespace(
config_manager=SimpleNamespace(