Merge branch 'master' of github.com:kennethreitz/requests
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Kenneth Reitz · committed by Kenneth Reitz · parents 036b5d3, f4a3aa4 · Browse files · 5 files·+46 added−3 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+46 added−3 removed
- tests:+37 added−0 removed
- other:+9 added−3 removed
Provenance
- Commit
8c6e938- Tree
ec87904- Author
Kenneth Reitz <me@kennethreitz.org>- Committer
Kenneth Reitz <me@kennethreitz.org>- Parent 1
036b5d3- Parent 2
f4a3aa4
5 files changed+46 added−3 removed
modified:requests/auth.py+6 added
225 unmodified lines226 227 :rtype: requests.Response228 """229 230+ # If response is not 4xx, do not auth231+ # See https://github.com/kennethreitz/requests/issues/3772232+ if not 400 <= r.status_code < 500:233+ self._thread_local.num_401_calls = 1234+ return r235+236 if self._thread_local.pos is not None:237 # Rewind the file position indicator of the body to where238 # it was to resend the request.239 r.request.body.seek(self._thread_local.pos)55 unmodified linesmodified:tests/test_lowlevel.py+37 added
134 unmodified lines135 assert r.history[0].status_code == 401136 close_server.set()137 138 139+def test_digestauth_only_on_4xx():140+ """Ensure we only send digestauth on 4xx challenges.141+142+ See https://github.com/kennethreitz/requests/issues/3772.143+ """144+ text_200_chal = (b'HTTP/1.1 200 OK\r\n'145+ b'Content-Length: 0\r\n'146+ b'WWW-Authenticate: Digest nonce="6bf5d6e4da1ce66918800195d6b9130d"'147+ b', opaque="372825293d1c26955496c80ed6426e9e", '148+ b'realm="me@kennethreitz.com", qop=auth\r\n\r\n')149+150+ auth = requests.auth.HTTPDigestAuth('user', 'pass')151+152+ def digest_response_handler(sock):153+ # Respond to GET with a 200 containing www-authenticate header.154+ request_content = consume_socket_content(sock, timeout=0.5)155+ assert request_content.startswith(b"GET / HTTP/1.1")156+ sock.send(text_200_chal)157+158+ # Verify the client didn't respond with auth.159+ request_content = consume_socket_content(sock, timeout=0.5)160+ assert request_content == b''161+162+ return request_content163+164+ close_server = threading.Event()165+ server = Server(digest_response_handler, wait_to_close_event=close_server)166+167+ with server as (host, port):168+ url = 'http://{0}:{1}/'.format(host, port)169+ r = requests.get(url, auth=auth)170+ # Verify server didn't receive auth from us.171+ assert r.status_code == 200172+ assert len(r.history) == 0173+ close_server.set()174+175+176 _schemes_by_var_prefix = [177 ('http', ['http']),178 ('https', ['https']),179 ('all', ['http', 'https']),27 unmodified linesmodified:.travis.yml+1 added-1 removed
13 unmodified lines14151617181813 unmodified lines# command to run testsscript: - make coverageafter_success: - codecov - pipenv run codecovmodified:LICENSE+1 added-1 removed
1-Copyright 2016 Kenneth Reitz1+Copyright 2017 Kenneth Reitz2 3 Licensed under the Apache License, Version 2.0 (the "License");4 you may not use this file except in compliance with the License.5 You may obtain a copy of the License at8 unmodified linesmodified:Makefile+1 added-1 removed
1 .PHONY: docs2 3 init:4- pip install pipenv4+ pip install pipenv==3.1.95 pipenv lock6 pipenv install --dev7 8 test:53 unmodified lines