From e168b845a482468aad0d548140111e2d20a56177 Mon Sep 17 00:00:00 2001 From: Xavier Fernandez Date: Mon, 3 Aug 2015 22:21:02 +0200 Subject: [PATCH] Allow --trusted-host option in requirement files closes #2822 --- CHANGES.txt | 2 ++ pip/req/req_file.py | 4 ++++ tests/unit/test_req_file.py | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 124aafb9c4d..21e4051d23f 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -14,6 +14,8 @@ changes made to the repository protocol made in PEP 470, these options are no longer functional. +* Allow ``--trusted-host`` within a requirements file. :issue:`2822`. + **7.1.2 (2015-08-22)** diff --git a/pip/req/req_file.py b/pip/req/req_file.py index 283834c3645..8ff87c019fc 100644 --- a/pip/req/req_file.py +++ b/pip/req/req_file.py @@ -43,6 +43,7 @@ cmdoptions.always_unzip, cmdoptions.no_binary, cmdoptions.only_binary, + cmdoptions.trusted_host, ] # options to be passed to requirements @@ -218,6 +219,9 @@ def process_line(line, filename, line_number, finder=None, comes_from=None, if os.path.exists(relative_to_reqs_file): value = relative_to_reqs_file finder.find_links.append(value) + if opts.trusted_hosts: + finder.secure_origins.extend( + ("*", host, "*") for host in opts.trusted_hosts) def break_args_options(line): diff --git a/tests/unit/test_req_file.py b/tests/unit/test_req_file.py index 8c9ce43729a..20bee85869f 100644 --- a/tests/unit/test_req_file.py +++ b/tests/unit/test_req_file.py @@ -202,6 +202,10 @@ def test_set_finder_no_use_wheel(self, finder): no_use_wheel_fmt = pip.index.FormatControl(set([':all:']), set()) assert finder.format_control == no_use_wheel_fmt + def test_set_finder_trusted_host(self, finder): + list(process_line("--trusted-host=url", "file", 1, finder=finder)) + assert finder.secure_origins == [('*', 'url', '*')] + def test_noop_always_unzip(self, finder): # noop, but confirm it can be set list(process_line("--always-unzip", "file", 1, finder=finder))