94
def vary_by_http_auth_scheme():
96
('basic', dict(_auth_server=http_utils.HTTPBasicAuthServer)),
97
('digest', dict(_auth_server=http_utils.HTTPDigestAuthServer)),
99
dict(_auth_server=http_utils.HTTPBasicAndDigestAuthServer)),
101
# Add some attributes common to all scenarios
102
for scenario_id, scenario_dict in scenarios:
103
scenario_dict.update(_username_prompt_prefix='',
104
_password_prompt_prefix='')
94
108
def vary_by_http_proxy_auth_scheme():
96
110
('basic', dict(_auth_server=http_utils.ProxyBasicAuthServer)),
97
111
('digest', dict(_auth_server=http_utils.ProxyDigestAuthServer)),
99
113
dict(_auth_server=http_utils.ProxyBasicAndDigestAuthServer)),
103
def vary_by_http_auth_scheme():
105
('basic', dict(_auth_server=http_utils.HTTPBasicAuthServer)),
106
('digest', dict(_auth_server=http_utils.HTTPDigestAuthServer)),
108
dict(_auth_server=http_utils.HTTPBasicAndDigestAuthServer)),
115
# Add some attributes common to all scenarios
116
for scenario_id, scenario_dict in scenarios:
117
scenario_dict.update(_username_prompt_prefix='Proxy ',
118
_password_prompt_prefix='Proxy ')
112
122
def vary_by_http_activity():
1489
1499
self.get_a, self.old_transport, redirected)
1502
def _setup_authentication_config(**kwargs):
1503
conf = config.AuthenticationConfig()
1504
conf._get_config().update({'httptest': kwargs})
1508
class TestUrllib2AuthHandler(tests.TestCaseWithTransport):
1509
"""Unit tests for glue by which urllib2 asks us for authentication"""
1511
def test_get_user_password_without_port(self):
1512
"""We cope if urllib2 doesn't tell us the port.
1514
See https://bugs.launchpad.net/bzr/+bug/654684
1518
_setup_authentication_config(scheme='http', host='localhost',
1519
user=user, password=password)
1520
handler = _urllib2_wrappers.HTTPAuthHandler()
1521
got_pass = handler.get_user_password(dict(
1528
self.assertEquals((user, password), got_pass)
1492
1531
class TestAuth(http_utils.TestCaseWithWebserver):
1493
1532
"""Test authentication scheme"""
1498
1537
vary_by_http_auth_scheme(),
1501
_auth_header = 'Authorization'
1502
_password_prompt_prefix = ''
1503
_username_prompt_prefix = ''
1507
1540
def setUp(self):
1508
1541
super(TestAuth, self).setUp()
1509
1542
self.server = self.get_readonly_server()
1650
1683
ui.ui_factory = tests.TestUIFactory(stdin=stdin_content,
1651
1684
stderr=tests.StringIOWrapper())
1652
1685
# Create a minimal config file with the right password
1653
_setup_authentication_config(
1655
port=self.server.port,
1686
_setup_authentication_config(scheme='http', port=self.server.port,
1687
user=user, password=password)
1658
1688
# Issue a request to the server to connect
1659
1689
self.assertEqual('contents of a\n',t.get('a').read())
1660
1690
# stdin should have been left untouched
1691
1721
password = 'foo'
1692
1722
self.server.add_user(user, password)
1693
_setup_authentication_config(
1695
port=self.server.port,
1723
_setup_authentication_config(scheme='http', port=self.server.port,
1724
user=user, password=password)
1698
1725
t = self.get_user_transport(None, None)
1699
1726
# Issue a request to the server to connect
1700
1727
self.assertEqual('contents of a\n', t.get('a').read())
1702
1729
self.assertEqual(1, self.server.auth_required_errors)
1705
def _setup_authentication_config(**kwargs):
1706
conf = config.AuthenticationConfig()
1707
conf._get_config().update({'httptest': kwargs})
1712
class TestUrllib2AuthHandler(tests.TestCaseWithTransport):
1713
"""Unit tests for glue by which urllib2 asks us for authentication"""
1715
def test_get_user_password_without_port(self):
1716
"""We cope if urllib2 doesn't tell us the port.
1718
See https://bugs.launchpad.net/bzr/+bug/654684
1722
_setup_authentication_config(
1727
handler = _urllib2_wrappers.HTTPAuthHandler()
1728
got_pass = handler.get_user_password(dict(
1735
self.assertEquals((user, password), got_pass)
1738
1732
class TestProxyAuth(TestAuth):
1739
"""Test proxy authentication schemes."""
1733
"""Test proxy authentication schemes.
1735
This inherits from TestAuth to tweak the setUp and filter some failing
1741
1739
scenarios = multiply_scenarios(
1742
1740
vary_by_http_client_implementation(),
1744
1742
vary_by_http_proxy_auth_scheme(),
1747
_auth_header = 'Proxy-authorization'
1748
_password_prompt_prefix = 'Proxy '
1749
_username_prompt_prefix = 'Proxy '
1751
1745
def setUp(self):
1752
1746
super(TestProxyAuth, self).setUp()
1753
1747
# Override the contents to avoid false positives