check_apt_key: reject extra pub without fpr, secret keys, option injection, and unnormalized expected (CHECK-APT-KEY-PARSING-AND-GUARDS) #1610

Merged
leonida/mandy
quietfold merged 1 commit from fix/check-apt-key-parsing-and-guards into main 2026-11-28 10:37:19 +00:00

Pull request successfully merged and closed

quietfold commented 2026-11-25 05:51:09 +00:00

Item ID: CHECK-APT-KEY-PARSING-AND-GUARDS (unlisted; coordination issue #14 is at GitHub's 2,500-comment cap with no open successor at submission time, and no open PR touches scripts/check_apt_key.py).

What changed

  • Count primary pub keys even when they lack an fpr record (scripts/check_apt_key.py, primary_fingerprints): previously a pub record followed by another pub, sub/ssb/sec, or EOF without an fpr line was silently dropped, so appending an extra pub record without fpr after the pinned key passed check(). Now every pub record without a matching fpr appends "" (rendered as <missing> in diagnostics), causing check() to fail.
  • Reject secret key records (sec / ssb) in check(): previously a sec record appended after the pinned pub key was ignored and passed check(). Key files handed to apt must contain public key material only.
  • Pass -- end-of-options before path in show_keys(): prevents a key file path starting with - from being interpreted as a gpg option.
  • Normalize and validate expected inside check() and guard non-strings in normalize(): direct callers passing lowercase/spaced fingerprints now match, invalid/empty expected values are refused before invoking gpg, and normalize(None) returns None instead of raising TypeError.
  • Support -h / --help and default argv=None in main().
  • Synthetic regression tests (tests/test_check_apt_key.py): 6 new tests plus expanded test_normalize covering all of the above (no game files, no GPU, no real gpg required).

Verification

  • AI-assisted: yes
  • GPUs tested: none (CPU-only Python script on macOS)
  • python3 -W error -I tests/test_check_apt_key.py -v: 19 passed
  • python3 -W error -I tests/test_text_write_line_endings.py: passed
  • python3 -I scripts/check_no_game_data.py scripts/check_apt_key.py tests/test_check_apt_key.py: clean
  • python3 -m compileall -q scripts/check_apt_key.py tests/test_check_apt_key.py: clean
  • Mutation test (tests/test_check_apt_key.py against unpatched main:scripts/check_apt_key.py): 7 failures, 1 error across the 19 tests (all new tests fail on unpatched main).
Item ID: `CHECK-APT-KEY-PARSING-AND-GUARDS` (unlisted; coordination issue #14 is at GitHub's 2,500-comment cap with no open successor at submission time, and no open PR touches `scripts/check_apt_key.py`). ## What changed - **Count primary `pub` keys even when they lack an `fpr` record (`scripts/check_apt_key.py`, `primary_fingerprints`)**: previously a `pub` record followed by another `pub`, `sub`/`ssb`/`sec`, or EOF without an `fpr` line was silently dropped, so appending an extra `pub` record without `fpr` after the pinned key passed `check()`. Now every `pub` record without a matching `fpr` appends `""` (rendered as `<missing>` in diagnostics), causing `check()` to fail. - **Reject secret key records (`sec` / `ssb`) in `check()`**: previously a `sec` record appended after the pinned `pub` key was ignored and passed `check()`. Key files handed to `apt` must contain public key material only. - **Pass `--` end-of-options before `path` in `show_keys()`**: prevents a key file path starting with `-` from being interpreted as a `gpg` option. - **Normalize and validate `expected` inside `check()` and guard non-strings in `normalize()`**: direct callers passing lowercase/spaced fingerprints now match, invalid/empty `expected` values are refused before invoking `gpg`, and `normalize(None)` returns `None` instead of raising `TypeError`. - **Support `-h` / `--help` and default `argv=None` in `main()`**. - **Synthetic regression tests (`tests/test_check_apt_key.py`)**: 6 new tests plus expanded `test_normalize` covering all of the above (no game files, no GPU, no real `gpg` required). ## Verification - AI-assisted: yes - GPUs tested: none (CPU-only Python script on macOS) - `python3 -W error -I tests/test_check_apt_key.py -v`: **19 passed** - `python3 -W error -I tests/test_text_write_line_endings.py`: passed - `python3 -I scripts/check_no_game_data.py scripts/check_apt_key.py tests/test_check_apt_key.py`: clean - `python3 -m compileall -q scripts/check_apt_key.py tests/test_check_apt_key.py`: clean - Mutation test (`tests/test_check_apt_key.py` against unpatched `main:scripts/check_apt_key.py`): **7 failures, 1 error** across the 19 tests (all new tests fail on unpatched `main`).
copilot-pull-request-reviewer[bot] reviewed 2026-11-25 05:51:20 +00:00
copilot-pull-request-reviewer[bot] left a comment
No description provided.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
MoonEyes commented 2026-11-28 10:37:09 +00:00

Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18).
Targeted batch of 18 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13.
AI-assisted (Claude Code, Claude Opus 5.5)

Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18). Targeted batch of 18 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13. AI-assisted (Claude Code, Claude Opus 5.5)
Sign in to join this conversation.
No description provided.