Skip to content
Myr

Fix infinite loop on wrong Digest Authentication

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

authored by Pierre Chapuis · committed by Pierre Chapuis · parent 8a055c5 · Browse files · 3 files+28 added−1 removed
This commit

State

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

Diff stats

3 files+28 added−1 removed

  • tests:+14 added−0 removed
  • other:+14 added−1 removed

3 files+28 added−1 removed

modified:requests/auth.py+2 added
54 unmodified lines
5556 def handle_401(self, r):57 """Takes the given response and tries digest-auth, if needed."""5859 r.request.deregister_hook('response', self.handle_401)6061 s_auth = r.headers.get('www-authenticate', '')6263 if 'digest' in s_auth.lower():64
86 unmodified lines
modified:requests/models.py+12 added-1 removed
406 unmodified lines
407408 def register_hook(self, event, hook):409 """Properly register a hook."""410411 return self.hooks[event].append(hook)411 self.hooks[event].append(hook)412413 def deregister_hook(self,event,hook):414 """Deregister a previously registered hook.415 Returns True if the hook existed, False if not.416 """417418 try:419 self.hooks[event].remove(hook)420 return True421 except ValueError:422 return False423424 def send(self, anyway=False, prefetch=False):425 """Sends the request. Returns True of successful, False if not.426 If there was an HTTPError during transmission,427 self.response.status_code will contain the HTTPError code.
402 unmodified lines
modified:tests/test_requests.py+14 added
270 unmodified lines
271 s = requests.session(auth=auth)272 r = get(url, session=s)273 self.assertEqual(r.status_code, 200)274275 def test_DIGESTAUTH_WRONG_HTTP_401_GET(self):276277 for service in SERVICES:278279 auth = HTTPDigestAuth('user', 'wrongpass')280 url = service('digest-auth', 'auth', 'user', 'pass')281282 r = get(url, auth=auth)283 self.assertEqual(r.status_code, 401)284285 s = requests.session(auth=auth)286 r = get(url, session=s)287 self.assertEqual(r.status_code, 401)288289 def test_POSTBIN_GET_POST_FILES(self):290291 for service in SERVICES:292
538 unmodified lines