|
1 | 1 | import os
|
| 2 | +import ssl |
2 | 3 | import tempfile
|
3 | 4 | import textwrap
|
4 | 5 |
|
5 | 6 | import pytest
|
6 | 7 |
|
7 |
| -from tests.lib.server import file_response, package_page |
| 8 | +from tests.lib.server import ( |
| 9 | + authorization_response, |
| 10 | + file_response, |
| 11 | + make_mock_server, |
| 12 | + package_page, |
| 13 | + server_running, |
| 14 | +) |
8 | 15 |
|
9 | 16 |
|
10 | 17 | def test_options_from_env_vars(script):
|
@@ -209,3 +216,61 @@ def test_install_no_binary_via_config_disables_cached_wheels(
|
209 | 216 | assert "Building wheel for upper" not in str(res), str(res)
|
210 | 217 | # Must have used source, not a cached wheel to install upper.
|
211 | 218 | assert "Running setup.py install for upper" in str(res), str(res)
|
| 219 | + |
| 220 | + |
| 221 | +def test_prompt_for_authentication(script, data, cert_factory): |
| 222 | + """Test behaviour while installing from a index url |
| 223 | + requiring authentication |
| 224 | + """ |
| 225 | + cert_path = cert_factory() |
| 226 | + ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23) |
| 227 | + ctx.load_cert_chain(cert_path, cert_path) |
| 228 | + ctx.load_verify_locations(cafile=cert_path) |
| 229 | + ctx.verify_mode = ssl.CERT_REQUIRED |
| 230 | + |
| 231 | + server = make_mock_server(ssl_context=ctx) |
| 232 | + server.mock.side_effect = [ |
| 233 | + package_page({ |
| 234 | + "simple-3.0.tar.gz": "/files/simple-3.0.tar.gz", |
| 235 | + }), |
| 236 | + authorization_response(str(data.packages / "simple-3.0.tar.gz")), |
| 237 | + ] |
| 238 | + |
| 239 | + url = "https://{}:{}/simple".format(server.host, server.port) |
| 240 | + |
| 241 | + with server_running(server): |
| 242 | + result = script.pip('install', "--index-url", url, |
| 243 | + "--cert", cert_path, "--client-cert", cert_path, |
| 244 | + 'simple', expect_error=True) |
| 245 | + |
| 246 | + assert 'User for {}:{}'.format(server.host, server.port) in \ |
| 247 | + result.stdout, str(result) |
| 248 | + |
| 249 | + |
| 250 | +def test_do_not_prompt_for_authentication(script, data, cert_factory): |
| 251 | + """Test behaviour if --no-input option is given while installing |
| 252 | + from a index url requiring authentication |
| 253 | + """ |
| 254 | + cert_path = cert_factory() |
| 255 | + ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23) |
| 256 | + ctx.load_cert_chain(cert_path, cert_path) |
| 257 | + ctx.load_verify_locations(cafile=cert_path) |
| 258 | + ctx.verify_mode = ssl.CERT_REQUIRED |
| 259 | + |
| 260 | + server = make_mock_server(ssl_context=ctx) |
| 261 | + |
| 262 | + server.mock.side_effect = [ |
| 263 | + package_page({ |
| 264 | + "simple-3.0.tar.gz": "/files/simple-3.0.tar.gz", |
| 265 | + }), |
| 266 | + authorization_response(str(data.packages / "simple-3.0.tar.gz")), |
| 267 | + ] |
| 268 | + |
| 269 | + url = "https://{}:{}/simple".format(server.host, server.port) |
| 270 | + |
| 271 | + with server_running(server): |
| 272 | + result = script.pip('install', "--index-url", url, |
| 273 | + "--cert", cert_path, "--client-cert", cert_path, |
| 274 | + '--no-input', 'simple', expect_error=True) |
| 275 | + |
| 276 | + assert "ERROR: HTTP error 401" in result.stderr |
0 commit comments