This file is indexed.

/usr/share/pyshared/cherrypy/test/test_config.py is in python-cherrypy 2.3.0-3.

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
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
"""Tests for the CherryPy configuration system."""
import test
test.prefer_parent_path()

import StringIO
import cherrypy


def setup_server():
    
    class Root:
        def index(self, key):
            return cherrypy.config.get(key, "None")
        index.exposed = True
        global_ = index
        xyz = index
    
    class Foo:
        def index(self, key):
            return cherrypy.config.get(key, "None")
        index.exposed = True
        bar = index
        nex = index
        
        def getall(self, key):
            return repr(cherrypy.config.getAll(key))
        getall.exposed = True
    
    class Env:
        def index(self, key):
            return str(cherrypy.config.get(key, "None"))
        index.exposed = True
        prod = index
        embed = index
        
        def wrong(self):
            conf = "\n[global]\nserver.environment = production\n"
            cherrypy.config.update(file=StringIO.StringIO(conf))
        wrong.exposed=True
    
    cherrypy.tree.mount(Root())
    cherrypy.root.foo = Foo()
    
    cherrypy.config.update({
        'global': {'server.log_to_screen': False,
                   'server.environment': 'production',
                   'server.show_tracebacks': True,
                   },
        '/': {
            'foo': 'this',
            'bar': 'that',
            },
        '/foo': {
            'foo': 'this2',
            'baz': 'that2',
            },
        '/foo/bar': {
            'foo': 'this3',
            'bax': 'this4',
            },
    })

    _env_conf = {'/': {'server.environment': 'development'},
                 '/prod': {'server.environment': 'production'},
                 '/embed': {'server.environment': 'embedded'},
                 }
    cherrypy.tree.mount(Env(), "/env", _env_conf)

    # Shortcut syntax--should get put in the "global" bucket
    cherrypy.config.update({'luxuryyacht': 'throatwobblermangrove'})


#                             Client-side code                             #

import helper

class ConfigTests(helper.CPWebCase):
    
    def testConfig(self):
        tests = [
            ('/',        'nex', 'None'),
            ('/',        'foo', 'this'),
            ('/',        'bar', 'that'),
            ('/xyz',     'foo', 'this'),
            ('/foo/',    'foo', 'this2'),
            ('/foo/',    'bar', 'that'),
            ('/foo/',    'bax', 'None'),
            ('/foo/bar', 'baz', 'that2'),
            ('/foo/nex', 'baz', 'that2'),
            # If 'foo' == 'this', then the mount point '/env' leaks into '/'.
            ('/env/prod','foo', 'None'),
        ]
        for path, key, expected in tests:
            self.getPage(path + "?key=" + key)
            self.assertBody(expected)
        
        self.getPage("/foo/getall?key=foo")
        self.assertBody("[('/', 'this'), ('/foo', 'this2')]")
    
    def testUnrepr(self):
        err = ('WrongConfigValue: ("section: '
               "'global', option: 'server.environment', value: 'production'"
               '''", 'UnknownType', ('production',))''')
        self.getPage("/env/wrong")
        self.assertErrorPage(500, pattern=err)
    
    def testEnvironments(self):
        for key, val in cherrypy.config.environments['development'].iteritems():
            self.getPage("/env/?key=" + key)
            # The dev environment will have logdebuginfo data
            data = self.body.split("\n")[0]
            self.assertEqual(data, str(val))
        for key, val in cherrypy.config.environments['production'].iteritems():
            self.getPage("/env/prod/?key=" + key)
            self.assertBody(str(val))
        for key, val in cherrypy.config.environments['embedded'].iteritems():
            self.getPage("/env/embed/?key=" + key)
            data = self.body.split("\n")[0]
            self.assertEqual(data, str(val))


if __name__ == '__main__':
    setup_server()
    helper.testmain()