~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: 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:
297
297
 
298
298
    def authorized(self):
299
299
        tcs = self.server.test_case_server
300
 
        if tcs.auth_scheme != 'digest':
301
 
            return False
302
300
 
303
301
        auth_header = self.headers.get(tcs.auth_header_recv, None)
304
302
        if auth_header is None:
319
317
        self.send_header(tcs.auth_header_sent,header)
320
318
 
321
319
 
 
320
class DigestAndBasicAuthRequestHandler(DigestAuthRequestHandler):
 
321
    """Implements a digest and basic authentication of a request.
 
322
 
 
323
    I.e. the server proposes both schemes and the client should choose the best
 
324
    one it can handle, which, in that case, should be digest, the only scheme
 
325
    accepted here.
 
326
    """
 
327
 
 
328
    def send_header_auth_reqed(self):
 
329
        tcs = self.server.test_case_server
 
330
        self.send_header(tcs.auth_header_sent,
 
331
                         'Basic realm="%s"' % tcs.auth_realm)
 
332
        header = 'Digest realm="%s", ' % tcs.auth_realm
 
333
        header += 'nonce="%s", algorithm="%s", qop="auth"' % (tcs.auth_nonce,
 
334
                                                              'MD5')
 
335
        self.send_header(tcs.auth_header_sent,header)
 
336
 
 
337
 
322
338
class AuthServer(http_server.HttpServer):
323
339
    """Extends HttpServer with a dictionary of passwords.
324
340
 
410
426
 
411
427
        return response_digest == auth['response']
412
428
 
 
429
 
413
430
class HTTPAuthServer(AuthServer):
414
431
    """An HTTP server requiring authentication"""
415
432
 
447
464
        self.init_http_auth()
448
465
 
449
466
 
 
467
class HTTPBasicAndDigestAuthServer(DigestAuthServer, HTTPAuthServer):
 
468
    """An HTTP server requiring basic or digest authentication"""
 
469
 
 
470
    def __init__(self, protocol_version=None):
 
471
        DigestAuthServer.__init__(self, DigestAndBasicAuthRequestHandler,
 
472
                                  'basicdigest',
 
473
                                  protocol_version=protocol_version)
 
474
        self.init_http_auth()
 
475
        # We really accept Digest only
 
476
        self.auth_scheme = 'digest'
 
477
 
 
478
 
450
479
class ProxyBasicAuthServer(ProxyAuthServer):
451
480
    """A proxy server requiring basic authentication"""
452
481
 
465
494
        self.init_proxy_auth()
466
495
 
467
496
 
 
497
class ProxyBasicAndDigestAuthServer(DigestAuthServer, ProxyAuthServer):
 
498
    """An proxy server requiring basic or digest authentication"""
 
499
 
 
500
    def __init__(self, protocol_version=None):
 
501
        DigestAuthServer.__init__(self, DigestAndBasicAuthRequestHandler,
 
502
                                  'basicdigest',
 
503
                                  protocol_version=protocol_version)
 
504
        self.init_proxy_auth()
 
505
        # We really accept Digest only
 
506
        self.auth_scheme = 'digest'
 
507
 
 
508