~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/transport_util.py

  • Committer: Vincent Ladeuil
  • Date: 2009-05-04 14:48:21 UTC
  • mto: (4349.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4350.
  • Revision ID: v.ladeuil+lp@free.fr-20090504144821-39dvqkikmd3zqkdg
Handle servers proposing several authentication schemes.

* bzrlib/transport/http/_urllib2_wrappers.py:
(AbstractAuthHandler.auth_required): Several schemes can be
proposed by the server, try to match each one in turn.
(BasicAuthHandler.auth_match): Delete dead code.

* bzrlib/tests/test_http.py:
(load_tests): Separate proxy and http authentication tests as they
require different server setups.
(TestAuth.create_transport_readonly_server): Simplified by using
parameter provided by load_tests.
(TestAuth.test_changing_nonce): Adapt to new parametrization.
(TestProxyAuth.create_transport_readonly_server): Deleted.

* bzrlib/tests/http_utils.py:
(DigestAndBasicAuthRequestHandler, HTTPBasicAndDigestAuthServer,
ProxyBasicAndDigestAuthServer): Add a test server proposing both
basic and digest auth schemes but accepting only digest as valid.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
import bzrlib.hooks
18
 
from bzrlib import transport
19
 
from bzrlib.tests import features
20
18
 
21
19
# SFTPTransport offers better performances but relies on paramiko, if paramiko
22
20
# is not available, we fallback to FtpTransport
23
 
if features.paramiko.available():
24
 
    from bzrlib.tests import test_sftp_transport
 
21
from bzrlib.tests import test_sftp_transport
 
22
if test_sftp_transport.paramiko_loaded:
25
23
    from bzrlib.transport import sftp
26
24
    _backing_scheme = 'sftp'
27
25
    _backing_transport_class = sftp.SFTPTransport
47
45
    """Dict-mapping hook name to a list of callables for transport hooks"""
48
46
 
49
47
    def __init__(self):
50
 
        super(TransportHooks, self).__init__("bzrlib.tests.transport_util",
51
 
            "InstrumentedTransport.hooks")
 
48
        super(TransportHooks, self).__init__()
52
49
        # Invoked when the transport has just created a new connection.
53
50
        # The api signature is (transport, connection, credentials)
54
51
        self['_set_connection'] = []
101
98
    def setUp(self):
102
99
        register_urlparse_netloc_protocol(_hooked_scheme)
103
100
        register_transport(_hooked_scheme, ConnectionHookedTransport)
104
 
        self.addCleanup(unregister_transport, _hooked_scheme,
105
 
                        ConnectionHookedTransport)
106
 
        self.addCleanup(_unregister_urlparse_netloc_protocol, _hooked_scheme)
 
101
 
 
102
        def unregister():
 
103
            unregister_transport(_hooked_scheme, ConnectionHookedTransport)
 
104
            _unregister_urlparse_netloc_protocol(_hooked_scheme)
 
105
 
 
106
        self.addCleanup(unregister)
107
107
        super(TestCaseWithConnectionHookedTransport, self).setUp()
108
108
        self.reset_connections()
109
 
        # Add the 'hooked' url to the permitted url list.
110
 
        # XXX: See TestCase.start_server. This whole module shouldn't need to
111
 
        # exist - a bug has been filed on that. once its cleanedup/removed, the
112
 
        # standard test support code will work and permit the server url
113
 
        # correctly.
114
 
        url = self.get_url()
115
 
        t = transport.get_transport(url)
116
 
        if t.base.endswith('work/'):
117
 
            t = t.clone('../..')
118
 
        self.permit_url(t.base)
119
109
 
120
110
    def get_url(self, relpath=None):
121
111
        super_self = super(TestCaseWithConnectionHookedTransport, self)
126
116
        return url
127
117
 
128
118
    def start_logging_connections(self):
129
 
        self.overrideAttr(InstrumentedTransport, 'hooks', TransportHooks())
130
 
        # We preserved the hooks class attribute. Now we install our hook.
131
119
        ConnectionHookedTransport.hooks.install_named_hook(
132
120
            '_set_connection', self._collect_connection, None)
 
121
        # uninstall our hooks when we are finished
 
122
        self.addCleanup(self.reset_hooks)
 
123
 
 
124
    def reset_hooks(self):
 
125
        InstrumentedTransport.hooks = TransportHooks()
133
126
 
134
127
    def reset_connections(self):
135
128
        self.connections = []