-
-
Notifications
You must be signed in to change notification settings - Fork 615
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix leaked URLs with credentials in the output (#1146)
- Loading branch information
Showing
5 changed files
with
99 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,7 +107,7 @@ def test_find_links_option(runner): | |
out = runner.invoke(cli, ["-v", "-f", "./libs1", "-f", "./libs2"]) | ||
|
||
# Check that find-links has been passed to pip | ||
assert "Configuration:\n -f ./libs1\n -f ./libs2\n -f ./libs3\n" in out.stderr | ||
assert "Using links:\n ./libs1\n ./libs2\n ./libs3\n" in out.stderr | ||
|
||
# Check that find-links has been written to a requirements.txt | ||
with open("requirements.txt", "r") as req_txt: | ||
|
@@ -143,6 +143,30 @@ def test_extra_index_option(pip_with_index_conf, runner): | |
) | ||
|
||
|
||
@pytest.mark.parametrize("option", ("--extra-index-url", "--find-links")) | ||
def test_redacted_urls_in_verbose_output(runner, option): | ||
""" | ||
Test that URLs with sensitive data don't leak to the output. | ||
""" | ||
with open("requirements.in", "w"): | ||
pass | ||
|
||
out = runner.invoke( | ||
cli, | ||
[ | ||
"--no-header", | ||
"--no-index", | ||
"--no-emit-find-links", | ||
"--verbose", | ||
option, | ||
"http://username:[email protected]", | ||
], | ||
) | ||
|
||
assert "http://username:****@example.com" in out.stderr | ||
assert "password" not in out.stderr | ||
|
||
|
||
def test_trusted_host(pip_conf, runner): | ||
with open("requirements.in", "w"): | ||
pass | ||
|
@@ -658,21 +682,37 @@ def test_no_candidates_pre(pip_conf, runner): | |
assert "Tried pre-versions:" in out.stderr | ||
|
||
|
||
def test_default_index_url(pip_with_index_conf): | ||
@pytest.mark.parametrize( | ||
("url", "expected_url"), | ||
( | ||
pytest.param("https://example.com", "https://example.com", id="regular url"), | ||
pytest.param( | ||
"https://username:[email protected]", | ||
"https://username:****@example.com", | ||
id="url with credentials", | ||
), | ||
), | ||
) | ||
def test_default_index_url(make_pip_conf, url, expected_url): | ||
""" | ||
Test help's output with default index URL. | ||
""" | ||
make_pip_conf( | ||
dedent( | ||
"""\ | ||
[global] | ||
index-url = {url} | ||
""".format( | ||
url=url | ||
) | ||
) | ||
) | ||
|
||
status, output = invoke([sys.executable, "-m", "piptools", "compile", "--help"]) | ||
output = output.decode("utf-8") | ||
|
||
# Click's subprocess output has \r\r\n line endings on win py27. Fix it. | ||
output = output.replace("\r\r", "\r") | ||
|
||
assert status == 0 | ||
expected = ( | ||
" -i, --index-url TEXT Change index URL (defaults to" | ||
+ os.linesep | ||
+ " http://example.com)" | ||
+ os.linesep | ||
) | ||
assert expected in output | ||
assert expected_url in output | ||
|
||
|
||
def test_stdin_without_output_file(runner): | ||
|
@@ -995,15 +1035,20 @@ def test_options_in_requirements_file(runner, options): | |
("cli_options", "expected_message"), | ||
( | ||
pytest.param( | ||
["--index-url", "file:foo"], | ||
"Was file:foo reachable?", | ||
["--index-url", "scheme://foo"], | ||
"Was scheme://foo reachable?", | ||
id="single index url", | ||
), | ||
pytest.param( | ||
["--index-url", "file:foo", "--extra-index-url", "file:bar"], | ||
"Were file:foo or file:bar reachable?", | ||
["--index-url", "scheme://foo", "--extra-index-url", "scheme://bar"], | ||
"Were scheme://foo or scheme://bar reachable?", | ||
id="multiple index urls", | ||
), | ||
pytest.param( | ||
["--index-url", "scheme://username:password@host"], | ||
"Was scheme://username:****@host reachable?", | ||
id="index url with credentials", | ||
), | ||
), | ||
) | ||
def test_unreachable_index_urls(runner, cli_options, expected_message): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -274,6 +274,16 @@ def test_force_text(value, expected_text): | |
["--pip-args", "--disable-pip-version-check --isolated"], | ||
"pip-compile --pip-args='--disable-pip-version-check --isolated'", | ||
), | ||
pytest.param( | ||
["--extra-index-url", "https://username:[email protected]/"], | ||
"pip-compile --extra-index-url='https://username:****@example.com/'", | ||
id="redact password in index", | ||
), | ||
pytest.param( | ||
["--find-links", "https://username:[email protected]/"], | ||
"pip-compile --find-links='https://username:****@example.com/'", | ||
id="redact password in link", | ||
), | ||
), | ||
) | ||
def test_get_compile_command(tmpdir_cwd, cli_args, expected_command): | ||
|