/
opt
/
imh-python
/
lib
/
python3.9
/
site-packages
/
cherrypy
/
test
/
/opt/imh-python/lib/python3.9/site-packages/cherrypy/test
mkdir
upload
Name
Size
Mode
Actions
static/
-
0755
rm
__pycache__/
-
0755
rm
benchmark.py
12563
0644
edit
dl
rm
checkerdemo.py
1861
0644
edit
dl
rm
fastcgi.conf
686
0644
edit
dl
rm
fcgi.conf
486
0644
edit
dl
rm
helper.py
16369
0644
edit
dl
rm
logtest.py
8151
0644
edit
dl
rm
modfastcgi.py
4652
0644
edit
dl
rm
modfcgid.py
4237
0644
edit
dl
rm
modpy.py
4978
0644
edit
dl
rm
modwsgi.py
4834
0644
edit
dl
rm
sessiondemo.py
5425
0644
edit
dl
rm
style.css
17
0644
edit
dl
rm
test.pem
2254
0644
edit
dl
rm
test_auth_basic.py
4499
0644
edit
dl
rm
test_auth_digest.py
4454
0644
edit
dl
rm
test_bus.py
9960
0644
edit
dl
rm
test_caching.py
14386
0644
edit
dl
rm
test_config.py
8836
0644
edit
dl
rm
test_config_server.py
4037
0644
edit
dl
rm
test_conn.py
30744
0644
edit
dl
rm
test_core.py
30408
0644
edit
dl
rm
test_dynamicobjectmapping.py
12331
0644
edit
dl
rm
test_encoding.py
17535
0644
edit
dl
rm
test_etags.py
3093
0644
edit
dl
rm
test_http.py
10939
0644
edit
dl
rm
test_httputil.py
2412
0644
edit
dl
rm
test_iterator.py
5724
0644
edit
dl
rm
test_json.py
2860
0644
edit
dl
rm
test_logging.py
8315
0644
edit
dl
rm
test_mime.py
4538
0644
edit
dl
rm
test_misc_tools.py
7094
0644
edit
dl
rm
test_native.py
971
0644
edit
dl
rm
test_objectmapping.py
14504
0644
edit
dl
rm
test_params.py
1862
0644
edit
dl
rm
test_plugins.py
334
0644
edit
dl
rm
test_proxy.py
5630
0644
edit
dl
rm
test_refleaks.py
1555
0644
edit
dl
rm
test_request_obj.py
37097
0644
edit
dl
rm
test_routes.py
2583
0644
edit
dl
rm
test_session.py
17949
0644
edit
dl
rm
test_sessionauthenticate.py
2013
0644
edit
dl
rm
test_states.py
16703
0644
edit
dl
rm
test_static.py
16702
0644
edit
dl
rm
test_tools.py
17851
0644
edit
dl
rm
test_tutorials.py
6964
0644
edit
dl
rm
test_virtualhost.py
4021
0644
edit
dl
rm
test_wsgiapps.py
3997
0644
edit
dl
rm
test_wsgi_ns.py
2812
0644
edit
dl
rm
test_wsgi_unix_socket.py
2228
0644
edit
dl
rm
test_wsgi_vhost.py
1034
0644
edit
dl
rm
test_xmlrpc.py
4584
0644
edit
dl
rm
webtest.py
262
0644
edit
dl
rm
_test_decorators.py
951
0644
edit
dl
rm
_test_states_demo.py
1876
0644
edit
dl
rm
__init__.py
396
0644
edit
dl
rm
Edit:
/opt/imh-python/lib/python3.9/site-packages/cherrypy/test/test_auth_digest.py
(4454B)
# This file is part of CherryPy <http://www.cherrypy.org/> # -*- 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
Save
cmd:
run