add test for HTTP Digest auth algorithms SHA-256 and SHA-512
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Poole · committed by David Poole · parent a31531f · Browse files · 1 file·+52 added−41 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+52 added−41 removed
- tests:+52 added−41 removed
Provenance
- Commit
1e46cbb- Tree
408cb6c- Author
David Poole <testcluster@gmail.com>- Committer
David Poole <testcluster@gmail.com>- Parent
a31531f
1 file changed+52 added−41 removed
modified:tests/test_requests.py+52 added-41 removed
52 unmodified lines53 54 55 class TestRequests:56 57+ digest_auth_algo = ('MD5', 'SHA-256', 'SHA-512')58+59 def test_entry_points(self):60 61 requests.session62 requests.session().get512 unmodified lines575 requests.sessions.get_netrc_auth = old_auth576 577 def test_DIGEST_HTTP_200_OK_GET(self, httpbin):578 579+ for authtype in self.digest_auth_algo:577- auth = HTTPDigestAuth('user', 'pass')578- url = httpbin('digest-auth', 'auth', 'user', 'pass')580+ auth = HTTPDigestAuth('user', 'pass')581+ url = httpbin('digest-auth', 'auth', 'user', 'pass', authtype, 'never')582 580- r = requests.get(url, auth=auth)581- assert r.status_code == 200583+ r = requests.get(url, auth=auth)584+ assert r.status_code == 200585 583- r = requests.get(url)584- assert r.status_code == 401586+ r = requests.get(url)587+ assert r.status_code == 401588+ print(r.headers['WWW-Authenticate'])589 586- s = requests.session()587- s.auth = HTTPDigestAuth('user', 'pass')588- r = s.get(url)589- assert r.status_code == 200590+ s = requests.session()591+ s.auth = HTTPDigestAuth('user', 'pass')592+ r = s.get(url)593+ assert r.status_code == 200594 595 def test_DIGEST_AUTH_RETURNS_COOKIE(self, httpbin):592- url = httpbin('digest-auth', 'auth', 'user', 'pass')593- auth = HTTPDigestAuth('user', 'pass')594- r = requests.get(url)595- assert r.cookies['fake'] == 'fake_value'596 597- r = requests.get(url, auth=auth)598- assert r.status_code == 200597+ for authtype in self.digest_auth_algo:598+ url = httpbin('digest-auth', 'auth', 'user', 'pass', authtype)599+ auth = HTTPDigestAuth('user', 'pass')600+ r = requests.get(url)601+ assert r.cookies['fake'] == 'fake_value'602 603+ r = requests.get(url, auth=auth)604+ assert r.status_code == 200605+606 def test_DIGEST_AUTH_SETS_SESSION_COOKIES(self, httpbin):601- url = httpbin('digest-auth', 'auth', 'user', 'pass')602- auth = HTTPDigestAuth('user', 'pass')603- s = requests.Session()604- s.get(url, auth=auth)605- assert s.cookies['fake'] == 'fake_value'607 608+ for authtype in self.digest_auth_algo:609+ url = httpbin('digest-auth', 'auth', 'user', 'pass', authtype)610+ auth = HTTPDigestAuth('user', 'pass')611+ s = requests.Session()612+ s.get(url, auth=auth)613+ assert s.cookies['fake'] == 'fake_value'614+615 def test_DIGEST_STREAM(self, httpbin):616 617+ for authtype in self.digest_auth_algo:609- auth = HTTPDigestAuth('user', 'pass')610- url = httpbin('digest-auth', 'auth', 'user', 'pass')618+ auth = HTTPDigestAuth('user', 'pass')619+ url = httpbin('digest-auth', 'auth', 'user', 'pass', authtype)620 612- r = requests.get(url, auth=auth, stream=True)613- assert r.raw.read() != b''621+ r = requests.get(url, auth=auth, stream=True)622+ assert r.raw.read() != b''623 615- r = requests.get(url, auth=auth, stream=False)616- assert r.raw.read() == b''624+ r = requests.get(url, auth=auth, stream=False)625+ assert r.raw.read() == b''626 627 def test_DIGESTAUTH_WRONG_HTTP_401_GET(self, httpbin):628 629+ for authtype in self.digest_auth_algo:620- auth = HTTPDigestAuth('user', 'wrongpass')621- url = httpbin('digest-auth', 'auth', 'user', 'pass')630+ auth = HTTPDigestAuth('user', 'wrongpass')631+ url = httpbin('digest-auth', 'auth', 'user', 'pass', authtype)632 623- r = requests.get(url, auth=auth)624- assert r.status_code == 401633+ r = requests.get(url, auth=auth)634+ assert r.status_code == 401635 626- r = requests.get(url)627- assert r.status_code == 401636+ r = requests.get(url)637+ assert r.status_code == 401638 629- s = requests.session()630- s.auth = auth631- r = s.get(url)632- assert r.status_code == 401639+ s = requests.session()640+ s.auth = auth641+ r = s.get(url)642+ assert r.status_code == 401643 644 def test_DIGESTAUTH_QUOTES_QOP_VALUE(self, httpbin):645 646+ for authtype in self.digest_auth_algo:636- auth = HTTPDigestAuth('user', 'pass')637- url = httpbin('digest-auth', 'auth', 'user', 'pass')647+ auth = HTTPDigestAuth('user', 'pass')648+ url = httpbin('digest-auth', 'auth', 'user', 'pass', authtype)649 639- r = requests.get(url, auth=auth)640- assert '"auth"' in r.request.headers['Authorization']650+ r = requests.get(url, auth=auth)651+ assert '"auth"' in r.request.headers['Authorization']652 653 def test_POSTBIN_GET_POST_FILES(self, httpbin):654 655 url = httpbin('post')1796 unmodified lines