Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self):
self.p = Project(title='Bogus project for testing webapp')
self.app = webapp.SimpleWSGIApp(self.p)
self.app.handlers = []
self.bogus_environ = dict(
PATH_INFO='/fibityfoo',
QUERY_STRING='?a=1')
wsgiref.util.setup_testing_defaults(self.bogus_environ)
def checkShift(self,sn_in,pi_in,part,sn_out,pi_out):
env = {'SCRIPT_NAME':sn_in,'PATH_INFO':pi_in}
util.setup_testing_defaults(env)
self.assertEqual(util.shift_path_info(env),part)
self.assertEqual(env['PATH_INFO'],pi_out)
self.assertEqual(env['SCRIPT_NAME'],sn_out)
return env
def checkShift(self,sn_in,pi_in,part,sn_out,pi_out):
env = {'SCRIPT_NAME':sn_in,'PATH_INFO':pi_in}
util.setup_testing_defaults(env)
self.assertEqual(util.shift_path_info(env),part)
self.assertEqual(env['PATH_INFO'],pi_out)
self.assertEqual(env['SCRIPT_NAME'],sn_out)
return env
def setUp(self):
e = dict()
wsgiref.util.setup_testing_defaults(e)
b = Bottle()
request.bind(e)
response.bind()
def test_filewrapper_getitem_deprecation(self):
wrapper = util.FileWrapper(StringIO('foobar'), 3)
with self.assertWarnsRegex(DeprecationWarning,
r'Use iterator protocol instead'):
# This should have returned 'bar'.
self.assertEqual(wrapper[1], 'foo')
def __call__(self, instance, environ, start_response):
"""Create Request, call thing, unwrap results and respond."""
req = Request(environ, start_response, self.extra_props)
body = self.app(instance, req)
req.save_to_environ()
if body is None:
body = req.res.body
if not req.start_response_called:
req.start_response(req.res.status, req.res._headers, req.exc_info)
req.start_response_called = True
if isinstance(body, str):
return [body]
elif isiterable(body):
return body
else:
return util.FileWrapper(body)
"""Aids in the debugging of routes associated.
Args:
path: Validate the specified path against the router
method: The http request method
format: The http request format
server: The hostname of the request
"""
try:
router = self.router
if not router.routes:
raise ConsoleError(
'There are no routes associated with the application.')
if path:
environ = {}
util.setup_testing_defaults(environ)
server = server or '127.0.0.1'
environ.update({
'REQUEST_METHOD': method or 'GET',
'HTTP_ACCEPT': format or 'text/html',
'PATH_INFO': path,
'SERVER_NAME': server,
'HTTP_HOST': server
})
request = Request.from_environ(environ)
matches = [match for match in router.matches(request)]
if matches:
longest_route = max([match.route.name for match in matches], key=len)
self.write(
colors.header('Displaying {} matching routes for {}:\n'.format(
len(matches), request.url)))
cookies = environ.get('HTTP_COOKIE')
email_addr, admin, _ = login.get_user_info(cookies)
if constants.FAKE_IS_ADMIN_HEADER in environ:
admin = True
if constants.FAKE_LOGGED_IN_HEADER in environ:
email_addr = 'Fake User'
# admin has an effect only with login: admin (not login: required).
if requires_login and not email_addr and not (admin and admin_only):
if auth_fail_action == appinfo.AUTH_FAIL_ACTION_REDIRECT:
logging.debug('login required, redirecting user')
return login.login_redirect(wsgiref.util.application_uri(environ),
wsgiref.util.request_uri(environ),
start_response)
elif auth_fail_action == appinfo.AUTH_FAIL_ACTION_UNAUTHORIZED:
logging.debug('login required, user unauthorized')
start_response('401 Not authorized', [('Content-Type', 'text/html'),
('Cache-Control', 'no-cache')])
return ['Login required to view page.']
elif admin_only and not admin:
logging.debug('admin required, user unauthorized')
start_response('401 Not authorized', [('Content-Type', 'text/html'),
('Cache-Control', 'no-cache')])
return ['Current logged in user %s is not '
'authorized to view this page.'
% email_addr]
# Authorization check succeeded
return None
if not _HTTP_TOKEN_RE.match(name):
raise appinfo_errors.InvalidHttpHeaderName(
'An HTTP header must be a non-empty RFC 2616 token.')
if name in _HTTP_REQUEST_HEADERS:
raise appinfo_errors.InvalidHttpHeaderName(
'%r can only be used in HTTP requests, not responses.'
% original_name)
if name.startswith('x-appengine'):
raise appinfo_errors.InvalidHttpHeaderName(
'HTTP header names that begin with X-Appengine are reserved.')
if wsgiref.util.is_hop_by_hop(name):
raise appinfo_errors.InvalidHttpHeaderName(
'Only use end-to-end headers may be used. See RFC 2616 section'
' 13.5.1.')
if name in HttpHeadersDict.DISALLOWED_HEADERS:
raise appinfo_errors.InvalidHttpHeaderName(
'%s is a disallowed header.' % name)
return original_name