Rev 4286: Fix realm extraction for http basic authentication in http://bazaar.launchpad.net/%7Evila/bzr/integration
Vincent Ladeuil
v.ladeuil+lp at free.fr
Sat Apr 11 16:40:48 BST 2009
At http://bazaar.launchpad.net/%7Evila/bzr/integration
------------------------------------------------------------
revno: 4286 [merge]
revision-id: v.ladeuil+lp at free.fr-20090411154041-uxjscywwiaob54fb
parent: pqm at pqm.ubuntu.com-20090411130119-4kn8b6070uyqg5xx
parent: v.ladeuil+lp at free.fr-20090411153928-r4ozpn85lkoeg1mq
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: integration
timestamp: Sat 2009-04-11 17:40:41 +0200
message:
Fix realm extraction for http basic authentication
modified:
bzrlib/tests/test_http.py testhttp.py-20051018020158-b2eef6e867c514d9
bzrlib/transport/http/_urllib2_wrappers.py _urllib2_wrappers.py-20060913231729-ha9ugi48ktx481ao-1
------------------------------------------------------------
Use --levels 0 (or -n0) to see merged revisions.
-------------- next part --------------
=== modified file 'bzrlib/tests/test_http.py'
--- a/bzrlib/tests/test_http.py 2009-04-09 20:04:47 +0000
+++ b/bzrlib/tests/test_http.py 2009-04-11 15:39:28 +0000
@@ -215,9 +215,11 @@
class TestAuthHeader(tests.TestCase):
- def parse_header(self, header):
- ah = _urllib2_wrappers.AbstractAuthHandler()
- return ah._parse_auth_header(header)
+ def parse_header(self, header, auth_handler_class=None):
+ if auth_handler_class is None:
+ auth_handler_class = _urllib2_wrappers.AbstractAuthHandler
+ self.auth_handler = auth_handler_class()
+ return self.auth_handler._parse_auth_header(header)
def test_empty_header(self):
scheme, remainder = self.parse_header('')
@@ -235,6 +237,14 @@
self.assertEquals('basic', scheme)
self.assertEquals('realm="Thou should not pass"', remainder)
+ def test_basic_extract_realm(self):
+ scheme, remainder = self.parse_header(
+ 'Basic realm="Thou should not pass"',
+ _urllib2_wrappers.BasicAuthHandler)
+ match, realm = self.auth_handler.extract_realm(remainder)
+ self.assertTrue(match is not None)
+ self.assertEquals('Thou should not pass', realm)
+
def test_digest_header(self):
scheme, remainder = self.parse_header(
'Digest realm="Thou should not pass"')
@@ -1533,7 +1543,7 @@
self.assertEquals(expected_prompt, stdout.read(len(expected_prompt)))
self._check_password_prompt(t._unqualified_scheme, 'joe',
stdout.readline())
-
+
def test_prompt_for_password(self):
if self._testing_pycurl():
raise tests.TestNotApplicable(
=== modified file 'bzrlib/transport/http/_urllib2_wrappers.py'
--- a/bzrlib/transport/http/_urllib2_wrappers.py 2009-04-09 20:04:47 +0000
+++ b/bzrlib/transport/http/_urllib2_wrappers.py 2009-04-11 06:32:41 +0000
@@ -1244,14 +1244,20 @@
auth_header = 'Basic ' + raw.encode('base64').strip()
return auth_header
+ def extract_realm(self, header_value):
+ match = self.auth_regexp.search(header_value)
+ realm = None
+ if match:
+ realm = match.group(1)
+ return match, realm
+
def auth_match(self, header, auth):
scheme, raw_auth = self._parse_auth_header(header)
if scheme != 'basic':
return False
- match = self.auth_regexp.search(raw_auth)
+ match, realm = self.extract_realm(raw_auth)
if match:
- realm = match.groups()
if scheme != 'basic':
return False
More information about the bazaar-commits
mailing list