~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-04-10 19:37:20 UTC
  • mfrom: (4222.3.15 username)
  • Revision ID: pqm@pqm.ubuntu.com-20090410193720-nyej7ft1k2yoyhui
(Jelmer) Prompt for user names for http if they are not in the
        configuration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1440
1440
 
1441
1441
    _auth_header = 'Authorization'
1442
1442
    _password_prompt_prefix = ''
 
1443
    _username_prompt_prefix = ''
1443
1444
 
1444
1445
    def setUp(self):
1445
1446
        super(TestAuth, self).setUp()
1514
1515
        # initial 'who are you' and 'this is not you, who are you')
1515
1516
        self.assertEqual(2, self.server.auth_required_errors)
1516
1517
 
 
1518
    def test_prompt_for_username(self):
 
1519
        if self._testing_pycurl():
 
1520
            raise tests.TestNotApplicable(
 
1521
                'pycurl cannot prompt, it handles auth by embedding'
 
1522
                ' user:pass in urls only')
 
1523
 
 
1524
        self.server.add_user('joe', 'foo')
 
1525
        t = self.get_user_transport(None, None)
 
1526
        stdout = tests.StringIOWrapper()
 
1527
        ui.ui_factory = tests.TestUIFactory(stdin='joe\nfoo\n', stdout=stdout)
 
1528
        self.assertEqual('contents of a\n',t.get('a').read())
 
1529
        # stdin should be empty
 
1530
        self.assertEqual('', ui.ui_factory.stdin.readline())
 
1531
        stdout.seek(0)
 
1532
        expected_prompt = self._expected_username_prompt(t._unqualified_scheme)
 
1533
        self.assertEquals(expected_prompt, stdout.read(len(expected_prompt)))
 
1534
        self._check_password_prompt(t._unqualified_scheme, 'joe',
 
1535
                                    stdout.readline())
 
1536
 
1517
1537
    def test_prompt_for_password(self):
1518
1538
        if self._testing_pycurl():
1519
1539
            raise tests.TestNotApplicable(
1546
1566
                                 self.server.auth_realm)))
1547
1567
        self.assertEquals(expected_prompt, actual_prompt)
1548
1568
 
 
1569
    def _expected_username_prompt(self, scheme):
 
1570
        return (self._username_prompt_prefix
 
1571
                + "%s %s:%d, Realm: '%s' username: " % (scheme.upper(),
 
1572
                                 self.server.host, self.server.port,
 
1573
                                 self.server.auth_realm))
 
1574
 
1549
1575
    def test_no_prompt_for_password_when_using_auth_config(self):
1550
1576
        if self._testing_pycurl():
1551
1577
            raise tests.TestNotApplicable(
1617
1643
    """Test proxy authentication schemes."""
1618
1644
 
1619
1645
    _auth_header = 'Proxy-authorization'
1620
 
    _password_prompt_prefix='Proxy '
 
1646
    _password_prompt_prefix = 'Proxy '
 
1647
    _username_prompt_prefix = 'Proxy '
1621
1648
 
1622
1649
    def setUp(self):
1623
1650
        super(TestProxyAuth, self).setUp()