def test_bound_method_is_authentication_exempt(): class Api: def handler(self, request): return None api = Api() assert security.is_handler_authentication_exempt(api.handler) is False assert security.is_handler_authentication_exempt(security.authentication_exempt(api.handler)) is True
async def test_authentication_exempt_bound_method_returns_200(base_world, aiohttp_client): class Api: async def public(self, request): return web.Response(status=200, text='hello!') api = Api() app = web.Application() app.router.add_get('/public', security.authentication_exempt(api.public)) auth_svc = AuthService() await auth_svc.apply( app=app, users=base_world.get_config('users') ) app.middlewares.append(security.authentication_required_middleware_factory(auth_svc)) client = await aiohttp_client(app) resp = await client.get('/public') assert resp.status == 200
def add_routes(self, app: web.Application): router = app.router router.add_get('/health', security.authentication_exempt(self.get_health_info)) router.add_get('/health-authenticated', self.get_health_info)
def test_function_is_authentication_exempt(): def fake_handler(request): return None assert security.is_handler_authentication_exempt(fake_handler) is False assert security.is_handler_authentication_exempt(security.authentication_exempt(fake_handler)) is True