1
0
Fork 0
forked from sr2/cloud-api

feat: improved caor request model

Issue: #23
This commit is contained in:
Chris Milne 2026-06-10 09:32:02 +01:00
parent 768a3881ef
commit 939abaefe9
4 changed files with 44 additions and 17 deletions

View file

@ -18,16 +18,20 @@ pytestmark = [
@pytest.mark.anyio
async def test_post_act_on_resource_endpoint_success(default_client: AsyncClient):
body = {
"service": "Test Service",
"organisation": "Test Org",
"resource": "test_resource",
"rn": {
"service": "Test Service",
"organisation": "Test Org",
"resource": "test_resource",
"instance": None,
},
"action": "read",
}
headers = {
"Authorization": "Bearer not_checked_when_auth_is_disabled",
"X-API-Key": "123456789",
}
resp = await default_client.post(
"/iam/can_act_on_resource?action=read", json=body, headers=headers
"/iam/can_act_on_resource", json=body, headers=headers
)
data = resp.json()
@ -43,13 +47,20 @@ async def test_post_act_on_resource_endpoint_success(default_client: AsyncClient
async def test_act_on_resource_wrong_key(
default_client: AsyncClient, db_session, service: str, api_key: str
):
body = {"service": service, "organisation": "Test Org", "resource": "test_resource"}
body = {
"rn": {
"service": service,
"organisation": "Test Org",
"resource": "test_resource",
},
"action": "read",
}
headers = {
"Authorization": "Bearer not_checked_when_auth_is_disabled",
"X-API-Key": api_key,
}
resp = await default_client.post(
"/iam/can_act_on_resource?action=read", json=body, headers=headers
"/iam/can_act_on_resource", json=body, headers=headers
)
data = resp.json()
@ -60,9 +71,12 @@ async def test_act_on_resource_wrong_key(
@pytest.mark.anyio
async def test_act_on_resource_missing_key(default_client: AsyncClient):
body = {
"service": "Test Service",
"organisation": "Test Org",
"resource": "test_resource",
"rn": {
"service": "Test Service",
"organisation": "Test Org",
"resource": "test_resource",
},
"action": "read",
}
headers = {"Authorization": "Bearer not_checked_when_auth_is_disabled"}
resp = await default_client.post(
@ -120,13 +134,16 @@ async def test_act_on_resource_logic(
action,
expected_response: bool,
):
body = {"service": service, "organisation": org, "resource": resource}
body = {
"rn": {"service": service, "organisation": org, "resource": resource},
"action": action,
}
headers = {
"Authorization": "Bearer not_checked_when_auth_is_disabled",
"X-API-Key": "123456789",
}
resp = await default_client.post(
f"/iam/can_act_on_resource?action={action}", json=body, headers=headers
"/iam/can_act_on_resource", json=body, headers=headers
)
data = resp.json()