227
226
def parse_header(self, header, auth_handler_class=None):
228
227
if auth_handler_class is None:
229
auth_handler_class = _urllib2_wrappers.AbstractAuthHandler
228
auth_handler_class = http.AbstractAuthHandler
230
229
self.auth_handler = auth_handler_class()
231
230
return self.auth_handler._parse_auth_header(header)
247
246
self.assertEqual('realm="Thou should not pass"', remainder)
249
248
def test_build_basic_header_with_long_creds(self):
250
handler = _urllib2_wrappers.BasicAuthHandler()
249
handler = http.BasicAuthHandler()
251
250
user = 'user' * 10 # length 40
252
251
password = 'password' * 5 # length 40
253
252
header = handler.build_auth_header(
259
258
def test_basic_extract_realm(self):
260
259
scheme, remainder = self.parse_header(
261
260
'Basic realm="Thou should not pass"',
262
_urllib2_wrappers.BasicAuthHandler)
261
http.BasicAuthHandler)
263
262
match, realm = self.auth_handler.extract_realm(remainder)
264
263
self.assertTrue(match is not None)
265
264
self.assertEqual(u'Thou should not pass', realm)
1132
1131
def _proxied_request(self):
1133
handler = _urllib2_wrappers.ProxyHandler()
1134
request = _urllib2_wrappers.Request('GET', 'http://baz/buzzle')
1132
handler = http.ProxyHandler()
1133
request = http.Request('GET', 'http://baz/buzzle')
1135
1134
handler.set_proxy(request, 'http')
1138
1137
def assertEvaluateProxyBypass(self, expected, host, no_proxy):
1139
handler = _urllib2_wrappers.ProxyHandler()
1138
handler = http.ProxyHandler()
1140
1139
self.assertEqual(expected,
1141
1140
handler.evaluate_proxy_bypass(host, no_proxy))
1328
1327
self.get_new_transport().get('a').read())
1331
class RedirectedRequest(_urllib2_wrappers.Request):
1330
class RedirectedRequest(http.Request):
1332
1331
"""Request following redirections. """
1334
init_orig = _urllib2_wrappers.Request.__init__
1333
init_orig = http.Request.__init__
1336
1335
def __init__(self, method, url, *args, **kwargs):
1337
1336
"""Constructor.
1340
1339
# Since the tests using this class will replace
1341
# _urllib2_wrappers.Request, we can't just call the base class __init__
1340
# http.Request, we can't just call the base class __init__
1342
1341
# or we'll loop.
1343
1342
RedirectedRequest.init_orig(self, method, url, *args, **kwargs)
1344
1343
self.follow_redirections = True
1347
1346
def install_redirected_request(test):
1348
test.overrideAttr(_urllib2_wrappers, 'Request', RedirectedRequest)
1347
test.overrideAttr(http, 'Request', RedirectedRequest)
1351
1350
def cleanup_http_redirection_connections(test):
1352
1351
# Some sockets are opened but never seen by _urllib, so we trap them at
1353
# the _urllib2_wrappers level to be able to clean them up.
1352
# the http level to be able to clean them up.
1354
1353
def socket_disconnect(sock):
1356
1355
sock.shutdown(socket.SHUT_RDWR)
1362
1361
test.http_connect_orig(connection)
1363
1362
test.addCleanup(socket_disconnect, connection.sock)
1364
1363
test.http_connect_orig = test.overrideAttr(
1365
_urllib2_wrappers.HTTPConnection, 'connect', connect)
1364
http.HTTPConnection, 'connect', connect)
1367
1366
def connect(connection):
1368
1367
test.https_connect_orig(connection)
1369
1368
test.addCleanup(socket_disconnect, connection.sock)
1370
1369
test.https_connect_orig = test.overrideAttr(
1371
_urllib2_wrappers.HTTPSConnection, 'connect', connect)
1370
http.HTTPSConnection, 'connect', connect)
1374
1373
class TestHTTPSilentRedirections(http_utils.TestCaseWithRedirectedWebserver):
1377
1376
http implementations do not redirect silently anymore (they
1378
1377
do not redirect at all in fact). The mechanism is still in
1379
place at the _urllib2_wrappers.Request level and these tests
1378
place at the http.Request level and these tests
1498
1497
password = 'foo'
1499
1498
_setup_authentication_config(scheme='http', host='localhost',
1500
1499
user=user, password=password)
1501
handler = _urllib2_wrappers.HTTPAuthHandler()
1500
handler = http.HTTPAuthHandler()
1502
1501
got_pass = handler.get_user_password(dict(
1504
1503
protocol='http',