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

Fix redact url in --help #9207

Merged
merged 3 commits into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions news/9191.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Handle case of list default values in UpdatingDefaultsHelpFormatter
Happens because we pass a list from --extra-index-url
pradyunsg marked this conversation as resolved.
Show resolved Hide resolved
18 changes: 13 additions & 5 deletions src/pip/_internal/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,23 @@ class UpdatingDefaultsHelpFormatter(PrettyHelpFormatter):
"""

def expand_default(self, option):
default_value = None
default_values = None
if self.parser is not None:
self.parser._update_defaults(self.parser.defaults)
default_value = self.parser.defaults.get(option.dest)
default_values = self.parser.defaults.get(option.dest)
help_text = optparse.IndentedHelpFormatter.expand_default(self, option)

if default_value and option.metavar == 'URL':
help_text = help_text.replace(
default_value, redact_auth_from_url(default_value))
if default_values and option.metavar == 'URL':
if isinstance(default_values, string_types):
default_values = [default_values]

# If its not a list, we should abort and just return the help text
if not isinstance(default_values, list):
default_values = []

for val in default_values:
help_text = help_text.replace(
val, redact_auth_from_url(val))
pradyunsg marked this conversation as resolved.
Show resolved Hide resolved

return help_text

Expand Down
11 changes: 11 additions & 0 deletions tests/functional/test_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ def test_help_command_redact_auth_from_url(script):
assert 'secret' not in result.stdout


def test_help_command_redact_auth_from_url_with_extra_index_url(script):
"""
Test `help` on various subcommands redact auth from url with extra index url
"""
script.environ['PIP_INDEX_URL'] = 'https://user:secret@example.com'
script.environ['PIP_EXTRA_INDEX_URL'] = 'https://user:secret@example2.com'
result = script.pip('install', '--help')
assert result.returncode == SUCCESS
assert 'secret' not in result.stdout


def test_help_commands_equally_functional(in_memory_pip):
"""
Test if `pip help` and 'pip --help' behave the same way.
Expand Down