Skip to content

fix(tests): allow real DNS passthrough for external IdP integration tests - #6797

Open
jonpspri wants to merge 1 commit into
mainfrom
fix/entra-test-dns-passthrough
Open

fix(tests): allow real DNS passthrough for external IdP integration tests#6797
jonpspri wants to merge 1 commit into
mainfrom
fix/entra-test-dns-passthrough

Conversation

@jonpspri

Copy link
Copy Markdown
Collaborator

Problem

tests/conftest.py installs a session-scoped autouse _deterministic_dns fixture that resolves every non-localhost hostname to a hardcoded example.com address (93.184.215.14). Any test that makes a real HTTPS call to an external IdP from under tests/ therefore connects to a black-holed IP and fails with httpx.ConnectTimeout.

This makes the Entra ID E2E suite (tests/integration/test_entra_id_integration.py) unrunnable as shipped: with Azure credentials configured, 11 of 15 tests error in fixture setup (Graph API + ROPC egress) and only the purely local claim-forgery tests pass.

Fix

  • TESTS_DNS_PASSTHROUGH_HOSTS — opt-in, comma-separated hostnames resolved via real DNS while the stub stays active for everything else. The hermetic default is unchanged (verified: without the variable, external names still resolve to the stub address).
  • Bytes-host normalization — httpx resolves through anyio.getaddrinfo, which IDNA-encodes hostnames to bytes before calling socket.getaddrinfo. The previous string-only comparison never matched on that path, so even a correctly configured passthrough (or localhost) entry was ignored for httpx traffic. The stub now decodes bytes/bytearray hosts before matching.
  • Docsdocs/docs/testing/entra-id-e2e.md gains the new variable in its environment reference and export example, plus the --with-integration flag that the run command was missing (the suite silently skips without it).

Verification

Against a live Entra tenant with User.ReadWrite.All/Group.ReadWrite.All application permissions:

TESTS_DNS_PASSTHROUGH_HOSTS=login.microsoftonline.com,graph.microsoft.com \
  pytest tests/integration/test_entra_id_integration.py -v --with-integration
→ 15 passed

Without TESTS_DNS_PASSTHROUGH_HOSTS, resolution stays stubbed and the suite behaves exactly as before this change.

.secrets.baseline carries only line-number drift (390→395, 391→396) from the conftest insertion, regenerated by the pre-commit hook.

This PR is deliberately not part of the JWT-trust stack; the stack will be rebased onto this branch so the trust-mode work inherits a runnable Entra E2E baseline.

…ests

The session-scoped _deterministic_dns stub in tests/conftest.py resolves
every non-localhost hostname to a hardcoded example.com address, which
blackholes all Microsoft Graph / Entra ID egress from the in-process
integration suite (tests/integration/test_entra_id_integration.py):
every network-dependent test fails with httpx.ConnectTimeout, so the
suite cannot pass under tests/ as shipped.

- Add opt-in TESTS_DNS_PASSTHROUGH_HOSTS: comma-separated hosts resolved
  via real DNS while the stub stays active. Hermetic default unchanged.
- Normalize IDNA-encoded bytes hostnames before matching: httpx/anyio
  resolve through anyio.getaddrinfo, which encodes hostnames to bytes;
  the previous string-only comparison never matched passthrough (or
  localhost) entries on that path.
- Document TESTS_DNS_PASSTHROUGH_HOSTS and the required
  --with-integration flag in docs/docs/testing/entra-id-e2e.md.

Verified with a live tenant: the Entra ID E2E suite passes 15/15 with
the variables set; without them, DNS remains stubbed and the suite
self-skips as before.

Signed-off-by: Jonathan Springer <jps@s390x.com>
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