mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-08 15:28:44 +00:00
Trigger vault sync after imports
This commit is contained in:
@@ -3257,6 +3257,7 @@ class PasswordManager:
|
||||
parent_seed=self.parent_seed,
|
||||
)
|
||||
print(colored("Database imported successfully.", "green"))
|
||||
self.sync_vault()
|
||||
except Exception as e:
|
||||
logging.error(f"Failed to import database: {e}", exc_info=True)
|
||||
print(colored(f"Error: Failed to import database: {e}", "red"))
|
||||
|
@@ -513,6 +513,7 @@ async def import_vault(
|
||||
if not path:
|
||||
raise HTTPException(status_code=400, detail="Missing file or path")
|
||||
_pm.handle_import_database(Path(path))
|
||||
_pm.sync_vault()
|
||||
return {"status": "ok"}
|
||||
|
||||
|
||||
|
@@ -372,6 +372,7 @@ def vault_import(
|
||||
"""Import a vault from an encrypted JSON file."""
|
||||
pm = _get_pm(ctx)
|
||||
pm.handle_import_database(Path(file))
|
||||
pm.sync_vault()
|
||||
typer.echo(str(file))
|
||||
|
||||
|
||||
|
@@ -218,6 +218,7 @@ def test_vault_import_via_path(client, tmp_path):
|
||||
called["path"] = path
|
||||
|
||||
api._pm.handle_import_database = import_db
|
||||
api._pm.sync_vault = lambda: called.setdefault("sync", True)
|
||||
file_path = tmp_path / "b.json"
|
||||
file_path.write_text("{}")
|
||||
|
||||
@@ -230,6 +231,7 @@ def test_vault_import_via_path(client, tmp_path):
|
||||
assert res.status_code == 200
|
||||
assert res.json() == {"status": "ok"}
|
||||
assert called["path"] == file_path
|
||||
assert called.get("sync") is True
|
||||
|
||||
|
||||
def test_vault_import_via_upload(client, tmp_path):
|
||||
@@ -240,6 +242,7 @@ def test_vault_import_via_upload(client, tmp_path):
|
||||
called["path"] = path
|
||||
|
||||
api._pm.handle_import_database = import_db
|
||||
api._pm.sync_vault = lambda: called.setdefault("sync", True)
|
||||
file_path = tmp_path / "c.json"
|
||||
file_path.write_text("{}")
|
||||
|
||||
@@ -253,6 +256,7 @@ 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)
|
||||
assert called.get("sync") is True
|
||||
|
||||
|
||||
def test_vault_lock_endpoint(client):
|
||||
|
@@ -88,7 +88,9 @@ def test_vault_import(monkeypatch, tmp_path):
|
||||
called["path"] = path
|
||||
|
||||
pm = SimpleNamespace(
|
||||
handle_import_database=import_db, select_fingerprint=lambda fp: None
|
||||
handle_import_database=import_db,
|
||||
select_fingerprint=lambda fp: None,
|
||||
sync_vault=lambda: None,
|
||||
)
|
||||
monkeypatch.setattr(cli, "PasswordManager", lambda: pm)
|
||||
in_path = tmp_path / "in.json"
|
||||
@@ -98,6 +100,29 @@ def test_vault_import(monkeypatch, tmp_path):
|
||||
assert called["path"] == in_path
|
||||
|
||||
|
||||
def test_vault_import_triggers_sync(monkeypatch, tmp_path):
|
||||
called = {}
|
||||
|
||||
def import_db(path):
|
||||
called["path"] = path
|
||||
|
||||
def sync():
|
||||
called["sync"] = True
|
||||
|
||||
pm = SimpleNamespace(
|
||||
handle_import_database=import_db,
|
||||
sync_vault=sync,
|
||||
select_fingerprint=lambda fp: None,
|
||||
)
|
||||
monkeypatch.setattr(cli, "PasswordManager", lambda: pm)
|
||||
in_path = tmp_path / "in.json"
|
||||
in_path.write_text("{}")
|
||||
result = runner.invoke(app, ["vault", "import", "--file", str(in_path)])
|
||||
assert result.exit_code == 0
|
||||
assert called["path"] == in_path
|
||||
assert called.get("sync") is True
|
||||
|
||||
|
||||
def test_vault_change_password(monkeypatch):
|
||||
called = {}
|
||||
|
||||
|
Reference in New Issue
Block a user