A python3 kivy epassport viewer. You can read and dump a passport using BAC or CAN. There is also a screen OCR to read MZR if you like. Every dump gets its own folder. You can generate a set of sample dump folders. This project is just a fun test of what Claude can do. Hack all things!
This commit is contained in:
1 parent
08795e9073
commit
cb2b0f5fc0
102 files changed
+12882
-1
No files matched your search
@@ -0,0 +1,63 @@
|
||||
"""Settings persistence, and the promise that BAC data is not kept by default."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from epassport.config import Settings, new_dump_dir
|
||||
|
||||
|
||||
def test_defaults_do_not_remember_credentials() -> None:
|
||||
settings = Settings()
|
||||
assert settings.remember_bac is False
|
||||
assert settings.last_document_number == ""
|
||||
|
||||
|
||||
def test_saving_without_remember_strips_the_bac_fields(tmp_path: Path) -> None:
|
||||
path = tmp_path / "settings.json"
|
||||
settings = Settings(
|
||||
last_document_number="L898902C3",
|
||||
last_date_of_birth="740812",
|
||||
last_date_of_expiry="120415",
|
||||
remember_bac=False,
|
||||
)
|
||||
settings.save(path)
|
||||
raw = json.loads(path.read_text())
|
||||
assert raw["last_document_number"] == ""
|
||||
assert raw["last_date_of_birth"] == ""
|
||||
assert raw["last_date_of_expiry"] == ""
|
||||
|
||||
|
||||
def test_saving_with_remember_keeps_them(tmp_path: Path) -> None:
|
||||
path = tmp_path / "settings.json"
|
||||
Settings(last_document_number="L898902C3", remember_bac=True).save(path)
|
||||
assert json.loads(path.read_text())["last_document_number"] == "L898902C3"
|
||||
assert Settings.load(path).last_document_number == "L898902C3"
|
||||
|
||||
|
||||
def test_settings_file_is_owner_only(tmp_path: Path) -> None:
|
||||
path = tmp_path / "settings.json"
|
||||
Settings().save(path)
|
||||
assert path.stat().st_mode & 0o077 == 0
|
||||
|
||||
|
||||
def test_corrupt_settings_file_falls_back_to_defaults(tmp_path: Path) -> None:
|
||||
path = tmp_path / "settings.json"
|
||||
path.write_text("{ this is not json")
|
||||
assert Settings.load(path).timeout_seconds == 120.0
|
||||
|
||||
|
||||
def test_unknown_keys_are_ignored(tmp_path: Path) -> None:
|
||||
path = tmp_path / "settings.json"
|
||||
path.write_text(json.dumps({"camera_index": 2, "from_the_future": True}))
|
||||
assert Settings.load(path).camera_index == 2
|
||||
|
||||
|
||||
def test_dump_dirs_are_unique_and_owner_only(monkeypatch, tmp_path: Path) -> None:
|
||||
monkeypatch.setenv("XDG_DATA_HOME", str(tmp_path))
|
||||
first = new_dump_dir()
|
||||
second = new_dump_dir()
|
||||
assert first != second
|
||||
assert first.stat().st_mode & 0o077 == 0
|
||||
assert first.parent.stat().st_mode & 0o077 == 0
|
||||
Reference in new issue
Block a user