Skip to content
Merged
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
12 changes: 12 additions & 0 deletions src/requestor/routes/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,18 @@ async def create_request(
f"Found a draft request with request_id: {draft_previous_requests[0].request_id}"
)
request = draft_previous_requests[0]
if request.status != data["status"]:
msg = f'A draft access request for username \'{data["username"]}\' and policy_id \'{data["policy_id"]}\' in status \'{request.status}\' already exists. Use the update endpoint instead if you want to update the status to \'{data["status"]}\'.'
logger.error(
msg
+ f" body: {data}. existing requests: {[r.request_id for r in previous_requests]}",
exc_info=True,
)
raise HTTPException(
HTTP_409_CONFLICT,
msg,
)

else:
# create a new request
data = {"request_id": request_id, **data}
Expand Down
9 changes: 9 additions & 0 deletions tests/test_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ def test_create_duplicate_request(client):
new_request_id = request_data.get("request_id")
assert new_request_id == request_id

# create a request with the same username and policy_id, but a new status.
# since the status does not match, it should fail.
res = client.post(
"/request",
json={**data, "status": "INTERMEDIATE_STATUS"},
headers={"Authorization": f"bearer {fake_jwt}"},
)
assert res.status_code == 409, res.text

# update the orignal request's status to a non-final, non-draft status
res = client.put(f"/request/{request_id}", json={"status": "INTERMEDIATE_STATUS"})
assert res.status_code == 200, res.text
Expand Down
Loading