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

Changeset 1891

Show
Ignore:
Timestamp:
02/18/08 12:51:51
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
  • trunk/cherrypy/lib/auth.py

    r1682 r1891  
    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     
  • trunk/cherrypy/lib/httpauth.py

    r1890 r1891  
    308308                   raw data you are going to send to the client (usually the 
    309309                   HTML page. 
    310     """ 
     310     request_uri - the uri from the request line compared with the 'uri' 
     311                   directive of the authorization map. They must represent 
     312                   the same resource (unused at this time). 
     313    """ 
     314 
     315    if auth_map['realm'] != kwargs.get('realm', None): 
     316        return False 
    311317 
    312318    response =  _computeDigestResponse(auth_map, password, method, A1,**kwargs) 
     
    315321 
    316322def _checkBasicResponse (auth_map, password, method='GET', encrypt=None, **kwargs): 
     323    # Note that the Basic response doesn't provide the realm value so we cannot 
     324    # test it 
    317325    try: 
    318326        return encrypt(auth_map["password"], auth_map["username"]) == password 
  • trunk/cherrypy/test/test_httpauth.py

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

Hosted by WebFaction

Log in as guest/cpguest to create tickets