64
64
from bzrlib.transport.http._pycurl import PyCurlTransport
67
def load_tests(standard_tests, module, loader):
68
"""Multiply tests for http clients and protocol versions."""
69
result = loader.suiteClass()
71
# one for each transport implementation
72
t_tests, remaining_tests = tests.split_suite_by_condition(
73
standard_tests, tests.condition_isinstance((
74
TestHttpTransportRegistration,
75
TestHttpTransportUrls,
67
load_tests = load_tests_apply_scenarios
70
def vary_by_http_client_implementation():
71
"""Test the two libraries we can use, pycurl and urllib."""
78
72
transport_scenarios = [
79
73
('urllib', dict(_transport=_urllib.HttpTransport_urllib,
80
74
_server=http_server.HttpServer_urllib,
85
79
('pycurl', dict(_transport=PyCurlTransport,
86
80
_server=http_server.HttpServer_PyCurl,
87
81
_url_protocol='http+pycurl',)))
88
tests.multiply_tests(t_tests, transport_scenarios, result)
90
protocol_scenarios = [
91
('HTTP/1.0', dict(_protocol_version='HTTP/1.0')),
92
('HTTP/1.1', dict(_protocol_version='HTTP/1.1')),
95
# some tests are parametrized by the protocol version only
96
p_tests, remaining_tests = tests.split_suite_by_condition(
97
remaining_tests, tests.condition_isinstance((
100
tests.multiply_tests(p_tests, protocol_scenarios, result)
102
# each implementation tested with each HTTP version
103
tp_tests, remaining_tests = tests.split_suite_by_condition(
104
remaining_tests, tests.condition_isinstance((
105
SmartHTTPTunnellingTest,
106
TestDoCatchRedirections,
108
TestHTTPRedirections,
109
TestHTTPSilentRedirections,
110
TestLimitedRangeRequestServer,
114
TestSpecificRequestHandler,
116
tp_scenarios = tests.multiply_scenarios(transport_scenarios,
118
tests.multiply_tests(tp_tests, tp_scenarios, result)
120
# proxy auth: each auth scheme on all http versions on all implementations.
121
tppa_tests, remaining_tests = tests.split_suite_by_condition(
122
remaining_tests, tests.condition_isinstance((
125
proxy_auth_scheme_scenarios = [
82
return transport_scenarios
85
def vary_by_http_protocol_version():
86
"""Test on http/1.0 and 1.1"""
88
('HTTP/1.0', dict(_protocol_version='HTTP/1.0')),
89
('HTTP/1.1', dict(_protocol_version='HTTP/1.1')),
93
def vary_by_http_proxy_auth_scheme():
126
95
('basic', dict(_auth_server=http_utils.ProxyBasicAuthServer)),
127
96
('digest', dict(_auth_server=http_utils.ProxyDigestAuthServer)),
129
dict(_auth_server=http_utils.ProxyBasicAndDigestAuthServer)),
98
dict(_auth_server=http_utils.ProxyBasicAndDigestAuthServer)),
131
tppa_scenarios = tests.multiply_scenarios(tp_scenarios,
132
proxy_auth_scheme_scenarios)
133
tests.multiply_tests(tppa_tests, tppa_scenarios, result)
135
# auth: each auth scheme on all http versions on all implementations.
136
tpa_tests, remaining_tests = tests.split_suite_by_condition(
137
remaining_tests, tests.condition_isinstance((
140
auth_scheme_scenarios = [
102
def vary_by_http_auth_scheme():
141
104
('basic', dict(_auth_server=http_utils.HTTPBasicAuthServer)),
142
105
('digest', dict(_auth_server=http_utils.HTTPDigestAuthServer)),
144
dict(_auth_server=http_utils.HTTPBasicAndDigestAuthServer)),
107
dict(_auth_server=http_utils.HTTPBasicAndDigestAuthServer)),
146
tpa_scenarios = tests.multiply_scenarios(tp_scenarios,
147
auth_scheme_scenarios)
148
tests.multiply_tests(tpa_tests, tpa_scenarios, result)
150
# activity: on all http[s] versions on all implementations
151
tpact_tests, remaining_tests = tests.split_suite_by_condition(
152
remaining_tests, tests.condition_isinstance((
111
def vary_by_http_activity():
155
112
activity_scenarios = [
156
113
('urllib,http', dict(_activity_server=ActivityHTTPServer,
157
_transport=_urllib.HttpTransport_urllib,)),
114
_transport=_urllib.HttpTransport_urllib,)),
159
116
if tests.HTTPSServerFeature.available():
160
117
activity_scenarios.append(
161
118
('urllib,https', dict(_activity_server=ActivityHTTPSServer,
162
_transport=_urllib.HttpTransport_urllib,)),)
119
_transport=_urllib.HttpTransport_urllib,)),)
163
120
if features.pycurl.available():
164
121
activity_scenarios.append(
165
122
('pycurl,http', dict(_activity_server=ActivityHTTPServer,
166
_transport=PyCurlTransport,)),)
123
_transport=PyCurlTransport,)),)
167
124
if tests.HTTPSServerFeature.available():
168
125
from bzrlib.tests import (
1610
1619
# Only one 'Authentication Required' error should occur
1611
1620
self.assertEqual(1, self.server.auth_required_errors)
1613
def test_user_from_auth_conf(self):
1614
if self._testing_pycurl():
1615
raise tests.TestNotApplicable(
1616
'pycurl does not support authentication.conf')
1619
self.server.add_user(user, password)
1620
# Create a minimal config file with the right password
1621
conf = config.AuthenticationConfig()
1622
conf._get_config().update(
1623
{'httptest': {'scheme': 'http', 'port': self.server.port,
1624
'user': user, 'password': password}})
1626
t = self.get_user_transport(None, None)
1627
# Issue a request to the server to connect
1628
self.assertEqual('contents of a\n', t.get('a').read())
1629
# Only one 'Authentication Required' error should occur
1630
self.assertEqual(1, self.server.auth_required_errors)
1632
1622
def test_changing_nonce(self):
1633
1623
if self._auth_server not in (http_utils.HTTPDigestAuthServer,
1634
1624
http_utils.ProxyDigestAuthServer):
1650
1640
# initial 'who are you' and a second 'who are you' with the new nonce)
1651
1641
self.assertEqual(2, self.server.auth_required_errors)
1643
def test_user_from_auth_conf(self):
1644
if self._testing_pycurl():
1645
raise tests.TestNotApplicable(
1646
'pycurl does not support authentication.conf')
1649
self.server.add_user(user, password)
1650
_setup_authentication_config(
1652
port=self.server.port,
1655
t = self.get_user_transport(None, None)
1656
# Issue a request to the server to connect
1657
self.assertEqual('contents of a\n', t.get('a').read())
1658
# Only one 'Authentication Required' error should occur
1659
self.assertEqual(1, self.server.auth_required_errors)
1662
def _setup_authentication_config(**kwargs):
1663
conf = config.AuthenticationConfig()
1664
conf._get_config().update({'httptest': kwargs})
1669
class TestUrllib2AuthHandler(tests.TestCaseWithTransport):
1670
"""Unit tests for glue by which urllib2 asks us for authentication"""
1672
def test_get_user_password_without_port(self):
1673
"""We cope if urllib2 doesn't tell us the port.
1675
See https://bugs.launchpad.net/bzr/+bug/654684
1679
_setup_authentication_config(
1684
handler = _urllib2_wrappers.HTTPAuthHandler()
1685
got_pass = handler.get_user_password(dict(
1692
self.assertEquals((user, password), got_pass)
1655
1695
class TestProxyAuth(TestAuth):
1656
1696
"""Test proxy authentication schemes."""
1698
scenarios = multiply_scenarios(
1699
vary_by_http_client_implementation(),
1700
vary_by_http_protocol_version(),
1701
vary_by_http_proxy_auth_scheme(),
1658
1704
_auth_header = 'Proxy-authorization'
1659
1705
_password_prompt_prefix = 'Proxy '
1660
1706
_username_prompt_prefix = 'Proxy '