Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ components:
type: http
info:
title: Requestor
version: 1.5.1
version: 1.7.0
openapi: 3.0.2
paths:
/_status:
Expand Down
6 changes: 6 additions & 0 deletions src/requestor/routes/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ async def create_request(
client = api_request.app.arborist_client

if not data["policy_id"]:
# Check format of resource_paths (should have content after slash)
for p in data["resource_paths"]:
if not p.split("/")[1:]:
msg = f"Request creation failed. Resource path '{p}' does not have content after a forward slash ('/')."
raise_error(logger, msg, body)
Comment on lines +116 to +119

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the validity of resource paths should be Arborist's concern, not Requestor's. It looks like Requestor would work fine no matter the format of the resource path. What error/issue are we actually trying to fix here?

@george42-ctds george42-ctds Jul 29, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requestor returns a 500 when receiving a request with a bad resource_path (without a slash), after receiving a 400 from Arborist.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is when creating a new request, it sounds to me like we should catch that 400 from arborist, and return a 400 to the user after getting one from arborist. We shouldn't duplicate the input validation from the server into the client. Arborist probably returns a nice error message that Requestor can forward to the user

if the error happens later, during the automatic call to arborist when requests are approved, then it's a bit more tricky


if data.get("role_ids") and data.get("resource_paths"):

existing_roles = await arborist.list_roles(client)
Expand Down
20 changes: 19 additions & 1 deletion tests/test_manage_resource_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,31 @@ def test_get_auto_policy_id_for_resource_paths_and_role_ids(client, data):
"resource_display_name": "My Resource",
"err_msg": "The request cannot have both role_ids and policy_id",
},
{
# resource_path without slash
"username": "requestor_user",
"resource_path": "path-without-slash",
"resource_id": "uniqid",
"resource_display_name": "My Resource",
"err_msg": "does not have content after a forward slash",
},
{
# resource_paths without slash
"username": "requestor_user",
"role_ids": ["study_registrant"],
"resource_paths": ["path-without-slash"],
"resource_id": "uniqid",
"resource_display_name": "My Resource",
"err_msg": "does not have content after a forward slash",
},
],
)
def test_create_request_with_unallowed_params(client, data):
def test_create_request_with_unallowed_params(client, list_roles_patcher, data):
"""
When a user attempts to create a request with
- role_ids without resource_paths
- both role_ids and policy_id
- resource_paths do not have content following a slash
a 400 Bad request is returned to the client.
"""
fake_jwt = "1.2.3"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_query_resource_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def test_list_requests_with_access(client):

# create requests
request_data = {}
for resource_path in ["/my/resource", "something-i-cant-access"]:
for resource_path in ["/my/resource", "/something-i-cant-access"]:
data = {
"resource_path": resource_path,
"resource_id": "uniqid",
Expand All @@ -151,7 +151,7 @@ def test_list_requests_with_access(client):

# list requests
# the mocked auth_mapping response in mock_arborist_requests does not
# include "something-i-cant-access", so it should not be returned
# include "/something-i-cant-access", so it should not be returned
res = client.get("/request", headers={"Authorization": f"bearer {fake_jwt}"})
assert res.status_code == 200, res.text
assert res.json() == [request_data["/my/resource"]]
Expand Down