Rev 2424: Add test checking the number of roundtrips due to 401 or 407 errors. in http://bazaar.launchpad.net/~bzr/bzr/bzr.http.auth
Vincent Ladeuil
v.ladeuil+lp at free.fr
Wed Apr 18 09:08:19 BST 2007
At http://bazaar.launchpad.net/~bzr/bzr/bzr.http.auth
------------------------------------------------------------
revno: 2424
revision-id: v.ladeuil+lp at free.fr-20070418080816-ovy46d2gv7mzlr86
parent: v.ladeuil+lp at free.fr-20070417220718-kce3mj0wn8hi8m02
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: bzr.http.auth
timestamp: Wed 2007-04-18 10:08:16 +0200
message:
Add test checking the number of roundtrips due to 401 or 407 errors.
* bzrlib/tests/test_http.py:
(TestHTTPAuth.test_empty_pass): Verifying the number of
authentication errors allows to count the 40[17] roundtrips.
* bzrlib/tests/HTTPTestUtil.py:
(AbstractBasicAuthRequestHandler.do_GET): Count the authentication
errors.
modified:
bzrlib/tests/HTTPTestUtil.py HTTPTestUtil.py-20050914180604-247d3aafb7a43343
bzrlib/tests/test_http.py testhttp.py-20051018020158-b2eef6e867c514d9
-------------- next part --------------
=== modified file 'bzrlib/tests/HTTPTestUtil.py'
--- a/bzrlib/tests/HTTPTestUtil.py 2007-04-17 22:07:18 +0000
+++ b/bzrlib/tests/HTTPTestUtil.py 2007-04-18 08:08:16 +0000
@@ -331,6 +331,10 @@
user, password = coded_auth.decode('base64').split(':')
authorized = tcs.authorized(user, password)
if not authorized:
+ # Note that we must update tcs *before* sending
+ # the error or the client may try to read it
+ # before we have sent the whole error back.
+ tcs.auth_required_errors += 1
self.send_response(self._auth_error_code)
self.send_header(self._auth_header_sent,
'Basic realm="Thou should not pass"')
@@ -353,6 +357,7 @@
HttpServer.__init__(self, request_handler)
self.auth_scheme = auth_scheme
self.password_of = {}
+ self.auth_required_errors = 0
def add_user(self, user, password):
"""Declare a user with an associated password.
=== modified file 'bzrlib/tests/test_http.py'
--- a/bzrlib/tests/test_http.py 2007-04-17 22:07:18 +0000
+++ b/bzrlib/tests/test_http.py 2007-04-18 08:08:16 +0000
@@ -1172,21 +1172,32 @@
self.server.add_user('joe', '')
t = self._transport(self.get_user_url('joe', ''))
self.assertEqual('contents of a\n', t.get('a').read())
+ # Only one 'Authentication Required' error should occur
+ self.assertEqual(1, self.server.auth_required_errors)
def test_user_pass(self):
self.server.add_user('joe', 'foo')
t = self._transport(self.get_user_url('joe', 'foo'))
self.assertEqual('contents of a\n', t.get('a').read())
+ # Only one 'Authentication Required' error should occur
+ self.assertEqual(1, self.server.auth_required_errors)
def test_unknown_user(self):
self.server.add_user('joe', 'foo')
t = self._transport(self.get_user_url('bill', 'foo'))
self.assertRaises(errors.InvalidHttpResponse, t.get, 'a')
+ # Two 'Authentication Required' errors should occur (the
+ # initial 'who are you' and 'I don't know you, who are
+ # you').
+ self.assertEqual(2, self.server.auth_required_errors)
def test_wrong_pass(self):
self.server.add_user('joe', 'foo')
t = self._transport(self.get_user_url('joe', 'bar'))
self.assertRaises(errors.InvalidHttpResponse, t.get, 'a')
+ # Two 'Authentication Required' error should occur (the
+ # initial 'who are you' and 'this is not you, who are you')
+ self.assertEqual(2, self.server.auth_required_errors)
def test_prompt_for_password(self):
self.server.add_user('joe', 'foo')
@@ -1201,6 +1212,9 @@
t2 = t.clone()
# And neither against a clone
self.assertEqual('contents of b\n',t2.get('b').read())
+ # Only one 'Authentication Required' error should occur
+ self.assertEqual(1, self.server.auth_required_errors)
+
class TestHTTPBasicAuth(TestHTTPAuth, TestCaseWithWebserver):
@@ -1223,7 +1237,6 @@
_transport = HttpTransport_urllib
_auth_header = 'Proxy-authorization'
- _test_class = TestCaseWithWebserver
def setUp(self):
TestCaseWithTwoWebservers.setUp(self)
More information about the bazaar-commits
mailing list