Skip to content
Myr

Add test to verify .netrc authentication behavior.

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

Here's what should happen: - If no credentials are given, use netrc if there's a netrc entry. - If credentials are given, they should override netrc.

authored by Vikram Oberoi · committed by Vikram Oberoi · parent 188e760 · Browse files · 1 file+28 added−0 removed
This commit

State

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

Diff stats

1 file+28 added−0 removed

  • other:+28 added−0 removed

1 file+28 added−0 removed

modified:test_requests.py+28 added
232 unmodified lines
233 s.auth = auth234 r = s.get(url)235 self.assertEqual(r.status_code, 200)236237 def test_basicauth_with_netrc(self):238 auth = ('user', 'pass')239 wrong_auth = ('wronguser', 'wrongpass')240 url = httpbin('basic-auth', 'user', 'pass')241242 def get_netrc_auth_mock(url):243 return auth244 requests.sessions.get_netrc_auth = get_netrc_auth_mock245246 # Should use netrc and work.247 r = requests.get(url)248 self.assertEqual(r.status_code, 200)249250 # Given auth should override and fail.251 r = requests.get(url, auth=wrong_auth)252 self.assertEqual(r.status_code, 401)253254 s = requests.session()255 256 # Should use netrc and work.257 r = s.get(url)258 self.assertEqual(r.status_code, 200)259260 # Given auth should override and fail.261 s.auth = wrong_auth262 r = s.get(url)263 self.assertEqual(r.status_code, 401)264265 def test_DIGEST_HTTP_200_OK_GET(self):266267 auth = HTTPDigestAuth('user', 'pass')268 url = httpbin('digest-auth', 'auth', 'user', 'pass')
508 unmodified lines