~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/http_utils.py

  • Committer: Robert Collins
  • Date: 2009-08-25 21:09:17 UTC
  • mto: This revision was merged to the branch mainline in revision 4650.
  • Revision ID: robertc@robertcollins.net-20090825210917-dq2i8k6n4z63pneh
Support shelve and unshelve on windows - bug 305006.

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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
from cStringIO import StringIO
18
18
import errno
19
 
import md5
20
19
import re
21
 
import sha
22
20
import socket
23
21
import threading
24
22
import time
25
23
import urllib2
26
24
import urlparse
27
25
 
 
26
 
28
27
from bzrlib import (
29
28
    errors,
 
29
    osutils,
30
30
    tests,
31
31
    )
32
32
from bzrlib.smart import medium, protocol
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
 
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
 
397
413
        A1 = '%s:%s:%s' % (user, realm, password)
398
414
        A2 = '%s:%s' % (command, auth['uri'])
399
415
 
400
 
        H = lambda x: md5.new(x).hexdigest()
 
416
        H = lambda x: osutils.md5(x).hexdigest()
401
417
        KD = lambda secret, data: H("%s:%s" % (secret, data))
402
418
 
403
419
        nonce_count = int(auth['nc'], 16)
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