/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_http.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2021-01-10 01:31:27 UTC
  • mfrom: (7526.2.2 merge-3.1)
  • mto: This revision was merged to the branch mainline in revision 7532.
  • Revision ID: breezy.the.bot@gmail.com-20210110013127-vn6x2k2uv21p805n
Merge lp:brz/3.1

Merged from https://code.launchpad.net/~jelmer/brz/merge-3.1/+merge/396037

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
    multiply_scenarios,
58
58
    )
59
59
from ..transport import (
60
 
    http,
61
60
    remote,
62
61
    )
63
 
from ..transport.http import (
 
62
from ..transport.http import urllib
 
63
from ..transport.http.urllib import (
 
64
    AbstractAuthHandler,
 
65
    BasicAuthHandler,
64
66
    HttpTransport,
 
67
    HTTPAuthHandler,
 
68
    HTTPConnection,
 
69
    HTTPSConnection,
 
70
    ProxyHandler,
 
71
    Request,
65
72
    )
66
73
 
67
74
 
220
227
 
221
228
    def parse_header(self, header, auth_handler_class=None):
222
229
        if auth_handler_class is None:
223
 
            auth_handler_class = http.AbstractAuthHandler
 
230
            auth_handler_class = AbstractAuthHandler
224
231
        self.auth_handler = auth_handler_class()
225
232
        return self.auth_handler._parse_auth_header(header)
226
233
 
241
248
        self.assertEqual('realm="Thou should not pass"', remainder)
242
249
 
243
250
    def test_build_basic_header_with_long_creds(self):
244
 
        handler = http.BasicAuthHandler()
 
251
        handler = BasicAuthHandler()
245
252
        user = 'user' * 10  # length 40
246
253
        password = 'password' * 5  # length 40
247
254
        header = handler.build_auth_header(
253
260
    def test_basic_extract_realm(self):
254
261
        scheme, remainder = self.parse_header(
255
262
            'Basic realm="Thou should not pass"',
256
 
            http.BasicAuthHandler)
 
263
            BasicAuthHandler)
257
264
        match, realm = self.auth_handler.extract_realm(remainder)
258
265
        self.assertTrue(match is not None)
259
266
        self.assertEqual(u'Thou should not pass', realm)
509
516
        offsets = [(start, end - start + 1) for start, end in ranges]
510
517
        coalesce = transport.Transport._coalesce_offsets
511
518
        coalesced = list(coalesce(offsets, limit=0, fudge_factor=0))
512
 
        range_header = http.HttpTransport._range_header
 
519
        range_header = HttpTransport._range_header
513
520
        self.assertEqual(value, range_header(coalesced, tail))
514
521
 
515
522
    def test_range_header_single(self):
1124
1131
    """
1125
1132
 
1126
1133
    def _proxied_request(self):
1127
 
        handler = http.ProxyHandler()
1128
 
        request = http.Request('GET', 'http://baz/buzzle')
 
1134
        handler = ProxyHandler()
 
1135
        request = Request('GET', 'http://baz/buzzle')
1129
1136
        handler.set_proxy(request, 'http')
1130
1137
        return request
1131
1138
 
1132
1139
    def assertEvaluateProxyBypass(self, expected, host, no_proxy):
1133
 
        handler = http.ProxyHandler()
 
1140
        handler = ProxyHandler()
1134
1141
        self.assertEqual(expected,
1135
1142
                         handler.evaluate_proxy_bypass(host, no_proxy))
1136
1143
 
1322
1329
            self.get_new_transport().get('a').read())
1323
1330
 
1324
1331
 
1325
 
class RedirectedRequest(http.Request):
 
1332
class RedirectedRequest(Request):
1326
1333
    """Request following redirections. """
1327
1334
 
1328
 
    init_orig = http.Request.__init__
 
1335
    init_orig = Request.__init__
1329
1336
 
1330
1337
    def __init__(self, method, url, *args, **kwargs):
1331
1338
        """Constructor.
1332
1339
 
1333
1340
        """
1334
1341
        # Since the tests using this class will replace
1335
 
        # http.Request, we can't just call the base class __init__
 
1342
        # Request, we can't just call the base class __init__
1336
1343
        # or we'll loop.
1337
1344
        RedirectedRequest.init_orig(self, method, url, *args, **kwargs)
1338
1345
        self.follow_redirections = True
1339
1346
 
1340
1347
 
1341
1348
def install_redirected_request(test):
1342
 
    test.overrideAttr(http, 'Request', RedirectedRequest)
 
1349
    test.overrideAttr(urllib, 'Request', RedirectedRequest)
1343
1350
 
1344
1351
 
1345
1352
def cleanup_http_redirection_connections(test):
1356
1363
        test.http_connect_orig(connection)
1357
1364
        test.addCleanup(socket_disconnect, connection.sock)
1358
1365
    test.http_connect_orig = test.overrideAttr(
1359
 
        http.HTTPConnection, 'connect', connect)
 
1366
        HTTPConnection, 'connect', connect)
1360
1367
 
1361
1368
    def connect(connection):
1362
1369
        test.https_connect_orig(connection)
1363
1370
        test.addCleanup(socket_disconnect, connection.sock)
1364
1371
    test.https_connect_orig = test.overrideAttr(
1365
 
        http.HTTPSConnection, 'connect', connect)
 
1372
        HTTPSConnection, 'connect', connect)
1366
1373
 
1367
1374
 
1368
1375
class TestHTTPSilentRedirections(http_utils.TestCaseWithRedirectedWebserver):
1370
1377
 
1371
1378
    http implementations do not redirect silently anymore (they
1372
1379
    do not redirect at all in fact). The mechanism is still in
1373
 
    place at the http.Request level and these tests
 
1380
    place at the Request level and these tests
1374
1381
    exercise it.
1375
1382
    """
1376
1383
 
1494
1501
        password = 'foo'
1495
1502
        _setup_authentication_config(scheme='http', host='localhost',
1496
1503
                                     user=user, password=password)
1497
 
        handler = http.HTTPAuthHandler()
 
1504
        handler = HTTPAuthHandler()
1498
1505
        got_pass = handler.get_user_password(dict(
1499
1506
            user='joe',
1500
1507
            protocol='http',