Batch B6: deduplication (#36–#39) #59

Merged
amiryahaya merged 4 commits from fix/b6-dedup into main 2026-11-15 17:10:27 +01:00
Owner

Batch B6 — deduplication, #36–#39. Net 31 files, about -920 lines.

  • #36 MdidWs.MnesiaStore (use macro) replaces five hand-written DataStoreProtocol impls; each store is now configuration (table, struct, attributes, indexes, finders, optional sync: false, hooks before_save/dump/load/migrate). Legacy-schema migrations (oauth_client scopes, certificate_request issuance fields), index backfill and signing-key encryption are preserved.
  • #37 LeafIssuer + Pem shared by enrollment and renewal; test-only Renewal.process/2 and its 6 tests removed (same paths are covered through the standalone endpoints).
  • #38 one helper each for serial lookup (CertificateRequest.find_by_serial/1), PEM→DER b64, "valid" status, issuer filter, secret generation; the three cert base URLs share one default in config/config.exs (ocsp_base_url, issuer_aia_base_url, crl_base_url are fetch_env! now; prod runtime.exs already sets all three).
  • #39 scripts/lib/common.sh (token fetch, connection banner, --validity parsing, authenticated POST); client secret and bearer token go to curl over stdin, not argv; token format is validated before it is written to a curl config.

Small behaviour changes: {:by_id, id} works on every store (previously returned all rows on four of them); save(return_record: true) on oauth_client returns the default scopes; table-load wait is 15s and returns an error tuple; login_attempt no longer opens a schema transaction on every call; 07_full_workflow's token-failure message is no longer coloured.

Not done: SOAP check-then-retry ladders (enrollment/renewal classify differently) and XML escaping shared with scripts/10_soap_enroll.sh stay duplicated. #36–#39 otherwise addressed.

Verification: mix precommit 325 passed. Coverage: whole app 83.6% before the helper tests were added (MnesiaStore 100%, Status 96%, Revocation 94%; LeafIssuer/Pem/ClcData were 50–78% and now have direct tests, not re-measured). Scripts: bash -n, shellcheck, stub-curl and mock-server checks only; not run against a live API. Two-pass review: no must-fix/critical; findings applied (exact certificate_request schema match, banner helper, token guard, store tests). Not added: a direct certificate_request legacy-migration test (covered indirectly by 9 controller tests), tests asserting sync vs async.

🤖 Generated with Claude Code

Batch B6 — deduplication, #36–#39. Net 31 files, about -920 lines. - **#36** `MdidWs.MnesiaStore` (`use` macro) replaces five hand-written `DataStoreProtocol` impls; each store is now configuration (`table`, `struct`, `attributes`, `indexes`, `finders`, optional `sync: false`, hooks `before_save/dump/load/migrate`). Legacy-schema migrations (oauth_client scopes, certificate_request issuance fields), index backfill and signing-key encryption are preserved. - **#37** `LeafIssuer` + `Pem` shared by enrollment and renewal; test-only `Renewal.process/2` and its 6 tests removed (same paths are covered through the standalone endpoints). - **#38** one helper each for serial lookup (`CertificateRequest.find_by_serial/1`), PEM→DER b64, "valid" status, issuer filter, secret generation; the three cert base URLs share one default in `config/config.exs` (`ocsp_base_url`, `issuer_aia_base_url`, `crl_base_url` are `fetch_env!` now; prod runtime.exs already sets all three). - **#39** `scripts/lib/common.sh` (token fetch, connection banner, `--validity` parsing, authenticated POST); client secret and bearer token go to curl over stdin, not argv; token format is validated before it is written to a curl config. **Small behaviour changes**: `{:by_id, id}` works on every store (previously returned all rows on four of them); `save(return_record: true)` on oauth_client returns the default scopes; table-load wait is 15s and returns an error tuple; login_attempt no longer opens a schema transaction on every call; 07_full_workflow's token-failure message is no longer coloured. **Not done**: SOAP check-then-retry ladders (enrollment/renewal classify differently) and XML escaping shared with `scripts/10_soap_enroll.sh` stay duplicated. #36–#39 otherwise addressed. **Verification**: `mix precommit` 325 passed. Coverage: whole app 83.6% before the helper tests were added (MnesiaStore 100%, Status 96%, Revocation 94%; LeafIssuer/Pem/ClcData were 50–78% and now have direct tests, not re-measured). Scripts: `bash -n`, shellcheck, stub-curl and mock-server checks only; not run against a live API. Two-pass review: no must-fix/critical; findings applied (exact certificate_request schema match, banner helper, token guard, store tests). Not added: a direct certificate_request legacy-migration test (covered indirectly by 9 controller tests), tests asserting sync vs async. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
fix: B6 pass-1 review — token format guard, exact schema match, banner helper, store tests
All checks were successful
Lint / lint (pull_request) Successful in 1m57s
Security / Dependency advisories (mix hex.audit) (pull_request) Successful in 26s
Security / Secret scan (gitleaks) (pull_request) Successful in 11s
Unit tests / test (pull_request) Successful in 2m34s
d57d4dcf36
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign in to join this conversation.
No description provided.