1441
1441
_auth_header = 'Authorization'
1442
1442
_password_prompt_prefix = ''
1443
_username_prompt_prefix = ''
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)
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')
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())
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',
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)
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))
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."""
1619
1645
_auth_header = 'Proxy-authorization'
1620
_password_prompt_prefix='Proxy '
1646
_password_prompt_prefix = 'Proxy '
1647
_username_prompt_prefix = 'Proxy '
1622
1649
def setUp(self):
1623
1650
super(TestProxyAuth, self).setUp()