mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #8404 from francoisfreitag/test-ssl-broken
linkchecker: Remove dead code is_ssl_error()
This commit is contained in:
1
CHANGES
1
CHANGES
@@ -13,6 +13,7 @@ Incompatible changes
|
||||
Deprecated
|
||||
----------
|
||||
|
||||
* The ``is_ssl_error()`` function of ``sphinx.util.requests``
|
||||
* The ``follow_wrapped`` argument of ``sphinx.util.inspect.signature()``
|
||||
|
||||
Features added
|
||||
|
||||
@@ -27,6 +27,11 @@ The following is a list of deprecated interfaces.
|
||||
- Alternatives
|
||||
|
||||
|
||||
* - ``sphinx.util.requests.is_ssl_error()``
|
||||
- 3.4
|
||||
- 5.0
|
||||
- N/A
|
||||
|
||||
* - The ``follow_wrapped`` argument of ``sphinx.util.inspect.signature()``
|
||||
- 3.4
|
||||
- 5.0
|
||||
|
||||
@@ -28,7 +28,6 @@ from sphinx.locale import __
|
||||
from sphinx.util import encode_uri, logging, requests
|
||||
from sphinx.util.console import darkgray, darkgreen, purple, red, turquoise # type: ignore
|
||||
from sphinx.util.nodes import get_node_line
|
||||
from sphinx.util.requests import is_ssl_error
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -189,10 +188,7 @@ class CheckExternalLinksBuilder(Builder):
|
||||
else:
|
||||
return 'broken', str(err), 0
|
||||
except Exception as err:
|
||||
if is_ssl_error(err):
|
||||
return 'ignored', str(err), 0
|
||||
else:
|
||||
return 'broken', str(err), 0
|
||||
return 'broken', str(err), 0
|
||||
if response.url.rstrip('/') == req_url.rstrip('/'):
|
||||
return 'working', '', 0
|
||||
else:
|
||||
|
||||
@@ -18,6 +18,7 @@ import requests
|
||||
|
||||
import sphinx
|
||||
from sphinx.config import Config
|
||||
from sphinx.deprecation import RemovedInSphinx50Warning
|
||||
|
||||
try:
|
||||
from requests.packages.urllib3.exceptions import SSLError
|
||||
@@ -43,6 +44,10 @@ useragent_header = [('User-Agent',
|
||||
|
||||
def is_ssl_error(exc: Exception) -> bool:
|
||||
"""Check an exception is SSLError."""
|
||||
warnings.warn(
|
||||
"is_ssl_error() is outdated and likely returns incorrect results "
|
||||
"for modern versions of Requests.",
|
||||
RemovedInSphinx50Warning)
|
||||
if isinstance(exc, SSLError):
|
||||
return True
|
||||
else:
|
||||
|
||||
1
tests/roots/test-linkcheck-localserver-https/conf.py
Normal file
1
tests/roots/test-linkcheck-localserver-https/conf.py
Normal file
@@ -0,0 +1 @@
|
||||
exclude_patterns = ['_build']
|
||||
1
tests/roots/test-linkcheck-localserver-https/index.rst
Normal file
1
tests/roots/test-linkcheck-localserver-https/index.rst
Normal file
@@ -0,0 +1 @@
|
||||
`HTTPS server <https://localhost:7777/>`_
|
||||
@@ -269,3 +269,23 @@ def test_follows_redirects_on_GET(app, capsys):
|
||||
127.0.0.1 - - [] "GET /?redirected=1 HTTP/1.1" 204 -
|
||||
"""
|
||||
)
|
||||
|
||||
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver-https', freshenv=True)
|
||||
def test_invalid_ssl(app, status, warning):
|
||||
# Link indicates SSL should be used (https) but the server does not handle it.
|
||||
class OKHandler(http.server.BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
self.send_response(200, "OK")
|
||||
self.end_headers()
|
||||
self.wfile.write(b"ok\n")
|
||||
|
||||
with http_server(OKHandler):
|
||||
app.builder.build_all()
|
||||
|
||||
with open(app.outdir / 'output.json') as fp:
|
||||
content = json.load(fp)
|
||||
assert content["status"] == "broken"
|
||||
assert content["filename"] == "index.rst"
|
||||
assert content["lineno"] == 1
|
||||
assert content["uri"] == "https://localhost:7777/"
|
||||
assert "SSLError" in content["info"]
|
||||
|
||||
Reference in New Issue
Block a user