47
47
from bzrlib.tests.HTTPTestUtil import (
48
48
BadProtocolRequestHandler,
49
49
BadStatusRequestHandler,
51
FakeProxyRequestHandler,
52
50
ForbiddenRequestHandler,
53
53
HTTPServerRedirecting,
54
54
InvalidStatusRequestHandler,
55
55
NoRangeRequestHandler,
56
ProxyBasicAuthHTTPServer,
57
ProxyDigestAuthServer,
57
59
SingleRangeRequestHandler,
58
60
TestCaseWithRedirectedWebserver,
59
61
TestCaseWithTwoWebservers,
788
790
"""Creates an http server that will serve files with
789
791
'-proxied' appended to their names.
791
return HttpServer(FakeProxyRequestHandler)
793
795
def _install_env(self, env):
794
796
for name, value in env.iteritems():
1216
1218
self.assertEqual(1, self.server.auth_required_errors)
1219
class TestHTTPBasicAuth(TestHTTPAuth, TestCaseWithWebserver):
1220
"""Test basic http authentication scheme"""
1222
_transport = HttpTransport_urllib
1221
class TestHTTPAuth(TestAuth):
1222
"""Test HTTP authentication schemes.
1224
Daughter classes MUST inherit from TestCaseWithWebserver too.
1223
1227
_auth_header = 'Authorization'
1225
1229
def setUp(self):
1226
1230
TestCaseWithWebserver.setUp(self)
1227
1231
self.server = self.get_readonly_server()
1228
TestHTTPAuth.setUp(self)
1230
def create_transport_readonly_server(self):
1231
return BasicAuthHTTPServer()
1232
TestAuth.setUp(self)
1233
1234
def get_user_transport(self, user, password=None):
1234
1235
return self._transport(self.get_user_url(user, password))
1237
class TestHTTPProxyBasicAuth(TestHTTPAuth, TestCaseWithTwoWebservers):
1238
"""Test basic http authentication scheme"""
1238
class TestProxyAuth(TestAuth):
1239
"""Test proxy authentication schemes.
1240
_transport = HttpTransport_urllib
1241
Daughter classes MUST also inherit from TestCaseWithWebserver.
1241
1243
_auth_header = 'Proxy-authorization'
1243
1245
def setUp(self):
1244
TestCaseWithTwoWebservers.setUp(self)
1246
TestCaseWithWebserver.setUp(self)
1245
1247
self.server = self.get_readonly_server()
1246
1248
self._old_env = {}
1247
1249
self.addCleanup(self._restore_env)
1248
TestHTTPAuth.setUp(self)
1250
TestAuth.setUp(self)
1249
1251
# Override the contents to avoid false positives
1250
1252
self.build_tree_contents([('a', 'not proxied contents of a\n'),
1251
1253
('b', 'not proxied contents of b\n'),
1253
1255
('b-proxied', 'contents of b\n'),
1256
def create_transport_readonly_server(self):
1257
return ProxyBasicAuthHTTPServer()
1259
def _install_env(self, env):
1260
for name, value in env.iteritems():
1261
self._old_env[name] = osutils.set_or_unset_env(name, value)
1263
def _restore_env(self):
1264
for name, value in self._old_env.iteritems():
1265
osutils.set_or_unset_env(name, value)
1267
1258
def get_user_transport(self, user, password=None):
1268
1259
self._install_env({'all_proxy': self.get_user_url(user, password)})
1269
1260
return self._transport(self.server.get_url())
1262
def _install_env(self, env):
1263
for name, value in env.iteritems():
1264
self._old_env[name] = osutils.set_or_unset_env(name, value)
1266
def _restore_env(self):
1267
for name, value in self._old_env.iteritems():
1268
osutils.set_or_unset_env(name, value)
1271
class TestHTTPBasicAuth(TestHTTPAuth, TestCaseWithWebserver):
1272
"""Test http basic authentication scheme"""
1274
_transport = HttpTransport_urllib
1276
def create_transport_readonly_server(self):
1277
return HTTPBasicAuthServer()
1280
class TestHTTPProxyBasicAuth(TestProxyAuth, TestCaseWithWebserver):
1281
"""Test proxy basic authentication scheme"""
1283
_transport = HttpTransport_urllib
1285
def create_transport_readonly_server(self):
1286
return ProxyBasicAuthServer()
1289
class TestHTTPDigestAuth(TestHTTPAuth, TestCaseWithWebserver):
1290
"""Test http digest authentication scheme"""
1292
_transport = HttpTransport_urllib
1294
def create_transport_readonly_server(self):
1295
return HTTPDigestAuthServer()
1298
class TestHTTPProxyDigestAuth(TestProxyAuth, TestCaseWithWebserver):
1299
"""Test proxy digest authentication scheme"""
1301
_transport = HttpTransport_urllib
1303
def create_transport_readonly_server(self):
1304
return ProxyDigestAuthServer()