2015-08-04 18:19:01 +00:00
|
|
|
import asyncio
|
2015-11-19 11:53:38 +00:00
|
|
|
import pytest
|
2015-08-04 18:19:01 +00:00
|
|
|
|
|
|
|
from aiohttp import web
|
2015-11-19 11:53:38 +00:00
|
|
|
from aiohttp_security import authorized_userid, permits
|
2015-08-04 18:19:01 +00:00
|
|
|
|
|
|
|
|
2015-11-19 11:53:38 +00:00
|
|
|
@pytest.mark.run_loop
|
|
|
|
def test_authorized_userid(create_app_and_client):
|
2015-08-04 18:19:01 +00:00
|
|
|
|
|
|
|
@asyncio.coroutine
|
2015-11-19 11:53:38 +00:00
|
|
|
def check(request):
|
|
|
|
userid = yield from authorized_userid(request)
|
|
|
|
assert userid is None
|
|
|
|
return web.Response()
|
2015-08-04 18:19:01 +00:00
|
|
|
|
2015-11-19 11:53:38 +00:00
|
|
|
app, client = yield from create_app_and_client()
|
|
|
|
app.router.add_route('GET', '/', check)
|
|
|
|
resp = yield from client.get('/')
|
|
|
|
assert 200 == resp.status
|
|
|
|
yield from resp.release()
|
2015-08-04 18:19:01 +00:00
|
|
|
|
|
|
|
|
2015-11-19 11:53:38 +00:00
|
|
|
@pytest.mark.run_loop
|
|
|
|
def test_permits(create_app_and_client):
|
2015-08-04 18:19:01 +00:00
|
|
|
|
2015-11-19 11:53:38 +00:00
|
|
|
@asyncio.coroutine
|
|
|
|
def check(request):
|
|
|
|
ret = yield from permits(request, 'read')
|
|
|
|
assert ret
|
|
|
|
ret = yield from permits(request, 'write')
|
|
|
|
assert ret
|
|
|
|
ret = yield from permits(request, 'unknown')
|
|
|
|
assert ret
|
|
|
|
return web.Response()
|
|
|
|
|
|
|
|
app, client = yield from create_app_and_client()
|
|
|
|
app.router.add_route('GET', '/', check)
|
|
|
|
resp = yield from client.get('/')
|
|
|
|
assert 200 == resp.status
|
|
|
|
yield from resp.release()
|