/usr/share/pyshared/repoze/who/plugins/tests/fixtures/testapp.py is in python-repoze.who 1.0.18-4.
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 | def tack_environ(environ, msg):
import pprint
penv = pprint.pformat(environ)
return msg + '\n\n' + penv
def deny(start_response, environ, msg):
ct = 'text/plain'
msg = tack_environ(environ, msg)
cl = str(len(msg))
start_response('401 Unauthorized',
[ ('Content-Type', ct),
('Content-Length', cl) ],
)
def allow(start_response, environ, msg):
ct = 'text/plain'
msg = tack_environ(environ, msg)
cl = str(len(msg))
start_response('200 OK',
[ ('Content-Type', ct),
('Content-Length', cl) ],
)
return [msg]
def app(environ, start_response):
path_info = environ['PATH_INFO']
remote_user = environ.get('REMOTE_USER')
if path_info.endswith('/shared'):
if not remote_user:
return deny(start_response, environ, 'You cant do that')
else:
return allow(start_response, environ,
'Welcome to the shared area, %s' % remote_user)
elif path_info.endswith('/admin'):
if remote_user != 'admin':
return deny(start_response, environ, 'Only admin can do that')
else:
return allow(start_response, environ, 'Hello, admin!')
elif path_info.endswith('/chris'):
if remote_user != 'chris':
return deny(start_response, environ, 'Only chris can do that')
else:
return allow(start_response, environ, 'Hello, chris!')
else:
return allow(start_response, environ, 'Unprotected page')
def make_app(global_config, **kw):
return app
|