~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/http_utils.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-07-17 09:40:51 UTC
  • mfrom: (3518.1.2 virtualvf)
  • Revision ID: pqm@pqm.ubuntu.com-20080717094051-cgyo1zagozwcd4mm
(Jelmer) Add VirtualVersionedFiles class.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005 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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
from cStringIO import StringIO
18
18
import errno
 
19
import md5
19
20
import re
 
21
import sha
20
22
import socket
21
23
import threading
22
24
import time
23
25
import urllib2
24
26
import urlparse
25
27
 
26
 
 
27
28
from bzrlib import (
28
29
    errors,
29
 
    osutils,
30
30
    tests,
 
31
    transport,
31
32
    )
32
33
from bzrlib.smart import medium, protocol
33
34
from bzrlib.tests import http_server
34
 
from bzrlib.transport import (
35
 
    chroot,
36
 
    get_transport,
37
 
    )
38
35
 
39
36
 
40
37
class HTTPServerWithSmarts(http_server.HttpServer):
49
46
 
50
47
 
51
48
class SmartRequestHandler(http_server.TestingHTTPRequestHandler):
52
 
    """Extend TestingHTTPRequestHandler to support smart client POSTs.
53
 
 
54
 
    XXX: This duplicates a fair bit of the logic in bzrlib.transport.http.wsgi.
55
 
    """
 
49
    """Extend TestingHTTPRequestHandler to support smart client POSTs."""
56
50
 
57
51
    def do_POST(self):
58
52
        """Hand the request off to a smart server instance."""
59
 
        backing = get_transport(self.server.test_case_server._home_dir)
60
 
        chroot_server = chroot.ChrootServer(backing)
61
 
        chroot_server.start_server()
62
 
        try:
63
 
            t = get_transport(chroot_server.get_url())
64
 
            self.do_POST_inner(t)
65
 
        finally:
66
 
            chroot_server.stop_server()
67
 
 
68
 
    def do_POST_inner(self, chrooted_transport):
69
53
        self.send_response(200)
70
54
        self.send_header("Content-type", "application/octet-stream")
71
 
        if not self.path.endswith('.bzr/smart'):
72
 
            raise AssertionError(
73
 
                'POST to path not ending in .bzr/smart: %r' % (self.path,))
74
 
        t = chrooted_transport.clone(self.path[:-len('.bzr/smart')])
 
55
        t = transport.get_transport(self.server.test_case_server._home_dir)
75
56
        # if this fails, we should return 400 bad request, but failure is
76
57
        # failure for now - RBC 20060919
77
58
        data_length = int(self.headers['Content-Length'])
133
114
        """Get the server instance for the secondary transport."""
134
115
        if self.__secondary_server is None:
135
116
            self.__secondary_server = self.create_transport_secondary_server()
136
 
            self.start_server(self.__secondary_server)
 
117
            self.__secondary_server.setUp()
 
118
            self.addCleanup(self.__secondary_server.tearDown)
137
119
        return self.__secondary_server
138
120
 
139
121
 
296
278
 
297
279
    def authorized(self):
298
280
        tcs = self.server.test_case_server
 
281
        if tcs.auth_scheme != 'digest':
 
282
            return False
299
283
 
300
284
        auth_header = self.headers.get(tcs.auth_header_recv, None)
301
285
        if auth_header is None:
316
300
        self.send_header(tcs.auth_header_sent,header)
317
301
 
318
302
 
319
 
class DigestAndBasicAuthRequestHandler(DigestAuthRequestHandler):
320
 
    """Implements a digest and basic authentication of a request.
321
 
 
322
 
    I.e. the server proposes both schemes and the client should choose the best
323
 
    one it can handle, which, in that case, should be digest, the only scheme
324
 
    accepted here.
325
 
    """
326
 
 
327
 
    def send_header_auth_reqed(self):
328
 
        tcs = self.server.test_case_server
329
 
        self.send_header(tcs.auth_header_sent,
330
 
                         'Basic realm="%s"' % tcs.auth_realm)
331
 
        header = 'Digest realm="%s", ' % tcs.auth_realm
332
 
        header += 'nonce="%s", algorithm="%s", qop="auth"' % (tcs.auth_nonce,
333
 
                                                              'MD5')
334
 
        self.send_header(tcs.auth_header_sent,header)
335
 
 
336
 
 
337
303
class AuthServer(http_server.HttpServer):
338
304
    """Extends HttpServer with a dictionary of passwords.
339
305
 
412
378
        A1 = '%s:%s:%s' % (user, realm, password)
413
379
        A2 = '%s:%s' % (command, auth['uri'])
414
380
 
415
 
        H = lambda x: osutils.md5(x).hexdigest()
 
381
        H = lambda x: md5.new(x).hexdigest()
416
382
        KD = lambda secret, data: H("%s:%s" % (secret, data))
417
383
 
418
384
        nonce_count = int(auth['nc'], 16)
425
391
 
426
392
        return response_digest == auth['response']
427
393
 
428
 
 
429
394
class HTTPAuthServer(AuthServer):
430
395
    """An HTTP server requiring authentication"""
431
396
 
463
428
        self.init_http_auth()
464
429
 
465
430
 
466
 
class HTTPBasicAndDigestAuthServer(DigestAuthServer, HTTPAuthServer):
467
 
    """An HTTP server requiring basic or digest authentication"""
468
 
 
469
 
    def __init__(self, protocol_version=None):
470
 
        DigestAuthServer.__init__(self, DigestAndBasicAuthRequestHandler,
471
 
                                  'basicdigest',
472
 
                                  protocol_version=protocol_version)
473
 
        self.init_http_auth()
474
 
        # We really accept Digest only
475
 
        self.auth_scheme = 'digest'
476
 
 
477
 
 
478
431
class ProxyBasicAuthServer(ProxyAuthServer):
479
432
    """A proxy server requiring basic authentication"""
480
433
 
493
446
        self.init_proxy_auth()
494
447
 
495
448
 
496
 
class ProxyBasicAndDigestAuthServer(DigestAuthServer, ProxyAuthServer):
497
 
    """An proxy server requiring basic or digest authentication"""
498
 
 
499
 
    def __init__(self, protocol_version=None):
500
 
        DigestAuthServer.__init__(self, DigestAndBasicAuthRequestHandler,
501
 
                                  'basicdigest',
502
 
                                  protocol_version=protocol_version)
503
 
        self.init_proxy_auth()
504
 
        # We really accept Digest only
505
 
        self.auth_scheme = 'digest'
506
 
 
507