~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: 2009-04-11 06:32:41 UTC
  • mto: (4285.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4286.
  • Revision ID: v.ladeuil+lp@free.fr-20090411063241-21hv3yp5kh9d05l4
Fix wrong realm extraction in http basic authentication (reported
by Jelmer).

* bzrlib/transport/http/_urllib2_wrappers.py:
(BasicAuthHandler.extract_realm): Factor out realm extraction for
tests purpose.

* bzrlib/tests/test_http.py:
(TestAuthHeader.parse_header): Accept a specific auth handler.
(TestAuthHeader.test_basic_extract_realm): Explicitly test realm
extraction.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1244
1244
        auth_header = 'Basic ' + raw.encode('base64').strip()
1245
1245
        return auth_header
1246
1246
 
 
1247
    def extract_realm(self, header_value):
 
1248
        match = self.auth_regexp.search(header_value)
 
1249
        realm = None
 
1250
        if match:
 
1251
            realm = match.group(1)
 
1252
        return match, realm
 
1253
 
1247
1254
    def auth_match(self, header, auth):
1248
1255
        scheme, raw_auth = self._parse_auth_header(header)
1249
1256
        if scheme != 'basic':
1250
1257
            return False
1251
1258
 
1252
 
        match = self.auth_regexp.search(raw_auth)
 
1259
        match, realm = self.extract_realm(raw_auth)
1253
1260
        if match:
1254
 
            realm = match.groups()
1255
1261
            if scheme != 'basic':
1256
1262
                return False
1257
1263