Add vault locking command and API

This commit is contained in:
thePR0M3TH3AN
2025-07-09 20:02:06 -04:00
parent cc4ba8486e
commit cc521dde76
7 changed files with 60 additions and 0 deletions

View File

@@ -220,6 +220,7 @@ def test_shutdown(client, monkeypatch):
("post", "/api/v1/entry/1/archive"),
("post", "/api/v1/entry/1/unarchive"),
("post", "/api/v1/change-password"),
("post", "/api/v1/vault/lock"),
],
)
def test_invalid_token_other_endpoints(client, method, path):

View File

@@ -253,3 +253,25 @@ def test_vault_import_via_upload(client, tmp_path):
assert res.status_code == 200
assert res.json() == {"status": "ok"}
assert isinstance(called.get("path"), Path)
def test_vault_lock_endpoint(client):
cl, token = client
called = {}
def lock():
called["locked"] = True
api._pm.locked = True
api._pm.lock_vault = lock
api._pm.locked = False
headers = {"Authorization": f"Bearer {token}"}
res = cl.post("/api/v1/vault/lock", headers=headers)
assert res.status_code == 200
assert res.json() == {"status": "locked"}
assert called.get("locked") is True
assert api._pm.locked is True
api._pm.unlock_vault = lambda: setattr(api._pm, "locked", False)
api._pm.unlock_vault()
assert api._pm.locked is False

View File

@@ -111,6 +111,23 @@ def test_vault_change_password(monkeypatch):
assert called.get("called") is True
def test_vault_lock(monkeypatch):
called = {}
def lock():
called["locked"] = True
pm.locked = True
pm = SimpleNamespace(
lock_vault=lock, locked=False, select_fingerprint=lambda fp: None
)
monkeypatch.setattr(cli, "PasswordManager", lambda: pm)
result = runner.invoke(app, ["vault", "lock"])
assert result.exit_code == 0
assert called.get("locked") is True
assert pm.locked is True
def test_vault_reveal_parent_seed(monkeypatch, tmp_path):
called = {}