2021-05-28 22:13:48 +02:00
|
|
|
import pytest
|
|
|
|
from starlette.responses import PlainTextResponse
|
|
|
|
from starlette.testclient import TestClient
|
2021-11-29 05:42:26 +01:00
|
|
|
from halfapi.half_route import HalfRoute
|
2021-05-28 22:13:48 +02:00
|
|
|
from halfapi.lib import acl
|
|
|
|
|
|
|
|
def test_acl_Check(dummy_app, token_debug_false_builder):
|
|
|
|
"""
|
|
|
|
A request with ?check should always return a 200 status code
|
|
|
|
"""
|
|
|
|
|
2021-11-29 05:42:26 +01:00
|
|
|
@HalfRoute.acl_decorator(params=[{'acl':acl.public}])
|
2021-05-28 22:13:48 +02:00
|
|
|
async def test_route_public(request, **kwargs):
|
|
|
|
raise Exception('Should not raise')
|
|
|
|
return PlainTextResponse('ok')
|
|
|
|
|
|
|
|
dummy_app.add_route('/test_public', test_route_public)
|
|
|
|
test_client = TestClient(dummy_app)
|
|
|
|
|
2023-01-14 11:10:13 +01:00
|
|
|
resp = test_client.request('get', '/test_public?check')
|
2021-05-28 22:13:48 +02:00
|
|
|
assert resp.status_code == 200
|
|
|
|
|
2021-11-29 05:42:26 +01:00
|
|
|
@HalfRoute.acl_decorator(params=[{'acl':acl.private}])
|
2021-05-28 22:13:48 +02:00
|
|
|
async def test_route_private(request, **kwargs):
|
|
|
|
raise Exception('Should not raise')
|
|
|
|
return PlainTextResponse('ok')
|
|
|
|
|
|
|
|
dummy_app.add_route('/test_private', test_route_private)
|
|
|
|
test_client = TestClient(dummy_app)
|
|
|
|
|
2023-01-14 11:10:13 +01:00
|
|
|
resp = test_client.request('get', '/test_private')
|
2021-05-28 22:13:48 +02:00
|
|
|
assert resp.status_code == 401
|
|
|
|
|
2023-01-14 11:10:13 +01:00
|
|
|
resp = test_client.request('get', '/test_private?check')
|
2021-05-28 22:13:48 +02:00
|
|
|
assert resp.status_code == 200
|
|
|
|
|
|
|
|
|