Skip to content
Myr

Fix empty netrc entry usage (#7205)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Nate Prewitt · committed by GitHub · parent 1b40fdd · Browse files · 2 files+11 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+11 added−1 removed

  • tests:+10 added−0 removed
  • other:+1 added−1 removed

2 files+11 added−1 removed

modified:src/requests/utils.py+1 added-1 removed
229 unmodified lines
230 host = ri.hostname231232 try:233 _netrc = netrc(netrc_path).authenticators(host)234 if _netrc:234 if _netrc and any(_netrc):235 # Return with login / password236 login_i = 0 if _netrc[0] else 1237 return (_netrc[login_i], _netrc[2])238 except (NetrcParseError, OSError):
846 unmodified lines
modified:tests/test_utils.py+10 added
168 unmodified lines
169 f.write("machine example.com login aaaa password bbbb\n")170 auth = get_netrc_auth("http://example.com:@evil.com/'")171 assert auth is None172173 def test_empty_default_credentials_ignored(self, tmp_path, monkeypatch):174 """Empty default credentials should not be returned."""175 netrc_path = tmp_path / ".netrc"176 monkeypatch.setenv("NETRC", str(netrc_path))177 with open(netrc_path, "w") as f:178 f.write("machine example.com login user password pass\ndefault\n")179180 auth = get_netrc_auth("http://httpbin.org/")181 assert auth is None182183184class TestToKeyValList:185 @pytest.mark.parametrize(186 "value, expected",187 (
800 unmodified lines