Add schema v3 migration and update tests

This commit is contained in:
thePR0M3TH3AN
2025-07-04 19:31:31 -04:00
parent b3ee860fd2
commit f2b6219dc0
4 changed files with 73 additions and 13 deletions

View File

@@ -13,17 +13,24 @@ def setup(tmp_path: Path):
return enc_mgr, vault
def test_migrate_v0_to_v2(tmp_path: Path):
def test_migrate_v0_to_v3(tmp_path: Path):
enc_mgr, vault = setup(tmp_path)
legacy = {"passwords": {"0": {"website": "a", "length": 8}}}
enc_mgr.save_json_data(legacy)
data = vault.load_index()
assert data["schema_version"] == LATEST_VERSION
expected_entry = {"website": "a", "length": 8, "type": "password", "notes": ""}
expected_entry = {
"website": "a",
"length": 8,
"type": "password",
"notes": "",
"custom_fields": [],
"origin": "",
}
assert data["entries"]["0"] == expected_entry
def test_migrate_v1_to_v2(tmp_path: Path):
def test_migrate_v1_to_v3(tmp_path: Path):
enc_mgr, vault = setup(tmp_path)
legacy = {"schema_version": 1, "passwords": {"0": {"website": "b", "length": 10}}}
enc_mgr.save_json_data(legacy)
@@ -34,6 +41,30 @@ def test_migrate_v1_to_v2(tmp_path: Path):
"length": 10,
"type": "password",
"notes": "",
"custom_fields": [],
"origin": "",
}
assert data["entries"]["0"] == expected_entry
def test_migrate_v2_to_v3(tmp_path: Path):
enc_mgr, vault = setup(tmp_path)
legacy = {
"schema_version": 2,
"entries": {
"0": {"website": "c", "length": 5, "type": "password", "notes": ""}
},
}
enc_mgr.save_json_data(legacy)
data = vault.load_index()
assert data["schema_version"] == LATEST_VERSION
expected_entry = {
"website": "c",
"length": 5,
"type": "password",
"notes": "",
"custom_fields": [],
"origin": "",
}
assert data["entries"]["0"] == expected_entry