File tree Expand file tree Collapse file tree 2 files changed +20
-8
lines changed Expand file tree Collapse file tree 2 files changed +20
-8
lines changed Original file line number Diff line number Diff line change @@ -219,14 +219,7 @@ def get_netrc_auth(url, raise_errors=False):
219219 netrc_path = None
220220
221221 for f in netrc_locations :
222- try :
223- loc = os .path .expanduser (f )
224- except KeyError :
225- # os.path.expanduser can fail when $HOME is undefined and
226- # getpwuid fails. See https://bugs.python.org/issue20164 &
227- # https://github.com/psf/requests/issues/1846
228- return
229-
222+ loc = os .path .expanduser (f )
230223 if os .path .exists (loc ):
231224 netrc_path = loc
232225 break
Original file line number Diff line number Diff line change 2323 get_encoding_from_headers ,
2424 get_encodings_from_content ,
2525 get_environ_proxies ,
26+ get_netrc_auth ,
2627 guess_filename ,
2728 guess_json_utf ,
2829 is_ipv4_address ,
@@ -152,6 +153,24 @@ def test_super_len_with_no_matches(self):
152153 assert super_len (object ()) == 0
153154
154155
156+ class TestGetNetrcAuth :
157+ def test_works (self , tmp_path , monkeypatch ):
158+ netrc_path = tmp_path / ".netrc"
159+ monkeypatch .setenv ("NETRC" , str (netrc_path ))
160+ with open (netrc_path , "w" ) as f :
161+ f .write ("machine example.com login aaaa password bbbb\n " )
162+ auth = get_netrc_auth ("http://example.com/thing" )
163+ assert auth == ("aaaa" , "bbbb" )
164+
165+ def test_not_vulnerable_to_bad_url_parsing (self , tmp_path , monkeypatch ):
166+ netrc_path = tmp_path / ".netrc"
167+ monkeypatch .setenv ("NETRC" , str (netrc_path ))
168+ with open (netrc_path , "w" ) as f :
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 None
172+
173+
155174class TestToKeyValList :
156175 @pytest .mark .parametrize (
157176 "value, expected" ,
You can’t perform that action at this time.
0 commit comments