diff --git a/tests/test_builders/test_build_linkcheck.py b/tests/test_builders/test_build_linkcheck.py index d85438491f8..b04d6241685 100644 --- a/tests/test_builders/test_build_linkcheck.py +++ b/tests/test_builders/test_build_linkcheck.py @@ -966,7 +966,7 @@ def test_TooManyRedirects_on_HEAD(app, monkeypatch): @pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver') -def test_ignore_redirection(app): +def test_ignore_local_redirection(app): with serve_application(app, InfiniteRedirectOnHeadHandler) as address: app.config.linkcheck_ignore = [f'http://{address}/redirected'] app.build() @@ -983,6 +983,37 @@ def test_ignore_redirection(app): } +class RemoteDomainRedirectHandler(InfiniteRedirectOnHeadHandler): + protocol_version = 'HTTP/1.1' + + def do_GET(self): + self.send_response(301, 'Found') + if self.path == '/': + self.send_header('Location', '/local') + elif self.path == '/local': + self.send_header('Location', 'http://example.test/migrated') + self.send_header('Content-Length', '0') + self.end_headers() + + +@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver') +def test_ignore_remote_redirection(app): + with serve_application(app, RemoteDomainRedirectHandler) as address: + app.config.linkcheck_ignore = [f'http://example.test'] + app.build() + + with open(app.outdir / 'output.json', encoding='utf-8') as fp: + content = json.load(fp) + assert content == { + 'code': 301, + 'status': 'ignored', + 'filename': 'index.rst', + 'lineno': 1, + 'uri': f'http://{address}/', + 'info': f'ignored redirect: http://example.test/migrated', + } + + def make_retry_after_handler( responses: list[tuple[int, str | None]], ) -> type[BaseHTTPRequestHandler]: