1604
1604
ui.ui_factory = tests.TestUIFactory(stdin=stdin_content,
1605
1605
stderr=tests.StringIOWrapper())
1606
1606
# Create a minimal config file with the right password
1607
conf = config.AuthenticationConfig()
1608
conf._get_config().update(
1609
{'httptest': {'scheme': 'http', 'port': self.server.port,
1610
'user': user, 'password': password}})
1607
_setup_authentication_config(
1609
port=self.server.port,
1612
1612
# Issue a request to the server to connect
1613
1613
self.assertEqual('contents of a\n',t.get('a').read())
1614
1614
# stdin should have been left untouched
1616
1616
# Only one 'Authentication Required' error should occur
1617
1617
self.assertEqual(1, self.server.auth_required_errors)
1619
def test_user_from_auth_conf(self):
1620
if self._testing_pycurl():
1621
raise tests.TestNotApplicable(
1622
'pycurl does not support authentication.conf')
1625
self.server.add_user(user, password)
1626
# Create a minimal config file with the right password
1627
conf = config.AuthenticationConfig()
1628
conf._get_config().update(
1629
{'httptest': {'scheme': 'http', 'port': self.server.port,
1630
'user': user, 'password': password}})
1632
t = self.get_user_transport(None, None)
1633
# Issue a request to the server to connect
1634
self.assertEqual('contents of a\n', t.get('a').read())
1635
# Only one 'Authentication Required' error should occur
1636
self.assertEqual(1, self.server.auth_required_errors)
1638
1619
def test_changing_nonce(self):
1639
1620
if self._auth_server not in (http_utils.HTTPDigestAuthServer,
1640
1621
http_utils.ProxyDigestAuthServer):
1656
1637
# initial 'who are you' and a second 'who are you' with the new nonce)
1657
1638
self.assertEqual(2, self.server.auth_required_errors)
1640
def test_user_from_auth_conf(self):
1641
if self._testing_pycurl():
1642
raise tests.TestNotApplicable(
1643
'pycurl does not support authentication.conf')
1646
self.server.add_user(user, password)
1647
_setup_authentication_config(
1649
port=self.server.port,
1652
t = self.get_user_transport(None, None)
1653
# Issue a request to the server to connect
1654
self.assertEqual('contents of a\n', t.get('a').read())
1655
# Only one 'Authentication Required' error should occur
1656
self.assertEqual(1, self.server.auth_required_errors)
1659
def _setup_authentication_config(**kwargs):
1660
conf = config.AuthenticationConfig()
1661
conf._get_config().update({'httptest': kwargs})
1666
class TestUrllib2AuthHandler(tests.TestCaseWithTransport):
1667
"""Unit tests for glue by which urllib2 asks us for authentication"""
1669
def test_get_user_password_without_port(self):
1670
"""We cope if urllib2 doesn't tell us the port.
1672
See https://bugs.launchpad.net/bzr/+bug/654684
1676
_setup_authentication_config(
1681
handler = _urllib2_wrappers.HTTPAuthHandler()
1682
got_pass = handler.get_user_password(dict(
1689
self.assertEquals((user, password), got_pass)
1661
1692
class TestProxyAuth(TestAuth):