mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-09 07:48:57 +00:00
Merge pull request #748 from PR0M3TH3AN/codex/remove-stray-seedpass-files-after-migration
Clean up legacy index files after migration
This commit is contained in:
@@ -67,6 +67,17 @@ class Vault:
|
|||||||
legacy_checksum.rename(
|
legacy_checksum.rename(
|
||||||
self.fingerprint_dir / "seedpass_entries_db_checksum.txt"
|
self.fingerprint_dir / "seedpass_entries_db_checksum.txt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Remove any leftover legacy files to avoid triggering migration again
|
||||||
|
for stray in self.fingerprint_dir.glob("seedpass_passwords_db*.enc"):
|
||||||
|
try:
|
||||||
|
stray.unlink()
|
||||||
|
except FileNotFoundError:
|
||||||
|
pass
|
||||||
|
stray_checksum = self.fingerprint_dir / "seedpass_passwords_db_checksum.txt"
|
||||||
|
if stray_checksum.exists():
|
||||||
|
stray_checksum.unlink()
|
||||||
|
|
||||||
self.migrated_from_legacy = True
|
self.migrated_from_legacy = True
|
||||||
print(
|
print(
|
||||||
colored(
|
colored(
|
||||||
|
@@ -52,6 +52,38 @@ def test_legacy_index_migrates(monkeypatch, tmp_path: Path):
|
|||||||
assert backup.exists()
|
assert backup.exists()
|
||||||
|
|
||||||
|
|
||||||
|
def test_legacy_index_migration_removes_strays(monkeypatch, tmp_path: Path):
|
||||||
|
vault, _ = create_vault(tmp_path, TEST_SEED, TEST_PASSWORD)
|
||||||
|
|
||||||
|
key = derive_index_key(TEST_SEED)
|
||||||
|
data = {"schema_version": 4, "entries": {}}
|
||||||
|
enc = Fernet(key).encrypt(json.dumps(data).encode())
|
||||||
|
|
||||||
|
legacy_file = tmp_path / "seedpass_passwords_db.json.enc"
|
||||||
|
legacy_file.write_bytes(enc)
|
||||||
|
(tmp_path / "seedpass_passwords_db_checksum.txt").write_text(
|
||||||
|
hashlib.sha256(enc).hexdigest()
|
||||||
|
)
|
||||||
|
|
||||||
|
stray_file = tmp_path / "seedpass_passwords_db.extra.enc"
|
||||||
|
stray_file.write_text("junk")
|
||||||
|
|
||||||
|
monkeypatch.setattr("builtins.input", lambda *_a, **_k: "y")
|
||||||
|
|
||||||
|
# First load triggers migration and removes stray legacy files
|
||||||
|
loaded = vault.load_index()
|
||||||
|
assert loaded == data
|
||||||
|
assert not stray_file.exists()
|
||||||
|
|
||||||
|
# Subsequent load should not detect any legacy files
|
||||||
|
loaded_again = vault.load_index()
|
||||||
|
assert loaded_again == data
|
||||||
|
|
||||||
|
assert (tmp_path / "seedpass_entries_db.json.enc").exists()
|
||||||
|
assert list(tmp_path.glob("seedpass_passwords_db*.enc")) == []
|
||||||
|
assert not (tmp_path / "seedpass_passwords_db_checksum.txt").exists()
|
||||||
|
|
||||||
|
|
||||||
def test_migration_triggers_sync(monkeypatch, tmp_path: Path):
|
def test_migration_triggers_sync(monkeypatch, tmp_path: Path):
|
||||||
vault, enc_mgr = create_vault(tmp_path, TEST_SEED, TEST_PASSWORD)
|
vault, enc_mgr = create_vault(tmp_path, TEST_SEED, TEST_PASSWORD)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user