~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/http_utils.py

  • Committer: John Arbash Meinel
  • Date: 2008-09-09 15:09:12 UTC
  • mto: This revision was merged to the branch mainline in revision 3699.
  • Revision ID: john@arbash-meinel.com-20080909150912-wyttm8he1zsls2ck
Use the right timing function on win32

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
 
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
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
300
302
 
301
303
        auth_header = self.headers.get(tcs.auth_header_recv, None)
302
304
        if auth_header is None:
317
319
        self.send_header(tcs.auth_header_sent,header)
318
320
 
319
321
 
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
 
 
338
322
class AuthServer(http_server.HttpServer):
339
323
    """Extends HttpServer with a dictionary of passwords.
340
324
 
413
397
        A1 = '%s:%s:%s' % (user, realm, password)
414
398
        A2 = '%s:%s' % (command, auth['uri'])
415
399
 
416
 
        H = lambda x: osutils.md5(x).hexdigest()
 
400
        H = lambda x: md5.new(x).hexdigest()
417
401
        KD = lambda secret, data: H("%s:%s" % (secret, data))
418
402
 
419
403
        nonce_count = int(auth['nc'], 16)
426
410
 
427
411
        return response_digest == auth['response']
428
412
 
429
 
 
430
413
class HTTPAuthServer(AuthServer):
431
414
    """An HTTP server requiring authentication"""
432
415
 
464
447
        self.init_http_auth()
465
448
 
466
449
 
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
 
 
479
450
class ProxyBasicAuthServer(ProxyAuthServer):
480
451
    """A proxy server requiring basic authentication"""
481
452
 
494
465
        self.init_proxy_auth()
495
466
 
496
467
 
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