/opt/imh-python/lib/python3.9/site-packages/cherrypy/test
NameSizeModeActions
static/-0755rm
__pycache__/-0755rm
benchmark.py125630644editdlrm
checkerdemo.py18610644editdlrm
fastcgi.conf6860644editdlrm
fcgi.conf4860644editdlrm
helper.py163690644editdlrm
logtest.py81510644editdlrm
modfastcgi.py46520644editdlrm
modfcgid.py42370644editdlrm
modpy.py49780644editdlrm
modwsgi.py48340644editdlrm
sessiondemo.py54250644editdlrm
style.css170644editdlrm
test.pem22540644editdlrm
test_auth_basic.py44990644editdlrm
test_auth_digest.py44540644editdlrm
test_bus.py99600644editdlrm
test_caching.py143860644editdlrm
test_config.py88360644editdlrm
test_config_server.py40370644editdlrm
test_conn.py307440644editdlrm
test_core.py304080644editdlrm
test_dynamicobjectmapping.py123310644editdlrm
test_encoding.py175350644editdlrm
test_etags.py30930644editdlrm
test_http.py109390644editdlrm
test_httputil.py24120644editdlrm
test_iterator.py57240644editdlrm
test_json.py28600644editdlrm
test_logging.py83150644editdlrm
test_mime.py45380644editdlrm
test_misc_tools.py70940644editdlrm
test_native.py9710644editdlrm
test_objectmapping.py145040644editdlrm
test_params.py18620644editdlrm
test_plugins.py3340644editdlrm
test_proxy.py56300644editdlrm
test_refleaks.py15550644editdlrm
test_request_obj.py370970644editdlrm
test_routes.py25830644editdlrm
test_session.py179490644editdlrm
test_sessionauthenticate.py20130644editdlrm
test_states.py167030644editdlrm
test_static.py167020644editdlrm
test_tools.py178510644editdlrm
test_tutorials.py69640644editdlrm
test_virtualhost.py40210644editdlrm
test_wsgiapps.py39970644editdlrm
test_wsgi_ns.py28120644editdlrm
test_wsgi_unix_socket.py22280644editdlrm
test_wsgi_vhost.py10340644editdlrm
test_xmlrpc.py45840644editdlrm
webtest.py2620644editdlrm
_test_decorators.py9510644editdlrm
_test_states_demo.py18760644editdlrm
__init__.py3960644editdlrm
Edit: /opt/imh-python/lib/python3.9/site-packages/cherrypy/test/test_auth_digest.py (4454B)
# This file is part of CherryPy # -*- coding: utf-8 -*- # vim:ts=4:sw=4:expandtab:fileencoding=utf-8 import cherrypy from cherrypy.lib import auth_digest from cherrypy._cpcompat import ntob from cherrypy.test import helper def _fetch_users(): return {'test': 'test', '☃йюзер': 'їпароль'} get_ha1 = cherrypy.lib.auth_digest.get_ha1_dict_plain(_fetch_users()) class DigestAuthTest(helper.CPWebCase): @staticmethod def setup_server(): class Root: @cherrypy.expose def index(self): return 'This is public.' class DigestProtected: @cherrypy.expose def index(self, *args, **kwargs): return "Hello %s, you've been authorized." % ( cherrypy.request.login) conf = {'/digest': {'tools.auth_digest.on': True, 'tools.auth_digest.realm': 'localhost', 'tools.auth_digest.get_ha1': get_ha1, 'tools.auth_digest.key': 'a565c27146791cfb', 'tools.auth_digest.debug': True, 'tools.auth_digest.accept_charset': 'UTF-8'}} root = Root() root.digest = DigestProtected() cherrypy.tree.mount(root, config=conf) def testPublic(self): self.getPage('/') assert self.status == '200 OK' self.assertHeader('Content-Type', 'text/html;charset=utf-8') assert self.body == b'This is public.' def _test_parametric_digest(self, username, realm): test_uri = '/digest/?@/=%2F%40&%f0%9f%99%88=path' self.getPage(test_uri) assert self.status_code == 401 msg = 'Digest authentification scheme was not found' www_auth_digest = tuple(filter( lambda kv: kv[0].lower() == 'www-authenticate' and kv[1].startswith('Digest '), self.headers, )) assert len(www_auth_digest) == 1, msg items = www_auth_digest[0][-1][7:].split(', ') tokens = {} for item in items: key, value = item.split('=') tokens[key.lower()] = value assert tokens['realm'] == '"localhost"' assert tokens['algorithm'] == '"MD5"' assert tokens['qop'] == '"auth"' assert tokens['charset'] == '"UTF-8"' nonce = tokens['nonce'].strip('"') # Test user agent response with a wrong value for 'realm' base_auth = ('Digest username="%s", ' 'realm="%s", ' 'nonce="%s", ' 'uri="%s", ' 'algorithm=MD5, ' 'response="%s", ' 'qop=auth, ' 'nc=%s, ' 'cnonce="1522e61005789929"') encoded_user = username encoded_user = encoded_user.encode('utf-8') encoded_user = encoded_user.decode('latin1') auth_header = base_auth % ( encoded_user, realm, nonce, test_uri, '11111111111111111111111111111111', '00000001', ) auth = auth_digest.HttpDigestAuthorization(auth_header, 'GET') # calculate the response digest ha1 = get_ha1(auth.realm, auth.username) response = auth.request_digest(ha1) auth_header = base_auth % ( encoded_user, realm, nonce, test_uri, response, '00000001', ) self.getPage(test_uri, [('Authorization', auth_header)]) def test_wrong_realm(self): # send response with correct response digest, but wrong realm self._test_parametric_digest(username='test', realm='wrong realm') assert self.status_code == 401 def test_ascii_user(self): self._test_parametric_digest(username='test', realm='localhost') assert self.status == '200 OK' assert self.body == b"Hello test, you've been authorized." def test_unicode_user(self): self._test_parametric_digest(username='☃йюзер', realm='localhost') assert self.status == '200 OK' assert self.body == ntob( "Hello ☃йюзер, you've been authorized.", 'utf-8', ) def test_wrong_scheme(self): basic_auth = { 'Authorization': 'Basic foo:bar', } self.getPage('/digest/', headers=list(basic_auth.items())) assert self.status_code == 401