~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/http_utils.py

  • Committer: Mark Hammond
  • Date: 2009-01-12 01:55:34 UTC
  • mto: (3995.8.2 prepare-1.12)
  • mto: This revision was merged to the branch mainline in revision 4007.
  • Revision ID: mhammond@skippinet.com.au-20090112015534-yfxg50p7mpds9j4v
Include all .html files from the tortoise doc directory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
50
50
 
51
51
class SmartRequestHandler(http_server.TestingHTTPRequestHandler):
52
52
    """Extend TestingHTTPRequestHandler to support smart client POSTs.
53
 
 
 
53
    
54
54
    XXX: This duplicates a fair bit of the logic in bzrlib.transport.http.wsgi.
55
55
    """
56
56
 
58
58
        """Hand the request off to a smart server instance."""
59
59
        backing = get_transport(self.server.test_case_server._home_dir)
60
60
        chroot_server = chroot.ChrootServer(backing)
61
 
        chroot_server.start_server()
 
61
        chroot_server.setUp()
62
62
        try:
63
63
            t = get_transport(chroot_server.get_url())
64
64
            self.do_POST_inner(t)
65
65
        finally:
66
 
            chroot_server.stop_server()
 
66
            chroot_server.tearDown()
67
67
 
68
68
    def do_POST_inner(self, chrooted_transport):
69
69
        self.send_response(200)
133
133
        """Get the server instance for the secondary transport."""
134
134
        if self.__secondary_server is None:
135
135
            self.__secondary_server = self.create_transport_secondary_server()
136
 
            self.start_server(self.__secondary_server)
 
136
            self.__secondary_server.setUp()
 
137
            self.addCleanup(self.__secondary_server.tearDown)
137
138
        return self.__secondary_server
138
139
 
139
140
 
296
297
 
297
298
    def authorized(self):
298
299
        tcs = self.server.test_case_server
 
300
        if tcs.auth_scheme != 'digest':
 
301
            return False
299
302
 
300
303
        auth_header = self.headers.get(tcs.auth_header_recv, None)
301
304
        if auth_header is None:
316
319
        self.send_header(tcs.auth_header_sent,header)
317
320
 
318
321
 
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
322
class AuthServer(http_server.HttpServer):
338
323
    """Extends HttpServer with a dictionary of passwords.
339
324
 
425
410
 
426
411
        return response_digest == auth['response']
427
412
 
428
 
 
429
413
class HTTPAuthServer(AuthServer):
430
414
    """An HTTP server requiring authentication"""
431
415
 
463
447
        self.init_http_auth()
464
448
 
465
449
 
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
450
class ProxyBasicAuthServer(ProxyAuthServer):
479
451
    """A proxy server requiring basic authentication"""
480
452
 
493
465
        self.init_proxy_auth()
494
466
 
495
467
 
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