~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-21 20:39:06 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-20070421203906-hta5jt0nmauyl9qy
Implement digest authentication. Test suite passes. Tested against apache-2.x.

* bzrlib/transport/http/_urllib2_wrappers.py:
(AbstractAuthHandler.auth_required): Do not attempt to
authenticate if we don't have a user. Rework the detection of
already tried authentications. Avoid building the auth header two
times, save the auth info at the right places.
(AbstractAuthHandler.build_auth_header): Add a request parameter
for digest needs.
(BasicAuthHandler.auth_match): Simplify.
(get_digest_algorithm_impls, DigestAuthHandler): Implements client
digest authentication. MD5 and SHA algorithms are supported. Only
'auth' qop is suppoted.
(HTTPBasicAuthHandler, ProxyBasicAuthHandler): Renamed HTTPHandler
and ProxyAuthHandler respectively.
(HTTPBasicAuthHandler, ProxyBasicAuthHandler,
HTTPDigestAuthHandler, ProxyDigestAuthHandler): New classes
implementing the combinations between (http, proxy) and (basic,
digest).
(Opener.__init__): No more handlers in comment ! One TODO less !

* bzrlib/transport/http/_urllib.py:
(HttpTransport_urllib.__init__): self.base is not suitable for an
auth uri, it can contain decorators.

* bzrlib/tests/test_http.py:
(TestAuth.test_no_user): New test to check the behavior with no
user when authentication is required.

* bzrlib/tests/HTTPTestUtil.py:
(DigestAuthRequestHandler.authorized): Delegate most of the work
to the server that control the needed persistent infos.
(AuthServer): Define an auth_relam attribute.
(DigestAuthServer): Implement a first version of digest
authentication. Only the MD5 algorithm and the 'auth' qop are
supported so far.
(HTTPAuthServer.init_http_auth): New method to simplify
the [http|proxy], [basic|digest] server combinations writing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1170
1170
        url += '%s:%s/' % (self.server.host, self.server.port)
1171
1171
        return url
1172
1172
 
 
1173
    def test_no_user(self):
 
1174
        self.server.add_user('joe', 'foo')
 
1175
        t = self.get_user_transport()
 
1176
        self.assertRaises(errors.InvalidHttpResponse, t.get, 'a')
 
1177
        # Only one 'Authentication Required' error should occur
 
1178
        self.assertEqual(1, self.server.auth_required_errors)
 
1179
 
1173
1180
    def test_empty_pass(self):
1174
1181
        self.server.add_user('joe', '')
1175
1182
        t = self.get_user_transport('joe', '')
1231
1238
        self.server = self.get_readonly_server()
1232
1239
        TestAuth.setUp(self)
1233
1240
 
1234
 
    def get_user_transport(self, user, password=None):
 
1241
    def get_user_transport(self, user=None, password=None):
1235
1242
        return self._transport(self.get_user_url(user, password))
1236
1243
 
1237
1244
 
1255
1262
                                  ('b-proxied', 'contents of b\n'),
1256
1263
                                  ])
1257
1264
 
1258
 
    def get_user_transport(self, user, password=None):
 
1265
    def get_user_transport(self, user=None, password=None):
1259
1266
        self._install_env({'all_proxy': self.get_user_url(user, password)})
1260
1267
        return self._transport(self.server.get_url())
1261
1268