/usr/lib/python2.7/dist-packages/cherrypy/test/test_virtualhost_filter.py is in python-cherrypy 2.3.0-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | import test
test.prefer_parent_path()
import cherrypy
def setup_server():
class Root:
def index(self):
return "Hello, world"
index.exposed = True
def dom4(self):
return "Under construction"
dom4.exposed = True
def method(self, value):
return "You sent %s" % repr(value)
method.exposed = True
class VHost:
def __init__(self, sitename):
self.sitename = sitename
def index(self):
return "Welcome to %s" % self.sitename
index.exposed = True
def somewhere(self):
return "Over the %s rainbow" % self.sitename
somewhere.exposed = True
def vmethod(self, value):
return "You sent %s" % repr(value)
vmethod.exposed = True
cherrypy.root = Root()
cherrypy.root.mydom2 = VHost("Domain 2")
cherrypy.root.mydom3 = VHost("Domain 3")
cherrypy.config.update({
'server.logToScreen': False,
'server.environment': 'production',
'virtual_host_filter.on': True,
'virtual_host_filter.www.mydom2.com': '/mydom2',
'virtual_host_filter.www.mydom3.com': '/mydom3',
'virtual_host_filter.www.mydom4.com': '/dom4',
})
import helper
class VirtualHostFilterTest(helper.CPWebCase):
def testVirtualHostFilter(self):
self.getPage("/", [('Host', 'www.mydom1.com')])
self.assertBody('Hello, world')
self.getPage("/mydom2/", [('Host', 'www.mydom1.com')])
self.assertBody('Welcome to Domain 2')
self.getPage("/", [('Host', 'www.mydom2.com')])
self.assertBody('Welcome to Domain 2')
self.getPage("/", [('Host', 'www.mydom3.com')])
self.assertBody('Welcome to Domain 3')
self.getPage("/", [('Host', 'www.mydom4.com')])
self.assertBody('Under construction')
# Test sub pages. See http://www.cherrypy.org/ticket/543.
self.getPage("/somewhere", [('Host', 'www.mydom2.com')])
self.assertBody('Over the Domain 2 rainbow')
self.getPage("/somewhere", [('Host', 'www.mydom3.com')])
self.assertBody('Over the Domain 3 rainbow')
# Test GET, POST, and positional params
self.getPage("/method?value=root")
self.assertBody("You sent 'root'")
self.getPage("/vmethod?value=dom2+GET", [('Host', 'www.mydom2.com')])
self.assertBody("You sent 'dom2 GET'")
self.getPage("/vmethod", [('Host', 'www.mydom3.com')], method="POST",
body="value=dom3+POST")
self.assertBody("You sent 'dom3 POST'")
self.getPage("/vmethod/pos", [('Host', 'www.mydom3.com')])
self.assertBody("You sent 'pos'")
if __name__ == "__main__":
setup_server()
helper.testmain()
|