Skip to content
Myr

Merge pull request #1439 from voberoi/master

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

Make sure netrc doesn't override any authentication settings explicitly set by the client

authored by Kenneth Reitz · committed by Kenneth Reitz · parents 86d466c, d9c49ad · Browse files · 2 files+30 added−2 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+30 added−2 removed

  • other:+30 added−2 removed

2 files+30 added−2 removed

modified:requests/sessions.py+2 added-2 removed
287 unmodified lines
288 env_proxies = get_environ_proxies(url) or {}289 for (k, v) in env_proxies.items():290 proxies.setdefault(k, v)291292 # Set environment's basic authentication.293 if not auth:292 # Set environment's basic authentication if not explicitly set.293 if not auth and not self.auth:294 auth = get_netrc_auth(url)295296 # Look for configuration.297 if not verify and verify is not False:
207 unmodified lines
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