diff --git a/news/7688.doc b/news/7688.doc new file mode 100644 index 00000000000..e891c7e8c29 --- /dev/null +++ b/news/7688.doc @@ -0,0 +1 @@ +Add ``--no-input`` option to pip docs diff --git a/src/pip/_internal/cli/cmdoptions.py b/src/pip/_internal/cli/cmdoptions.py index 4c557efa80f..643b11280e3 100644 --- a/src/pip/_internal/cli/cmdoptions.py +++ b/src/pip/_internal/cli/cmdoptions.py @@ -243,7 +243,7 @@ class PipOption(Option): dest='no_input', action='store_true', default=False, - help=SUPPRESS_HELP + help="Disable prompting for input." ) # type: Callable[..., Option] proxy = partial( diff --git a/tests/functional/test_install_config.py b/tests/functional/test_install_config.py index 6cd283f077f..dcc9c66d5a4 100644 --- a/tests/functional/test_install_config.py +++ b/tests/functional/test_install_config.py @@ -1,10 +1,17 @@ import os +import ssl import tempfile import textwrap import pytest -from tests.lib.server import file_response, package_page +from tests.lib.server import ( + authorization_response, + file_response, + make_mock_server, + package_page, + server_running, +) def test_options_from_env_vars(script): @@ -209,3 +216,61 @@ def test_install_no_binary_via_config_disables_cached_wheels( assert "Building wheel for upper" not in str(res), str(res) # Must have used source, not a cached wheel to install upper. assert "Running setup.py install for upper" in str(res), str(res) + + +def test_prompt_for_authentication(script, data, cert_factory): + """Test behaviour while installing from a index url + requiring authentication + """ + cert_path = cert_factory() + ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23) + ctx.load_cert_chain(cert_path, cert_path) + ctx.load_verify_locations(cafile=cert_path) + ctx.verify_mode = ssl.CERT_REQUIRED + + server = make_mock_server(ssl_context=ctx) + server.mock.side_effect = [ + package_page({ + "simple-3.0.tar.gz": "/files/simple-3.0.tar.gz", + }), + authorization_response(str(data.packages / "simple-3.0.tar.gz")), + ] + + url = "https://{}:{}/simple".format(server.host, server.port) + + with server_running(server): + result = script.pip('install', "--index-url", url, + "--cert", cert_path, "--client-cert", cert_path, + 'simple', expect_error=True) + + assert 'User for {}:{}'.format(server.host, server.port) in \ + result.stdout, str(result) + + +def test_do_not_prompt_for_authentication(script, data, cert_factory): + """Test behaviour if --no-input option is given while installing + from a index url requiring authentication + """ + cert_path = cert_factory() + ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23) + ctx.load_cert_chain(cert_path, cert_path) + ctx.load_verify_locations(cafile=cert_path) + ctx.verify_mode = ssl.CERT_REQUIRED + + server = make_mock_server(ssl_context=ctx) + + server.mock.side_effect = [ + package_page({ + "simple-3.0.tar.gz": "/files/simple-3.0.tar.gz", + }), + authorization_response(str(data.packages / "simple-3.0.tar.gz")), + ] + + url = "https://{}:{}/simple".format(server.host, server.port) + + with server_running(server): + result = script.pip('install', "--index-url", url, + "--cert", cert_path, "--client-cert", cert_path, + '--no-input', 'simple', expect_error=True) + + assert "ERROR: HTTP error 401" in result.stderr diff --git a/tests/lib/server.py b/tests/lib/server.py index bb423a2d867..6cf891d0d5d 100644 --- a/tests/lib/server.py +++ b/tests/lib/server.py @@ -210,3 +210,19 @@ def responder(environ, start_response): return [f.read()] return responder + + +def authorization_response(path): + def responder(environ, start_response): + # type: (Environ, StartResponse) -> Body + + start_response( + "401 Unauthorized", [ + ("WWW-Authenticate", "Basic"), + ], + ) + + with open(path, 'rb') as f: + return [f.read()] + + return responder