Merge pull request #8404 from francoisfreitag/test-ssl-broken

linkchecker: Remove dead code is_ssl_error()
This commit is contained in:
Takeshi KOMIYA
2020-11-14 18:54:16 +09:00
committed by GitHub
7 changed files with 34 additions and 5 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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:

View File

@@ -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:

View File

@@ -0,0 +1 @@
exclude_patterns = ['_build']

View File

@@ -0,0 +1 @@
`HTTPS server <https://localhost:7777/>`_

View File

@@ -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"]