/
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_proxy.py
(5630B)
import cherrypy from cherrypy.test import helper script_names = ['', '/path/to/myapp'] class ProxyTest(helper.CPWebCase): @staticmethod def setup_server(): # Set up site cherrypy.config.update({ 'tools.proxy.on': True, 'tools.proxy.base': 'www.mydomain.test', }) # Set up application class Root: def __init__(self, sn): # Calculate a URL outside of any requests. self.thisnewpage = cherrypy.url( '/this/new/page', script_name=sn) @cherrypy.expose def pageurl(self): return self.thisnewpage @cherrypy.expose def index(self): raise cherrypy.HTTPRedirect('dummy') @cherrypy.expose def remoteip(self): return cherrypy.request.remote.ip @cherrypy.expose @cherrypy.config(**{ 'tools.proxy.local': 'X-Host', 'tools.trailing_slash.extra': True, }) def xhost(self): raise cherrypy.HTTPRedirect('blah') @cherrypy.expose def base(self): return cherrypy.request.base @cherrypy.expose @cherrypy.config(**{'tools.proxy.scheme': 'X-Forwarded-Ssl'}) def ssl(self): return cherrypy.request.base @cherrypy.expose def newurl(self): return ("Browse to <a href='%s'>this page</a>." % cherrypy.url('/this/new/page')) @cherrypy.expose @cherrypy.config(**{ 'tools.proxy.base': None, }) def base_no_base(self): return cherrypy.request.base for sn in script_names: cherrypy.tree.mount(Root(sn), sn) def testProxy(self): self.getPage('/') self.assertHeader('Location', '%s://www.mydomain.test%s/dummy' % (self.scheme, self.prefix())) # Test X-Forwarded-Host (Apache 1.3.33+ and Apache 2) self.getPage( '/', headers=[('X-Forwarded-Host', 'http://www.example.test')]) self.assertHeader('Location', 'http://www.example.test/dummy') self.getPage('/', headers=[('X-Forwarded-Host', 'www.example.test')]) self.assertHeader('Location', '%s://www.example.test/dummy' % self.scheme) # Test multiple X-Forwarded-Host headers self.getPage('/', headers=[ ('X-Forwarded-Host', 'http://www.example.test, www.cherrypy.test'), ]) self.assertHeader('Location', 'http://www.example.test/dummy') # Test X-Forwarded-For (Apache2) self.getPage('/remoteip', headers=[('X-Forwarded-For', '192.168.0.20')]) self.assertBody('192.168.0.20') # Fix bug #1268 self.getPage('/remoteip', headers=[ ('X-Forwarded-For', '67.15.36.43, 192.168.0.20') ]) self.assertBody('67.15.36.43') # Test X-Host (lighttpd; see https://trac.lighttpd.net/trac/ticket/418) self.getPage('/xhost', headers=[('X-Host', 'www.example.test')]) self.assertHeader('Location', '%s://www.example.test/blah' % self.scheme) # Test X-Forwarded-Proto (lighttpd) self.getPage('/base', headers=[('X-Forwarded-Proto', 'https')]) self.assertBody('https://www.mydomain.test') # Test X-Forwarded-Ssl (webfaction?) self.getPage('/ssl', headers=[('X-Forwarded-Ssl', 'on')]) self.assertBody('https://www.mydomain.test') # Test cherrypy.url() for sn in script_names: # Test the value inside requests self.getPage(sn + '/newurl') self.assertBody( "Browse to <a href='%s://www.mydomain.test" % self.scheme + sn + "/this/new/page'>this page</a>.") self.getPage(sn + '/newurl', headers=[('X-Forwarded-Host', 'http://www.example.test')]) self.assertBody("Browse to <a href='http://www.example.test" + sn + "/this/new/page'>this page</a>.") # Test the value outside requests port = '' if self.scheme == 'http' and self.PORT != 80: port = ':%s' % self.PORT elif self.scheme == 'https' and self.PORT != 443: port = ':%s' % self.PORT host = self.HOST if host in ('0.0.0.0', '::'): import socket host = socket.gethostname() expected = ('%s://%s%s%s/this/new/page' % (self.scheme, host, port, sn)) self.getPage(sn + '/pageurl') self.assertBody(expected) # Test trailing slash (see # https://github.com/cherrypy/cherrypy/issues/562). self.getPage('/xhost/', headers=[('X-Host', 'www.example.test')]) self.assertHeader('Location', '%s://www.example.test/xhost' % self.scheme) def test_no_base_port_in_host(self): """ If no base is indicated, and the host header is used to resolve the base, it should rely on the host header for the port also. """ headers = {'Host': 'localhost:8080'}.items() self.getPage('/base_no_base', headers=headers) self.assertBody('http://localhost:8080')
Save
cmd:
run