MCPcopy Index your code
hub / github.com/apache/caldera / simple_webapp

Function simple_webapp

tests/api/v2/test_security.py:30–67  ·  view source on GitHub ↗
(event_loop, base_world)

Source from the content-addressed store, hash-verified

28
29@pytest.fixture
30def simple_webapp(event_loop, base_world):
31 async def index(request):
32 return web.Response(status=200, text='hello!')
33
34 @security.authentication_exempt
35 async def public(request):
36 return web.Response(status=200, text='public')
37
38 async def private(request):
39 return web.Response(status=200, text='private')
40
41 @security.authentication_exempt
42 async def login(request):
43 await auth_svc.login_user(request) # Note: auth_svc defined in context function
44
45 app = web.Application()
46 app.router.add_get('/', index)
47 app.router.add_post('/login', login)
48 app.router.add_get('/public', public)
49 app.router.add_get('/private', private)
50
51 auth_svc = AuthService()
52
53 event_loop.run_until_complete(
54 auth_svc.apply(
55 app=app,
56 users=base_world.get_config('users')
57 )
58 )
59 event_loop.run_until_complete(auth_svc.set_login_handlers(auth_svc.get_services()))
60
61 # The authentication_required middleware needs to run after the session middleware.
62 # AuthService.apply(...) adds session middleware to the app, so we can append the
63 # the auth middleware after. Not doing this will cause a 500 in regards to the
64 # session middleware not being set up correctly.
65 app.middlewares.append(security.authentication_required_middleware_factory(auth_svc))
66
67 return app
68
69
70def test_function_is_authentication_exempt():

Callers

nothing calls this directly

Calls 5

applyMethod · 0.95
set_login_handlersMethod · 0.95
AuthServiceClass · 0.90
get_servicesMethod · 0.80
get_configMethod · 0.45

Tested by

no test coverage detected