Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1892

Show
Ignore:
Timestamp:
02/18/08 12:54:21
Author:
lawouach
Message:

Fix for #787 only for digest though as basic responses don't provide the realm

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/cherrypy-3.0.x/cherrypy/lib/auth.py

    r1681 r1892  
    33 
    44 
    5 def check_auth(users, encrypt=None): 
     5def check_auth(users, encrypt=None, realm=None): 
    66    """If an authorization header contains credentials, return True, else False.""" 
    77    if 'authorization' in cherrypy.request.headers: 
     
    3737        # and compare it with what the user-agent provided 
    3838        if httpauth.checkResponse(ah, password, method=cherrypy.request.method, 
    39                                   encrypt=encrypt): 
     39                                  encrypt=encrypt, realm=realm): 
    4040            cherrypy.request.login = ah["username"] 
    4141            return True 
     
    6666    users: a dict of the form: {username: password} or a callable returning a dict. 
    6767    """ 
    68     if check_auth(users): 
     68    if check_auth(users, realm=realm): 
    6969        return 
    7070     
  • branches/cherrypy-3.0.x/cherrypy/lib/httpauth.py

    r1889 r1892  
    310310    """ 
    311311 
     312    if auth_map['realm'] != kwargs.get('realm', None): 
     313        return False 
     314     
    312315    response =  _computeDigestResponse(auth_map, password, method, A1,**kwargs) 
    313316 
  • branches/cherrypy-3.0.x/cherrypy/test/test_httpauth.py

    r1681 r1892  
    129129            self._handlewebError(bad_value_msg % ('qop', '"auth"', tokens['qop'])) 
    130130 
    131             # now let's see if what  
     131        # Test a wrong 'realm' value 
     132        base_auth = 'Digest username="test", realm="wrong realm", nonce="%s", uri="/digest/", algorithm=MD5, response="%s", qop=auth, nc=%s, cnonce="1522e61005789929"' 
     133 
     134        auth = base_auth % (nonce, '', '00000001') 
     135        params = httpauth.parseAuthorization(auth) 
     136        response = httpauth._computeDigestResponse(params, 'test') 
     137         
     138        auth = base_auth % (nonce, response, '00000001') 
     139        self.getPage('/digest/', [('Authorization', auth)]) 
     140        self.assertStatus('401 Unauthorized') 
     141         
     142        # Test that must pass 
    132143        base_auth = 'Digest username="test", realm="localhost", nonce="%s", uri="/digest/", algorithm=MD5, response="%s", qop=auth, nc=%s, cnonce="1522e61005789929"' 
    133144 

Hosted by WebFaction

Log in as guest/cpguest to create tickets