refactor: dedupe CA download and client status code (CodeScene) #65

Merged
amiryahaya merged 3 commits from refactor/codescene-duplication into main 2026-11-15 20:31:19 +01:00
Owner

Small refactor from the CodeScene full audit. No behaviour change.

  • cert_management_controller.ex: download_ca_by_serial, download_root_ca and download_sub_ca share one send_ca_pem/3. Content type, filenames (mdid-root-ca.pem, mdid-sub-ca.pem, derived from the issuer type) and the three 404 messages are unchanged. CodeScene: 9.09 to 9.68.
  • client_credentials.ex: suspend_client and reactivate_client share a private set_status/2. CodeScene: 9.38 to 10.
  • AGENTS.md: a short CodeScene section (run code_health_review after changes; schemas.ex, router.ex and endpoint.ex cannot be scored).
  • Test added: unknown client reports not_found on suspend and reactivate.

Not changed: enrollment_response still has cyclomatic complexity 11 (controller stays at 9.68); api_spec.ex stays at 8.34.

Verification: mix precommit 330 passed; whole-app coverage 83.97% (ClientCredentials 90.16%, CertManagementController 87.00%). Two-pass review: Pass 1 found stale baseline numbers in the AGENTS.md note (removed); Pass 2 found no critical or important issues and suggested the not_found test (added). Not checked: the "Root CA not found" and "Sub CA not found" 404 messages are not pinned by any test (they are passed through unchanged).

🤖 Generated with Claude Code

Small refactor from the CodeScene full audit. No behaviour change. - `cert_management_controller.ex`: `download_ca_by_serial`, `download_root_ca` and `download_sub_ca` share one `send_ca_pem/3`. Content type, filenames (`mdid-root-ca.pem`, `mdid-sub-ca.pem`, derived from the issuer type) and the three 404 messages are unchanged. CodeScene: 9.09 to 9.68. - `client_credentials.ex`: `suspend_client` and `reactivate_client` share a private `set_status/2`. CodeScene: 9.38 to 10. - `AGENTS.md`: a short CodeScene section (run `code_health_review` after changes; `schemas.ex`, `router.ex` and `endpoint.ex` cannot be scored). - Test added: unknown client reports `not_found` on suspend and reactivate. Not changed: `enrollment_response` still has cyclomatic complexity 11 (controller stays at 9.68); `api_spec.ex` stays at 8.34. Verification: `mix precommit` 330 passed; whole-app coverage 83.97% (ClientCredentials 90.16%, CertManagementController 87.00%). Two-pass review: Pass 1 found stale baseline numbers in the AGENTS.md note (removed); Pass 2 found no critical or important issues and suggested the not_found test (added). Not checked: the "Root CA not found" and "Sub CA not found" 404 messages are not pinned by any test (they are passed through unchanged). 🤖 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>
test: unknown client reports not_found on suspend and reactivate
All checks were successful
Lint / lint (pull_request) Successful in 1m40s
Security / Dependency advisories (mix hex.audit) (pull_request) Successful in 18s
Security / Secret scan (gitleaks) (pull_request) Successful in 11s
Unit tests / test (pull_request) Successful in 2m33s
9a6aa24b49
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign in to join this conversation.
No description provided.