File tree 3 files changed +23
-1
lines changed
3 files changed +23
-1
lines changed Original file line number Diff line number Diff line change
1
+ Redact auth from URL in help message.
Original file line number Diff line number Diff line change 17
17
from pip ._internal .cli .status_codes import UNKNOWN_ERROR
18
18
from pip ._internal .configuration import Configuration , ConfigurationError
19
19
from pip ._internal .utils .compat import get_terminal_size
20
+ from pip ._internal .utils .misc import redact_auth_from_url
20
21
21
22
logger = logging .getLogger (__name__ )
22
23
@@ -106,12 +107,22 @@ class UpdatingDefaultsHelpFormatter(PrettyHelpFormatter):
106
107
107
108
This is updates the defaults before expanding them, allowing
108
109
them to show up correctly in the help listing.
110
+
111
+ Also redact auth from url type options
109
112
"""
110
113
111
114
def expand_default (self , option ):
115
+ default_value = None
112
116
if self .parser is not None :
113
117
self .parser ._update_defaults (self .parser .defaults )
114
- return optparse .IndentedHelpFormatter .expand_default (self , option )
118
+ default_value = self .parser .defaults .get (option .dest )
119
+ help_text = optparse .IndentedHelpFormatter .expand_default (self , option )
120
+
121
+ if default_value and option .metavar == 'URL' :
122
+ help_text = help_text .replace (
123
+ default_value , redact_auth_from_url (default_value ))
124
+
125
+ return help_text
115
126
116
127
117
128
class CustomOptionParser (optparse .OptionParser ):
Original file line number Diff line number Diff line change @@ -64,6 +64,16 @@ def test_help_command_should_exit_status_error_when_cmd_does_not_exist(script):
64
64
assert result .returncode == ERROR
65
65
66
66
67
+ def test_help_command_redact_auth_from_url (script ):
68
+ """
69
+ Test `help` on various subcommands redact auth from url
70
+ """
71
+ script .
environ [
'PIP_INDEX_URL' ]
= 'https://user:[email protected] '
72
+ result = script .pip ('install' , '--help' )
73
+ assert result .returncode == SUCCESS
74
+ assert 'secret' not in result .stdout
75
+
76
+
67
77
def test_help_commands_equally_functional (in_memory_pip ):
68
78
"""
69
79
Test if `pip help` and 'pip --help' behave the same way.
You can’t perform that action at this time.
0 commit comments