Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions tests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
import pickle
import re
import tempfile
import threading
import warnings
from unittest import mock
Expand Down Expand Up @@ -704,6 +705,36 @@ def get_netrc_auth_mock(url):
finally:
requests.sessions.get_netrc_auth = old_auth

def test_basicauth_with_netrc_leak(self, httpbin):
url1 = httpbin("basic-auth", "user", "pass")
url = url1[len("http://") :]
domain = url.split(":")[0]
url = f"http://example.com:@{url}"

netrc_file = ""
with tempfile.NamedTemporaryFile(mode="w", delete=False) as fp:
fp.write("machine example.com\n")
fp.write("login wronguser\n")
fp.write("password wrongpass\n")
fp.write(f"machine {domain}\n")
fp.write("login user\n")
fp.write("password pass\n")
fp.close()
netrc_file = fp.name

old_netrc = os.environ.get("NETRC", "")
os.environ["NETRC"] = netrc_file

try:
# Should use netrc
# Make sure that we don't use the example.com credentails
# for the request
r = requests.get(url)
assert r.status_code == 200
finally:
os.environ["NETRC"] = old_netrc
os.unlink(netrc_file)

def test_DIGEST_HTTP_200_OK_GET(self, httpbin):
for authtype in self.digest_auth_algo:
auth = HTTPDigestAuth("user", "pass")
Expand Down
Loading