aiohttp-security/tests/test_no_auth.py

35 lines
934 B
Python
Raw Permalink Normal View History

from aiohttp import web
2015-11-19 11:53:38 +00:00
from aiohttp_security import authorized_userid, permits
2018-09-06 10:06:55 +00:00
async def test_authorized_userid(loop, aiohttp_client):
2017-12-13 14:51:46 +00:00
async def check(request):
userid = await authorized_userid(request)
2015-11-19 11:53:38 +00:00
assert userid is None
return web.Response()
2018-09-06 10:06:55 +00:00
app = web.Application()
2015-11-19 11:53:38 +00:00
app.router.add_route('GET', '/', check)
2018-09-06 10:06:55 +00:00
client = await aiohttp_client(app)
2017-12-13 14:51:46 +00:00
resp = await client.get('/')
2015-11-19 11:53:38 +00:00
assert 200 == resp.status
2018-09-06 10:06:55 +00:00
async def test_permits(loop, aiohttp_client):
2017-12-13 14:51:46 +00:00
async def check(request):
ret = await permits(request, 'read')
2015-11-19 11:53:38 +00:00
assert ret
2017-12-13 14:51:46 +00:00
ret = await permits(request, 'write')
2015-11-19 11:53:38 +00:00
assert ret
2017-12-13 14:51:46 +00:00
ret = await permits(request, 'unknown')
2015-11-19 11:53:38 +00:00
assert ret
return web.Response()
2018-09-06 10:06:55 +00:00
app = web.Application()
2015-11-19 11:53:38 +00:00
app.router.add_route('GET', '/', check)
2018-09-06 10:06:55 +00:00
client = await aiohttp_client(app)
2017-12-13 14:51:46 +00:00
resp = await client.get('/')
2015-11-19 11:53:38 +00:00
assert 200 == resp.status