Skip to content

Skip urllib3 SSRF redirect tests when urllib3 is not installed#1682

Merged
brendancol merged 2 commits into
mainfrom
issue-1681
May 12, 2026
Merged

Skip urllib3 SSRF redirect tests when urllib3 is not installed#1682
brendancol merged 2 commits into
mainfrom
issue-1681

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Closes #1681.

Summary

TestRedirectRevalidation in xrspatial/geotiff/tests/test_ssrf_hardening_1664.py exercises the urllib3 transport path: each test mocks urllib3.PoolManager and calls src.read_range(...), which internally builds a urllib3.Timeout via _urllib3_timeout() (a lazy import urllib3). urllib3 is an optional runtime dep (_HTTPSource falls back to stdlib urllib.request when it's missing), but the test class did not gate on its presence.

In CI environments without urllib3, the four test_urllib3_* tests fail with ModuleNotFoundError. Main has been red on this since commit 919d827 (#1668); every PR branched from main hits the same wall (PRs #1675-#1680).

This adds an autouse pytest.importorskip("urllib3") fixture to the class so urllib3-specific tests skip cleanly when the package is absent. The three test_stdlib_* tests in the same class are unaffected.

Test plan

  • Local run with urllib3 installed: 7 passed (4 urllib3 + 3 stdlib).
  • CI run without urllib3: 4 skipped, 3 passed.
  • No other tests touched.

TestRedirectRevalidation mocks urllib3.PoolManager and exercises
read_range, which internally calls _urllib3_timeout() and tries to
import urllib3 lazily. urllib3 is an optional runtime dependency
(_HTTPSource falls back to stdlib urllib.request when it's missing),
but the test class did not gate on its presence, so CI without
urllib3 saw four ModuleNotFoundError failures.

Add an autouse pytest.importorskip("urllib3") fixture on the class
so the urllib3-specific tests skip cleanly when the package is
absent. The stdlib redirect-handler tests in the same class remain
untouched.
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label May 12, 2026
The autouse fixture on TestRedirectRevalidation also skipped the
three test_stdlib_* tests in the same class, which exercise the
stdlib redirect handler directly and must run regardless of whether
urllib3 is installed. Move the gate into each of the four urllib3
test methods individually so the stdlib tests stay live.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes CI failures in the GeoTIFF SSRF-hardening test suite by ensuring urllib3-specific redirect revalidation tests are skipped when urllib3 (an optional dependency) is not installed.

Changes:

  • Add pytest.importorskip("urllib3") guards to each test_urllib3_* redirect revalidation test.
  • Add an explanatory comment clarifying the separation between urllib3-transport tests vs stdlib-transport tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +270 to +276
# The test_urllib3_* tests exercise the urllib3 transport path: they mock
# urllib3.PoolManager and call read_range(), which internally builds a
# urllib3.Timeout via _urllib3_timeout(). urllib3 is an optional runtime
# dependency (_HTTPSource falls back to stdlib urllib.request when it's
# missing -- see _reader.py:615-617), so each urllib3-using test starts
# with pytest.importorskip("urllib3"). The test_stdlib_* tests below
# exercise the stdlib redirect handler directly and run regardless.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I tried that first — an @pytest.fixture(autouse=True) pytest.importorskip("urllib3") at the class level. The trade-off is that an autouse fixture also fires for the three test_stdlib_* methods in the same class (the stdlib redirect handler tests that don't go through _urllib3_timeout), and those should keep running on machines without urllib3 installed.

A separate class-with-autouse-fixture for just the urllib3 subset would work but it requires moving four methods out, which felt heavier than inlining the four calls. I left a class-level comment to nudge future urllib3-path tests toward the same gate.

@brendancol brendancol merged commit ef32bd7 into main May 12, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TestRedirectRevalidation urllib3 tests fail when urllib3 is not installed

2 participants