This file is indexed.

/usr/lib/python2.7/dist-packages/pecan/tests/middleware/test_errordocument.py is in python-pecan 0.6.1-2.

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
import json

from webtest import TestApp
from six import b as b_

import pecan
from pecan.middleware.errordocument import ErrorDocumentMiddleware
from pecan.middleware.recursive import RecursiveMiddleware
from pecan.tests import PecanTestCase


def four_oh_four_app(environ, start_response):
    if environ['PATH_INFO'].startswith('/error'):
        code = environ['PATH_INFO'].split('/')[2]
        start_response("200 OK", [('Content-type', 'text/plain')])

        body = "Error: %s" % code
        if environ['QUERY_STRING']:
            body += "\nQS: %s" % environ['QUERY_STRING']
        return [b_(body)]
    start_response("404 Not Found", [('Content-type', 'text/plain')])
    return []


class TestErrorDocumentMiddleware(PecanTestCase):

    def setUp(self):
        super(TestErrorDocumentMiddleware, self).setUp()
        self.app = TestApp(RecursiveMiddleware(ErrorDocumentMiddleware(
            four_oh_four_app, {404: '/error/404'}
        )))

    def test_hit_error_page(self):
        r = self.app.get('/error/404')
        assert r.status_int == 200
        assert r.body == b_('Error: 404')

    def test_middleware_routes_to_404_message(self):
        r = self.app.get('/', expect_errors=True)
        assert r.status_int == 404
        assert r.body == b_('Error: 404')

    def test_error_endpoint_with_query_string(self):
        app = TestApp(RecursiveMiddleware(ErrorDocumentMiddleware(
            four_oh_four_app, {404: '/error/404?foo=bar'}
        )))
        r = app.get('/', expect_errors=True)
        assert r.status_int == 404
        assert r.body == b_('Error: 404\nQS: foo=bar')

    def test_error_with_recursion_loop(self):
        app = TestApp(RecursiveMiddleware(ErrorDocumentMiddleware(
            four_oh_four_app, {404: '/'}
        )))
        r = app.get('/', expect_errors=True)
        assert r.status_int == 404
        assert r.body == b_(
            'Error: 404 Not Found.  (Error page could not be fetched)'
        )

    def test_original_exception(self):

        class RootController(object):

            @pecan.expose()
            def index(self):
                if pecan.request.method != 'POST':
                    pecan.abort(405, 'You have to POST, dummy!')
                return 'Hello, World!'

            @pecan.expose('json')
            def error(self, status):
                return dict(
                    status=int(status),
                    reason=pecan.request.environ[
                        'pecan.original_exception'
                    ].detail
                )

        app = pecan.Pecan(RootController())
        app = RecursiveMiddleware(ErrorDocumentMiddleware(app, {
            405: '/error/405'
        }))
        app = TestApp(app)

        assert app.post('/').status_int == 200
        r = app.get('/', expect_errors=405)
        assert r.status_int == 405

        resp = json.loads(r.body.decode())
        assert resp['status'] == 405
        assert resp['reason'] == 'You have to POST, dummy!'