~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-05-11 07:36:32 UTC
  • mfrom: (4349.1.1 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090511073632-ti658145fo07a4vw
Correctly handle http servers proposing multiple authentication
        schemes

Show diffs side-by-side

added added

removed removed

Lines of Context:
113
113
                                            protocol_scenarios)
114
114
    tests.multiply_tests(tp_tests, tp_scenarios, result)
115
115
 
 
116
    # proxy auth: each auth scheme on all http versions on all implementations.
 
117
    tppa_tests, remaining_tests = tests.split_suite_by_condition(
 
118
        remaining_tests, tests.condition_isinstance((
 
119
                TestProxyAuth,
 
120
                )))
 
121
    proxy_auth_scheme_scenarios = [
 
122
        ('basic', dict(_auth_server=http_utils.ProxyBasicAuthServer)),
 
123
        ('digest', dict(_auth_server=http_utils.ProxyDigestAuthServer)),
 
124
        ('basicdigest',
 
125
         dict(_auth_server=http_utils.ProxyBasicAndDigestAuthServer)),
 
126
        ]
 
127
    tppa_scenarios = tests.multiply_scenarios(tp_scenarios,
 
128
                                              proxy_auth_scheme_scenarios)
 
129
    tests.multiply_tests(tppa_tests, tppa_scenarios, result)
 
130
 
116
131
    # auth: each auth scheme on all http versions on all implementations.
117
132
    tpa_tests, remaining_tests = tests.split_suite_by_condition(
118
133
        remaining_tests, tests.condition_isinstance((
119
134
                TestAuth,
120
135
                )))
121
136
    auth_scheme_scenarios = [
122
 
        ('basic', dict(_auth_scheme='basic')),
123
 
        ('digest', dict(_auth_scheme='digest')),
 
137
        ('basic', dict(_auth_server=http_utils.HTTPBasicAuthServer)),
 
138
        ('digest', dict(_auth_server=http_utils.HTTPDigestAuthServer)),
 
139
        ('basicdigest',
 
140
         dict(_auth_server=http_utils.HTTPBasicAndDigestAuthServer)),
124
141
        ]
125
142
    tpa_scenarios = tests.multiply_scenarios(tp_scenarios,
126
 
        auth_scheme_scenarios)
 
143
                                             auth_scheme_scenarios)
127
144
    tests.multiply_tests(tpa_tests, tpa_scenarios, result)
128
145
 
129
146
    # activity: activity on all http versions on all implementations
1451
1468
    _auth_header = 'Authorization'
1452
1469
    _password_prompt_prefix = ''
1453
1470
    _username_prompt_prefix = ''
 
1471
    # Set by load_tests
 
1472
    _auth_server = None
1454
1473
 
1455
1474
    def setUp(self):
1456
1475
        super(TestAuth, self).setUp()
1459
1478
                                  ('b', 'contents of b\n'),])
1460
1479
 
1461
1480
    def create_transport_readonly_server(self):
1462
 
        if self._auth_scheme == 'basic':
1463
 
            server = http_utils.HTTPBasicAuthServer(
1464
 
                protocol_version=self._protocol_version)
1465
 
        else:
1466
 
            if self._auth_scheme != 'digest':
1467
 
                raise AssertionError('Unknown auth scheme: %r'
1468
 
                                     % self._auth_scheme)
1469
 
            server = http_utils.HTTPDigestAuthServer(
1470
 
                protocol_version=self._protocol_version)
1471
 
        return server
 
1481
        return self._auth_server(protocol_version=self._protocol_version)
1472
1482
 
1473
1483
    def _testing_pycurl(self):
1474
1484
        return pycurl_present and self._transport == PyCurlTransport
1628
1638
        self.assertEqual(1, self.server.auth_required_errors)
1629
1639
 
1630
1640
    def test_changing_nonce(self):
1631
 
        if self._auth_scheme != 'digest':
1632
 
            raise tests.TestNotApplicable('HTTP auth digest only test')
 
1641
        if self._auth_server not in (http_utils.HTTPDigestAuthServer,
 
1642
                                     http_utils.ProxyDigestAuthServer):
 
1643
            raise tests.TestNotApplicable('HTTP/proxy auth digest only test')
1633
1644
        if self._testing_pycurl():
1634
1645
            raise tests.KnownFailure(
1635
1646
                'pycurl does not handle a nonce change')
1667
1678
                                  ('b-proxied', 'contents of b\n'),
1668
1679
                                  ])
1669
1680
 
1670
 
    def create_transport_readonly_server(self):
1671
 
        if self._auth_scheme == 'basic':
1672
 
            server = http_utils.ProxyBasicAuthServer(
1673
 
                protocol_version=self._protocol_version)
1674
 
        else:
1675
 
            if self._auth_scheme != 'digest':
1676
 
                raise AssertionError('Unknown auth scheme: %r'
1677
 
                                     % self._auth_scheme)
1678
 
            server = http_utils.ProxyDigestAuthServer(
1679
 
                protocol_version=self._protocol_version)
1680
 
        return server
1681
 
 
1682
1681
    def get_user_transport(self, user, password):
1683
1682
        self._install_env({'all_proxy': self.get_user_url(user, password)})
1684
1683
        return self._transport(self.server.get_url())