~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/http/_urllib2_wrappers.py

  • Committer: Vincent Ladeuil
  • Date: 2007-04-12 13:09:53 UTC
  • mto: (2420.1.1 bzr.http.auth)
  • mto: This revision was merged to the branch mainline in revision 2463.
  • Revision ID: v.ladeuil+lp@free.fr-20070412130953-pwgok8w72gxazlel
Add white box tests for basic HTTP auth.

* bzrlib/transport/http/_urllib2_wrappers.py:
(HTTPBasicAuthHandler.get_auth, HTTPBasicAuthHandler.set_auth):
New methods.

* bzrlib/tests/test_http.py:
(TestHttpProxyWhiteBox._proxied_request): Get rid of local imports.
(TestHTTPBasicAuth): New class. Tests basic HTTP auth.

Show diffs side-by-side

added added

removed removed

Lines of Context:
282
282
                        # urllib2 using capitalize() for headers
283
283
                        # instead of title(sp?).
284
284
                        'User-agent': 'bzr/%s (urllib)' % bzrlib_version,
285
 
                        # FIXME: pycurl also set the following, understand why
286
285
                        'Accept': '*/*',
287
286
                        }
288
287
 
724
723
    roundtrip associated with the 401 error.
725
724
    """
726
725
 
 
726
    def get_auth(self, user, password):
 
727
        raw = '%s:%s' % (user, password)
 
728
        auth = 'Basic ' + raw.encode('base64').strip()
 
729
        return auth
 
730
 
 
731
    def set_auth(self, request):
 
732
        """Add the authentification header if needed.
 
733
 
 
734
        All required informations should be part of the request.
 
735
        """
 
736
        if request.password is not None:
 
737
            request.add_header(self.auth_header,
 
738
                               self.get_auth(request.user, request.password))
 
739
 
727
740
#    def http_request(self, request):
728
741
#        """Insert an authentification header if information is available"""
729
742
#        if request.auth == 'basic' and request.password is not None: