Skip to content
Myr

Add more tests to prevent regression of CVE 2024 47081

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

Remove workaround not needed since py38 for os.path.expanduser.

authored by Arthur Woimbée · committed by GitHub · parent 7bc4587 · Browse files · 2 files+20 added−8 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+20 added−8 removed

  • tests:+19 added−0 removed
  • other:+1 added−8 removed

2 files+20 added−8 removed

modified:src/requests/utils.py+1 added-8 removed
217 unmodified lines
218219 netrc_path = None220221 for f in netrc_locations:222 try:223 loc = os.path.expanduser(f)222 loc = os.path.expanduser(f)224 except KeyError:225 # os.path.expanduser can fail when $HOME is undefined and226 # getpwuid fails. See https://bugs.python.org/issue20164 &227 # https://github.com/psf/requests/issues/1846228 return229223 if os.path.exists(loc):224 netrc_path = loc225 break226
860 unmodified lines
modified:tests/test_utils.py+19 added
21 unmodified lines
22 get_auth_from_url,23 get_encoding_from_headers,24 get_encodings_from_content,25 get_environ_proxies,26 get_netrc_auth,27 guess_filename,28 guess_json_utf,29 is_ipv4_address,30 is_valid_cidr,
121 unmodified lines
152 """Ensure that objects without any length methods default to 0"""153 assert super_len(object()) == 0154155156class 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")164165 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 None172173174class TestToKeyValList:175 @pytest.mark.parametrize(176 "value, expected",177 (
800 unmodified lines