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