Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable --no-input option by adding docs and tests #8182

Merged
merged 3 commits into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/7688.doc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add ``--no-input`` option to pip docs
2 changes: 1 addition & 1 deletion src/pip/_internal/cli/cmdoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
67 changes: 66 additions & 1 deletion tests/functional/test_install_config.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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
16 changes: 16 additions & 0 deletions tests/lib/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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