-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Redact URL to hide password #6295
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
00b872f
Redact URL to hide password
expobrain 34b123d
Use already existent utility function ot hide password
expobrain 5c232bc
Updated unit test
expobrain ddb7320
Pass index url straight to the command
expobrain 70dee95
Moved test into unit
expobrain c33535b
Use caplog instead of mock
expobrain 1214941
Added NEWS file
expobrain 5bfb47c
Improved unit test
expobrain 137a7ab
Better unit test comment
expobrain b37ad3f
Better NEWS files content
expobrain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Redacts the URL of the extra index when `pip -v` to hide the user's password | ||
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 |
---|---|---|
|
@@ -118,6 +118,34 @@ def test_get_html_response_no_head(url): | |
] | ||
|
||
|
||
def test_get_html_response_dont_log_clear_text_password(caplog): | ||
""" | ||
`_get_html_response()` shouldn't log the full index's URL includoing the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo: including Also, this could be a little clearer. How about: " |
||
user's password in clear text on DEBUG channel but only the redacted URL | ||
""" | ||
session = mock.Mock(PipSession) | ||
|
||
# Mock the headers dict to ensure it is accessed. | ||
session.get.return_value = mock.Mock(headers=mock.Mock(**{ | ||
"get.return_value": "text/html", | ||
})) | ||
|
||
caplog.set_level(logging.DEBUG) | ||
|
||
resp = _get_html_response( | ||
"https://user:my_password@example.com/simple/", session=session | ||
) | ||
|
||
assert resp is not None | ||
|
||
assert len(caplog.records) == 1 | ||
record = caplog.records[0] | ||
assert record.levelname == 'DEBUG' | ||
assert record.message.splitlines() == [ | ||
"Getting page https://user:****@example.com/simple/", | ||
] | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"url, vcs_scheme", | ||
[ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the URL isn't being removed but only the password, it would be better to say something like, "Redact the password from the extra index URL when using
pip -v
." Also, you want to use double backticks before and after "pip -v" rather than single, and end the sentence with a period.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean like ``pip -v``?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. I couldn't get it to render in GitHub's viewer when I first tried. The reason for double is because the contents are reStructuredText and not, say, Markdown: https://pip.pypa.io/en/stable/development/contributing/#contents-of-a-news-entry
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used a backslash before the backtick to escape it and let Markdown ignore it