~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: 2010-12-02 14:58:47 UTC
  • mfrom: (5554.1.3 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20101202145847-fw822sd3nyhvrwmi
(vila) Merge 2.2 into trunk including fix for bug #583667 and bug
        #681885 (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011 Canonical Ltd
 
1
# Copyright (C) 2005-2010 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
from cStringIO import StringIO
 
18
import errno
18
19
import re
 
20
import socket
 
21
import threading
 
22
import time
19
23
import urllib2
 
24
import urlparse
20
25
 
21
26
 
22
27
from bzrlib import (
27
32
    )
28
33
from bzrlib.smart import (
29
34
    medium,
 
35
    protocol,
30
36
    )
31
37
from bzrlib.tests import http_server
32
38
from bzrlib.transport import chroot
51
57
 
52
58
    def do_POST(self):
53
59
        """Hand the request off to a smart server instance."""
54
 
        backing = transport.get_transport_from_path(
 
60
        backing = transport.get_transport(
55
61
            self.server.test_case_server._home_dir)
56
62
        chroot_server = chroot.ChrootServer(backing)
57
63
        chroot_server.start_server()
58
64
        try:
59
 
            t = transport.get_transport_from_url(chroot_server.get_url())
 
65
            t = transport.get_transport(chroot_server.get_url())
60
66
            self.do_POST_inner(t)
61
67
        finally:
62
68
            chroot_server.stop_server()
153
159
        return self._adjust_url(base, relpath)
154
160
 
155
161
    def get_secondary_transport(self, relpath=None):
156
 
        t = transport.get_transport_from_url(self.get_secondary_url(relpath))
 
162
        t = transport.get_transport(self.get_secondary_url(relpath))
157
163
        self.assertTrue(t.is_readonly())
158
164
        return t
159
165
 
257
263
        return self._adjust_url(base, relpath)
258
264
 
259
265
   def get_old_transport(self, relpath=None):
260
 
        t = transport.get_transport_from_url(self.get_old_url(relpath))
 
266
        t = transport.get_transport(self.get_old_url(relpath))
261
267
        self.assertTrue(t.is_readonly())
262
268
        return t
263
269
 
266
272
        return self._adjust_url(base, relpath)
267
273
 
268
274
   def get_new_transport(self, relpath=None):
269
 
        t = transport.get_transport_from_url(self.get_new_url(relpath))
 
275
        t = transport.get_transport(self.get_new_url(relpath))
270
276
        self.assertTrue(t.is_readonly())
271
277
        return t
272
278
 
284
290
    # - auth_header_recv: the header received containing auth
285
291
    # - auth_error_code: the error code to indicate auth required
286
292
 
287
 
    def _require_authentication(self):
288
 
        # Note that we must update test_case_server *before*
289
 
        # sending the error or the client may try to read it
290
 
        # before we have sent the whole error back.
291
 
        tcs = self.server.test_case_server
292
 
        tcs.auth_required_errors += 1
293
 
        self.send_response(tcs.auth_error_code)
294
 
        self.send_header_auth_reqed()
295
 
        # We do not send a body
296
 
        self.send_header('Content-Length', '0')
297
 
        self.end_headers()
298
 
        return
299
 
 
300
293
    def do_GET(self):
301
294
        if self.authorized():
302
295
            return http_server.TestingHTTPRequestHandler.do_GET(self)
303
296
        else:
304
 
            return self._require_authentication()
305
 
 
306
 
    def do_HEAD(self):
307
 
        if self.authorized():
308
 
            return http_server.TestingHTTPRequestHandler.do_HEAD(self)
309
 
        else:
310
 
            return self._require_authentication()
 
297
            # Note that we must update test_case_server *before*
 
298
            # sending the error or the client may try to read it
 
299
            # before we have sent the whole error back.
 
300
            tcs = self.server.test_case_server
 
301
            tcs.auth_required_errors += 1
 
302
            self.send_response(tcs.auth_error_code)
 
303
            self.send_header_auth_reqed()
 
304
            # We do not send a body
 
305
            self.send_header('Content-Length', '0')
 
306
            self.end_headers()
 
307
            return
311
308
 
312
309
 
313
310
class BasicAuthRequestHandler(AuthRequestHandler):