-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove the unneeded logger argument from is_secure_origin().
- Loading branch information
Showing
3 changed files
with
28 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -700,21 +700,22 @@ def test_iter_secure_origins__insecure_hosts_empty(self): | |
assert actual[0] == ('https', '*', '*') | ||
|
||
@pytest.mark.parametrize( | ||
("location", "trusted", "expected"), | ||
'location, trusted, expected', | ||
[ | ||
("http://pypi.org/something", [], True), | ||
("https://pypi.org/something", [], False), | ||
("git+http://pypi.org/something", [], True), | ||
("git+https://pypi.org/something", [], False), | ||
("git+ssh://[email protected]/something", [], False), | ||
("http://localhost", [], False), | ||
("http://127.0.0.1", [], False), | ||
("http://example.com/something/", [], True), | ||
("http://example.com/something/", ["example.com"], False), | ||
("http://eXample.com/something/", ["example.cOm"], False), | ||
("http://pypi.org/something", [], False), | ||
("https://pypi.org/something", [], True), | ||
("git+http://pypi.org/something", [], False), | ||
("git+https://pypi.org/something", [], True), | ||
("git+ssh://[email protected]/something", [], True), | ||
("http://localhost", [], True), | ||
("http://127.0.0.1", [], True), | ||
("http://example.com/something/", [], False), | ||
("http://example.com/something/", ["example.com"], True), | ||
# Try changing the case. | ||
("http://eXample.com/something/", ["example.cOm"], True), | ||
], | ||
) | ||
def test_secure_origin(self, location, trusted, expected): | ||
def test_is_secure_origin(self, caplog, location, trusted, expected): | ||
class MockLogger(object): | ||
def __init__(self): | ||
self.called = False | ||
|
@@ -723,9 +724,18 @@ def warning(self, *args, **kwargs): | |
self.called = True | ||
|
||
session = PipSession(insecure_hosts=trusted) | ||
logger = MockLogger() | ||
session.is_secure_origin(logger, location) | ||
assert logger.called == expected | ||
actual = session.is_secure_origin(location) | ||
assert actual == expected | ||
|
||
log_records = [(r.levelname, r.message) for r in caplog.records] | ||
if expected: | ||
assert not log_records | ||
return | ||
|
||
assert len(log_records) == 1 | ||
actual_level, actual_message = log_records[0] | ||
assert actual_level == 'WARNING' | ||
assert 'is not a trusted or secure host' in actual_message | ||
|
||
|
||
@pytest.mark.parametrize(["input_url", "url", "username", "password"], [ | ||
|