Skip to content

Add tests for PEM and Traefik header DN extraction#12

Open
karlnewell wants to merge 2 commits intoworkfloworchestrator:mainfrom
karlnewell:feat/traefik-tests
Open

Add tests for PEM and Traefik header DN extraction#12
karlnewell wants to merge 2 commits intoworkfloworchestrator:mainfrom
karlnewell:feat/traefik-tests

Conversation

@karlnewell
Copy link
Copy Markdown
Contributor

Fixes an issue where the remote client sends a cert chain. Makes headers configurable. Adds unit and functional tests.

  • Add session-scoped cert fixtures to conftest.py using cryptography to generate real self-signed certs (no mocking)
  • Add unit tests for _escape_dn_value, extract_dn_from_traefik_header, and extract_dn_from_pem_header including cert chain handling
  • Add functional tests for PEM and Info header allow/deny, priority ordering, and PEM parse failure fallback to Info header
  • Fix unquote_plus usage in extract_dn_from_pem_header (was unquote); Traefik's url.QueryEscape encodes spaces as '+' and base64 '+' as '%2B', so unquote_plus correctly reverses both

- Add session-scoped cert fixtures to conftest.py using cryptography
  to generate real self-signed certs (no mocking)
- Add unit tests for _escape_dn_value, extract_dn_from_traefik_header,
  and extract_dn_from_pem_header including cert chain handling
- Add functional tests for PEM and Info header allow/deny, priority
  ordering, and PEM parse failure fallback to Info header
- Fix unquote_plus usage in extract_dn_from_pem_header (was unquote);
  Traefik's url.QueryEscape encodes spaces as '+' and base64 '+' as
  '%2B', so unquote_plus correctly reverses both
Traefik sends X-Forwarded-Tls-Client-Cert as raw base64-encoded DER
with no PEM markers, no URL-encoding, and the full cert chain
concatenated without separators.

- Add _first_der_cert() to extract the leaf cert from concatenated DER
  bytes by parsing the ASN.1 SEQUENCE length header
- Use unquote (not unquote_plus) to preserve literal '+' in base64
- Fall through to raw base64 path when no PEM markers are present
- Update test fixture to match actual Traefik format (raw DER base64)
- Update cert chain test to use concatenated DER base64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant