~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http.py

  • Committer: Robert J. Tanner
  • Date: 2009-04-29 05:53:21 UTC
  • mfrom: (4311 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4312.
  • Revision ID: tanner@real-time.com-20090429055321-v2s5l1mgki9f6cgn
[merge] 1.14 back to trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
215
215
 
216
216
class TestAuthHeader(tests.TestCase):
217
217
 
218
 
    def parse_header(self, header):
219
 
        ah =  _urllib2_wrappers.AbstractAuthHandler()
220
 
        return ah._parse_auth_header(header)
 
218
    def parse_header(self, header, auth_handler_class=None):
 
219
        if auth_handler_class is None:
 
220
            auth_handler_class = _urllib2_wrappers.AbstractAuthHandler
 
221
        self.auth_handler =  auth_handler_class()
 
222
        return self.auth_handler._parse_auth_header(header)
221
223
 
222
224
    def test_empty_header(self):
223
225
        scheme, remainder = self.parse_header('')
235
237
        self.assertEquals('basic', scheme)
236
238
        self.assertEquals('realm="Thou should not pass"', remainder)
237
239
 
 
240
    def test_basic_extract_realm(self):
 
241
        scheme, remainder = self.parse_header(
 
242
            'Basic realm="Thou should not pass"',
 
243
            _urllib2_wrappers.BasicAuthHandler)
 
244
        match, realm = self.auth_handler.extract_realm(remainder)
 
245
        self.assertTrue(match is not None)
 
246
        self.assertEquals('Thou should not pass', realm)
 
247
 
238
248
    def test_digest_header(self):
239
249
        scheme, remainder = self.parse_header(
240
250
            'Digest realm="Thou should not pass"')
1440
1450
 
1441
1451
    _auth_header = 'Authorization'
1442
1452
    _password_prompt_prefix = ''
 
1453
    _username_prompt_prefix = ''
1443
1454
 
1444
1455
    def setUp(self):
1445
1456
        super(TestAuth, self).setUp()
1514
1525
        # initial 'who are you' and 'this is not you, who are you')
1515
1526
        self.assertEqual(2, self.server.auth_required_errors)
1516
1527
 
 
1528
    def test_prompt_for_username(self):
 
1529
        if self._testing_pycurl():
 
1530
            raise tests.TestNotApplicable(
 
1531
                'pycurl cannot prompt, it handles auth by embedding'
 
1532
                ' user:pass in urls only')
 
1533
 
 
1534
        self.server.add_user('joe', 'foo')
 
1535
        t = self.get_user_transport(None, None)
 
1536
        stdout = tests.StringIOWrapper()
 
1537
        ui.ui_factory = tests.TestUIFactory(stdin='joe\nfoo\n', stdout=stdout)
 
1538
        self.assertEqual('contents of a\n',t.get('a').read())
 
1539
        # stdin should be empty
 
1540
        self.assertEqual('', ui.ui_factory.stdin.readline())
 
1541
        stdout.seek(0)
 
1542
        expected_prompt = self._expected_username_prompt(t._unqualified_scheme)
 
1543
        self.assertEquals(expected_prompt, stdout.read(len(expected_prompt)))
 
1544
        self._check_password_prompt(t._unqualified_scheme, 'joe',
 
1545
                                    stdout.readline())
 
1546
 
1517
1547
    def test_prompt_for_password(self):
1518
1548
        if self._testing_pycurl():
1519
1549
            raise tests.TestNotApplicable(
1546
1576
                                 self.server.auth_realm)))
1547
1577
        self.assertEquals(expected_prompt, actual_prompt)
1548
1578
 
 
1579
    def _expected_username_prompt(self, scheme):
 
1580
        return (self._username_prompt_prefix
 
1581
                + "%s %s:%d, Realm: '%s' username: " % (scheme.upper(),
 
1582
                                 self.server.host, self.server.port,
 
1583
                                 self.server.auth_realm))
 
1584
 
1549
1585
    def test_no_prompt_for_password_when_using_auth_config(self):
1550
1586
        if self._testing_pycurl():
1551
1587
            raise tests.TestNotApplicable(
1617
1653
    """Test proxy authentication schemes."""
1618
1654
 
1619
1655
    _auth_header = 'Proxy-authorization'
1620
 
    _password_prompt_prefix='Proxy '
 
1656
    _password_prompt_prefix = 'Proxy '
 
1657
    _username_prompt_prefix = 'Proxy '
1621
1658
 
1622
1659
    def setUp(self):
1623
1660
        super(TestProxyAuth, self).setUp()