~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http.py

  • Committer: Vincent Ladeuil
  • Date: 2007-04-18 08:08:16 UTC
  • mto: (2420.1.21 bzr.http.auth)
  • mto: This revision was merged to the branch mainline in revision 2463.
  • Revision ID: v.ladeuil+lp@free.fr-20070418080816-ovy46d2gv7mzlr86
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.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1172
1172
        self.server.add_user('joe', '')
1173
1173
        t = self._transport(self.get_user_url('joe', ''))
1174
1174
        self.assertEqual('contents of a\n', t.get('a').read())
 
1175
        # Only one 'Authentication Required' error should occur
 
1176
        self.assertEqual(1, self.server.auth_required_errors)
1175
1177
 
1176
1178
    def test_user_pass(self):
1177
1179
        self.server.add_user('joe', 'foo')
1178
1180
        t = self._transport(self.get_user_url('joe', 'foo'))
1179
1181
        self.assertEqual('contents of a\n', t.get('a').read())
 
1182
        # Only one 'Authentication Required' error should occur
 
1183
        self.assertEqual(1, self.server.auth_required_errors)
1180
1184
 
1181
1185
    def test_unknown_user(self):
1182
1186
        self.server.add_user('joe', 'foo')
1183
1187
        t = self._transport(self.get_user_url('bill', 'foo'))
1184
1188
        self.assertRaises(errors.InvalidHttpResponse, t.get, 'a')
 
1189
        # Two 'Authentication Required' errors should occur (the
 
1190
        # initial 'who are you' and 'I don't know you, who are
 
1191
        # you').
 
1192
        self.assertEqual(2, self.server.auth_required_errors)
1185
1193
 
1186
1194
    def test_wrong_pass(self):
1187
1195
        self.server.add_user('joe', 'foo')
1188
1196
        t = self._transport(self.get_user_url('joe', 'bar'))
1189
1197
        self.assertRaises(errors.InvalidHttpResponse, t.get, 'a')
 
1198
        # Two 'Authentication Required' error should occur (the
 
1199
        # initial 'who are you' and 'this is not you, who are you')
 
1200
        self.assertEqual(2, self.server.auth_required_errors)
1190
1201
 
1191
1202
    def test_prompt_for_password(self):
1192
1203
        self.server.add_user('joe', 'foo')
1201
1212
        t2 = t.clone()
1202
1213
        # And neither against a clone
1203
1214
        self.assertEqual('contents of b\n',t2.get('b').read())
 
1215
        # Only one 'Authentication Required' error should occur
 
1216
        self.assertEqual(1, self.server.auth_required_errors)
 
1217
 
1204
1218
 
1205
1219
 
1206
1220
class TestHTTPBasicAuth(TestHTTPAuth, TestCaseWithWebserver):
1223
1237
 
1224
1238
    _transport = HttpTransport_urllib
1225
1239
    _auth_header = 'Proxy-authorization'
1226
 
    _test_class = TestCaseWithWebserver
1227
1240
 
1228
1241
    def setUp(self):
1229
1242
        TestCaseWithTwoWebservers.setUp(self)