mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-09 15:58:48 +00:00
Use vault migration flag to prompt sync
This commit is contained in:
@@ -1157,8 +1157,14 @@ class PasswordManager:
|
|||||||
)
|
)
|
||||||
|
|
||||||
migrated = False
|
migrated = False
|
||||||
|
index_exists = (
|
||||||
|
self.vault.index_file.exists()
|
||||||
|
or (
|
||||||
|
self.vault.fingerprint_dir / "seedpass_passwords_db.json.enc"
|
||||||
|
).exists()
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
self.vault.load_index(return_migration_flag=True)
|
_, migrated = self.vault.load_index(return_migration_flag=True)
|
||||||
except RuntimeError as exc:
|
except RuntimeError as exc:
|
||||||
print(colored(str(exc), "red"))
|
print(colored(str(exc), "red"))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@@ -1222,8 +1228,9 @@ class PasswordManager:
|
|||||||
delta_since=self.delta_since or None,
|
delta_since=self.delta_since or None,
|
||||||
)
|
)
|
||||||
|
|
||||||
if getattr(self.encryption_manager, "last_migration_performed", False):
|
if migrated and index_exists:
|
||||||
print(colored("Local database migration successful.", "green"))
|
print(colored("Local database migration successful.", "green"))
|
||||||
|
if self.encryption_manager is not None:
|
||||||
self.encryption_manager.last_migration_performed = False
|
self.encryption_manager.last_migration_performed = False
|
||||||
if not self.offline_mode and confirm_action(
|
if not self.offline_mode and confirm_action(
|
||||||
"Do you want to sync the migrated profile to Nostr now?"
|
"Do you want to sync the migrated profile to Nostr now?"
|
||||||
|
@@ -245,3 +245,38 @@ def test_legacy_index_reinit_syncs_once_when_confirmed(monkeypatch, tmp_path: Pa
|
|||||||
|
|
||||||
assert calls["sync"] == 1
|
assert calls["sync"] == 1
|
||||||
assert enc_mgr.last_migration_performed is False
|
assert enc_mgr.last_migration_performed is False
|
||||||
|
|
||||||
|
|
||||||
|
def test_schema_migration_triggers_sync(monkeypatch, tmp_path: Path):
|
||||||
|
vault, enc_mgr = create_vault(tmp_path, TEST_SEED, TEST_PASSWORD)
|
||||||
|
|
||||||
|
data = {"schema_version": 3, "entries": {}}
|
||||||
|
enc_mgr.save_json_data(data, Path("seedpass_entries_db.json.enc"))
|
||||||
|
enc_mgr.update_checksum(Path("seedpass_entries_db.json.enc"))
|
||||||
|
assert enc_mgr.last_migration_performed is False
|
||||||
|
|
||||||
|
pm = PasswordManager.__new__(PasswordManager)
|
||||||
|
pm.encryption_mode = EncryptionMode.SEED_ONLY
|
||||||
|
pm.encryption_manager = enc_mgr
|
||||||
|
pm.vault = Vault(enc_mgr, tmp_path)
|
||||||
|
pm.parent_seed = TEST_SEED
|
||||||
|
pm.fingerprint_dir = tmp_path
|
||||||
|
pm.current_fingerprint = tmp_path.name
|
||||||
|
pm.bip85 = SimpleNamespace()
|
||||||
|
pm.offline_mode = False
|
||||||
|
|
||||||
|
calls = {"sync": 0}
|
||||||
|
pm.sync_vault = lambda *a, **k: calls.__setitem__("sync", calls["sync"] + 1) or {
|
||||||
|
"manifest_id": "m",
|
||||||
|
"chunk_ids": [],
|
||||||
|
"delta_ids": [],
|
||||||
|
}
|
||||||
|
|
||||||
|
monkeypatch.setattr(
|
||||||
|
"seedpass.core.manager.NostrClient", lambda *a, **k: SimpleNamespace()
|
||||||
|
)
|
||||||
|
monkeypatch.setattr("seedpass.core.manager.confirm_action", lambda *_a, **_k: True)
|
||||||
|
|
||||||
|
pm.initialize_managers()
|
||||||
|
assert calls["sync"] == 1
|
||||||
|
assert enc_mgr.last_migration_performed is False
|
||||||
|
@@ -4,7 +4,6 @@ import threading
|
|||||||
import time
|
import time
|
||||||
from websocket import create_connection
|
from websocket import create_connection
|
||||||
|
|
||||||
import asyncio
|
|
||||||
import websockets
|
import websockets
|
||||||
from nostr.key_manager import KeyManager
|
from nostr.key_manager import KeyManager
|
||||||
from nostr_sdk import nostr_sdk as sdk
|
from nostr_sdk import nostr_sdk as sdk
|
||||||
|
Reference in New Issue
Block a user