Skip to content

Commit d985479

Browse files
committed
Add failing test for missing client cert when using --trusted-host
1 parent 204a004 commit d985479

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/functional/test_install.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import glob
33
import os
44
import shutil
5+
import ssl
56
import sys
67
import textwrap
78
from os.path import curdir, join, pardir
@@ -30,6 +31,12 @@
3031
from tests.lib.filesystem import make_socket_file
3132
from tests.lib.local_repos import local_checkout
3233
from tests.lib.path import Path
34+
from tests.lib.server import (
35+
file_response,
36+
make_mock_server,
37+
package_page,
38+
server_running,
39+
)
3340

3441
skip_if_python2 = pytest.mark.skipif(PY2, reason="Non-Python 2 only")
3542
skip_if_not_python2 = pytest.mark.skipif(not PY2, reason="Python 2 only")
@@ -1729,3 +1736,39 @@ def test_install_yanked_file_and_print_warning(script, data):
17291736
assert expected_warning in result.stderr, str(result)
17301737
# Make sure a "yanked" release is installed
17311738
assert 'Successfully installed simple-3.0\n' in result.stdout, str(result)
1739+
1740+
1741+
@pytest.mark.parametrize("install_args", [
1742+
(),
1743+
("--trusted-host", "localhost"),
1744+
])
1745+
def test_install_sends_client_cert(install_args, script, cert_factory, data):
1746+
cert_path = cert_factory()
1747+
ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
1748+
ctx.load_cert_chain(cert_path, cert_path)
1749+
ctx.load_verify_locations(cafile=cert_path)
1750+
ctx.verify_mode = ssl.CERT_REQUIRED
1751+
1752+
server = make_mock_server(ssl_context=ctx)
1753+
server.mock.side_effect = [
1754+
package_page({
1755+
"simple-3.0.tar.gz": "/files/simple-3.0.tar.gz",
1756+
}),
1757+
file_response(str(data.packages / "simple-3.0.tar.gz")),
1758+
]
1759+
1760+
url = "https://{}:{}/simple".format(server.host, server.port)
1761+
1762+
args = ["install", "-vvv", "--cert", cert_path, "--client-cert", cert_path]
1763+
args.extend(["--index-url", url])
1764+
args.extend(install_args)
1765+
args.append("simple")
1766+
1767+
with server_running(server):
1768+
script.pip(*args)
1769+
1770+
assert server.mock.call_count == 2
1771+
for call_args in server.mock.call_args_list:
1772+
environ, _ = call_args.args
1773+
assert "SSL_CLIENT_CERT" in environ
1774+
assert environ["SSL_CLIENT_CERT"]

0 commit comments

Comments
 (0)