|
2 | 2 | import glob
|
3 | 3 | import os
|
4 | 4 | import shutil
|
| 5 | +import ssl |
5 | 6 | import sys
|
6 | 7 | import textwrap
|
7 | 8 | from os.path import curdir, join, pardir
|
|
30 | 31 | from tests.lib.filesystem import make_socket_file
|
31 | 32 | from tests.lib.local_repos import local_checkout
|
32 | 33 | 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 | +) |
33 | 40 |
|
34 | 41 | skip_if_python2 = pytest.mark.skipif(PY2, reason="Non-Python 2 only")
|
35 | 42 | 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):
|
1729 | 1736 | assert expected_warning in result.stderr, str(result)
|
1730 | 1737 | # Make sure a "yanked" release is installed
|
1731 | 1738 | 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