mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-09 07:48:57 +00:00
Merge pull request #401 from PR0M3TH3AN/codex/add-migration-for-version-3-to-4
Add schema v4 migration and update tests
This commit is contained in:
@@ -58,7 +58,17 @@ def _v2_to_v3(data: dict) -> dict:
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
LATEST_VERSION = 3
|
@migration(3)
|
||||||
|
def _v3_to_v4(data: dict) -> dict:
|
||||||
|
"""Add tags defaults to each entry."""
|
||||||
|
entries = data.get("entries", {})
|
||||||
|
for entry in entries.values():
|
||||||
|
entry.setdefault("tags", [])
|
||||||
|
data["schema_version"] = 4
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
LATEST_VERSION = 4
|
||||||
|
|
||||||
|
|
||||||
def apply_migrations(data: dict) -> dict:
|
def apply_migrations(data: dict) -> dict:
|
||||||
|
@@ -22,7 +22,7 @@ def test_backup_restore_workflow(monkeypatch):
|
|||||||
index_file = fp_dir / "seedpass_entries_db.json.enc"
|
index_file = fp_dir / "seedpass_entries_db.json.enc"
|
||||||
|
|
||||||
data1 = {
|
data1 = {
|
||||||
"schema_version": 3,
|
"schema_version": 4,
|
||||||
"entries": {
|
"entries": {
|
||||||
"0": {
|
"0": {
|
||||||
"label": "a",
|
"label": "a",
|
||||||
@@ -32,6 +32,7 @@ def test_backup_restore_workflow(monkeypatch):
|
|||||||
"notes": "",
|
"notes": "",
|
||||||
"custom_fields": [],
|
"custom_fields": [],
|
||||||
"origin": "",
|
"origin": "",
|
||||||
|
"tags": [],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -46,7 +47,7 @@ def test_backup_restore_workflow(monkeypatch):
|
|||||||
assert backup1.stat().st_mode & 0o777 == 0o600
|
assert backup1.stat().st_mode & 0o777 == 0o600
|
||||||
|
|
||||||
data2 = {
|
data2 = {
|
||||||
"schema_version": 3,
|
"schema_version": 4,
|
||||||
"entries": {
|
"entries": {
|
||||||
"0": {
|
"0": {
|
||||||
"label": "b",
|
"label": "b",
|
||||||
@@ -56,6 +57,7 @@ def test_backup_restore_workflow(monkeypatch):
|
|||||||
"notes": "",
|
"notes": "",
|
||||||
"custom_fields": [],
|
"custom_fields": [],
|
||||||
"origin": "",
|
"origin": "",
|
||||||
|
"tags": [],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -69,11 +71,11 @@ def test_backup_restore_workflow(monkeypatch):
|
|||||||
if os.name != "nt":
|
if os.name != "nt":
|
||||||
assert backup2.stat().st_mode & 0o777 == 0o600
|
assert backup2.stat().st_mode & 0o777 == 0o600
|
||||||
|
|
||||||
vault.save_index({"schema_version": 3, "entries": {"temp": {}}})
|
vault.save_index({"schema_version": 4, "entries": {"temp": {}}})
|
||||||
backup_mgr.restore_latest_backup()
|
backup_mgr.restore_latest_backup()
|
||||||
assert vault.load_index()["entries"] == data2["entries"]
|
assert vault.load_index()["entries"] == data2["entries"]
|
||||||
|
|
||||||
vault.save_index({"schema_version": 3, "entries": {}})
|
vault.save_index({"schema_version": 4, "entries": {}})
|
||||||
backup_mgr.restore_backup_by_timestamp(1111)
|
backup_mgr.restore_backup_by_timestamp(1111)
|
||||||
assert vault.load_index()["entries"] == data1["entries"]
|
assert vault.load_index()["entries"] == data1["entries"]
|
||||||
|
|
||||||
@@ -91,7 +93,7 @@ def test_additional_backup_location(monkeypatch):
|
|||||||
cfg_mgr.set_additional_backup_path(extra)
|
cfg_mgr.set_additional_backup_path(extra)
|
||||||
backup_mgr = BackupManager(fp_dir, cfg_mgr)
|
backup_mgr = BackupManager(fp_dir, cfg_mgr)
|
||||||
|
|
||||||
vault.save_index({"schema_version": 3, "entries": {"a": {}}})
|
vault.save_index({"schema_version": 4, "entries": {"a": {}}})
|
||||||
|
|
||||||
monkeypatch.setattr(time, "time", lambda: 3333)
|
monkeypatch.setattr(time, "time", lambda: 3333)
|
||||||
backup_mgr.create_backup()
|
backup_mgr.create_backup()
|
||||||
|
@@ -31,7 +31,7 @@ def _setup_pm(tmp_path: Path):
|
|||||||
def test_cli_export_creates_file(monkeypatch, tmp_path):
|
def test_cli_export_creates_file(monkeypatch, tmp_path):
|
||||||
pm, vault = _setup_pm(tmp_path)
|
pm, vault = _setup_pm(tmp_path)
|
||||||
data = {
|
data = {
|
||||||
"schema_version": 3,
|
"schema_version": 4,
|
||||||
"entries": {
|
"entries": {
|
||||||
"0": {
|
"0": {
|
||||||
"label": "example",
|
"label": "example",
|
||||||
@@ -39,6 +39,7 @@ def test_cli_export_creates_file(monkeypatch, tmp_path):
|
|||||||
"notes": "",
|
"notes": "",
|
||||||
"custom_fields": [],
|
"custom_fields": [],
|
||||||
"origin": "",
|
"origin": "",
|
||||||
|
"tags": [],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -58,7 +59,7 @@ def test_cli_export_creates_file(monkeypatch, tmp_path):
|
|||||||
def test_cli_import_round_trip(monkeypatch, tmp_path):
|
def test_cli_import_round_trip(monkeypatch, tmp_path):
|
||||||
pm, vault = _setup_pm(tmp_path)
|
pm, vault = _setup_pm(tmp_path)
|
||||||
original = {
|
original = {
|
||||||
"schema_version": 3,
|
"schema_version": 4,
|
||||||
"entries": {
|
"entries": {
|
||||||
"0": {
|
"0": {
|
||||||
"label": "example",
|
"label": "example",
|
||||||
@@ -66,6 +67,7 @@ def test_cli_import_round_trip(monkeypatch, tmp_path):
|
|||||||
"notes": "",
|
"notes": "",
|
||||||
"custom_fields": [],
|
"custom_fields": [],
|
||||||
"origin": "",
|
"origin": "",
|
||||||
|
"tags": [],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -79,7 +81,7 @@ def test_cli_import_round_trip(monkeypatch, tmp_path):
|
|||||||
parent_seed=TEST_SEED,
|
parent_seed=TEST_SEED,
|
||||||
)
|
)
|
||||||
|
|
||||||
vault.save_index({"schema_version": 3, "entries": {}})
|
vault.save_index({"schema_version": 4, "entries": {}})
|
||||||
|
|
||||||
monkeypatch.setattr(main, "PasswordManager", lambda: pm)
|
monkeypatch.setattr(main, "PasswordManager", lambda: pm)
|
||||||
monkeypatch.setattr(main, "configure_logging", lambda: None)
|
monkeypatch.setattr(main, "configure_logging", lambda: None)
|
||||||
|
@@ -31,7 +31,7 @@ def test_index_export_import_round_trip():
|
|||||||
vault = setup_vault(tmp)
|
vault = setup_vault(tmp)
|
||||||
|
|
||||||
original = {
|
original = {
|
||||||
"schema_version": 3,
|
"schema_version": 4,
|
||||||
"entries": {
|
"entries": {
|
||||||
"0": {
|
"0": {
|
||||||
"label": "example",
|
"label": "example",
|
||||||
@@ -39,6 +39,7 @@ def test_index_export_import_round_trip():
|
|||||||
"notes": "",
|
"notes": "",
|
||||||
"custom_fields": [],
|
"custom_fields": [],
|
||||||
"origin": "",
|
"origin": "",
|
||||||
|
"tags": [],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -49,7 +50,7 @@ def test_index_export_import_round_trip():
|
|||||||
|
|
||||||
vault.save_index(
|
vault.save_index(
|
||||||
{
|
{
|
||||||
"schema_version": 3,
|
"schema_version": 4,
|
||||||
"entries": {
|
"entries": {
|
||||||
"0": {
|
"0": {
|
||||||
"label": "changed",
|
"label": "changed",
|
||||||
@@ -57,6 +58,7 @@ def test_index_export_import_round_trip():
|
|||||||
"notes": "",
|
"notes": "",
|
||||||
"custom_fields": [],
|
"custom_fields": [],
|
||||||
"origin": "",
|
"origin": "",
|
||||||
|
"tags": [],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@@ -13,7 +13,7 @@ def setup(tmp_path: Path):
|
|||||||
return enc_mgr, vault
|
return enc_mgr, vault
|
||||||
|
|
||||||
|
|
||||||
def test_migrate_v0_to_v3(tmp_path: Path):
|
def test_migrate_v0_to_v4(tmp_path: Path):
|
||||||
enc_mgr, vault = setup(tmp_path)
|
enc_mgr, vault = setup(tmp_path)
|
||||||
legacy = {"passwords": {"0": {"website": "a", "length": 8}}}
|
legacy = {"passwords": {"0": {"website": "a", "length": 8}}}
|
||||||
enc_mgr.save_json_data(legacy)
|
enc_mgr.save_json_data(legacy)
|
||||||
@@ -26,11 +26,12 @@ def test_migrate_v0_to_v3(tmp_path: Path):
|
|||||||
"notes": "",
|
"notes": "",
|
||||||
"custom_fields": [],
|
"custom_fields": [],
|
||||||
"origin": "",
|
"origin": "",
|
||||||
|
"tags": [],
|
||||||
}
|
}
|
||||||
assert data["entries"]["0"] == expected_entry
|
assert data["entries"]["0"] == expected_entry
|
||||||
|
|
||||||
|
|
||||||
def test_migrate_v1_to_v3(tmp_path: Path):
|
def test_migrate_v1_to_v4(tmp_path: Path):
|
||||||
enc_mgr, vault = setup(tmp_path)
|
enc_mgr, vault = setup(tmp_path)
|
||||||
legacy = {"schema_version": 1, "passwords": {"0": {"website": "b", "length": 10}}}
|
legacy = {"schema_version": 1, "passwords": {"0": {"website": "b", "length": 10}}}
|
||||||
enc_mgr.save_json_data(legacy)
|
enc_mgr.save_json_data(legacy)
|
||||||
@@ -43,11 +44,12 @@ def test_migrate_v1_to_v3(tmp_path: Path):
|
|||||||
"notes": "",
|
"notes": "",
|
||||||
"custom_fields": [],
|
"custom_fields": [],
|
||||||
"origin": "",
|
"origin": "",
|
||||||
|
"tags": [],
|
||||||
}
|
}
|
||||||
assert data["entries"]["0"] == expected_entry
|
assert data["entries"]["0"] == expected_entry
|
||||||
|
|
||||||
|
|
||||||
def test_migrate_v2_to_v3(tmp_path: Path):
|
def test_migrate_v2_to_v4(tmp_path: Path):
|
||||||
enc_mgr, vault = setup(tmp_path)
|
enc_mgr, vault = setup(tmp_path)
|
||||||
legacy = {
|
legacy = {
|
||||||
"schema_version": 2,
|
"schema_version": 2,
|
||||||
@@ -65,6 +67,7 @@ def test_migrate_v2_to_v3(tmp_path: Path):
|
|||||||
"notes": "",
|
"notes": "",
|
||||||
"custom_fields": [],
|
"custom_fields": [],
|
||||||
"origin": "",
|
"origin": "",
|
||||||
|
"tags": [],
|
||||||
}
|
}
|
||||||
assert data["entries"]["0"] == expected_entry
|
assert data["entries"]["0"] == expected_entry
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user