From 508cf36570090011b7667ebf644ade9836983398 Mon Sep 17 00:00:00 2001 From: Varun Valada Date: Thu, 12 Dec 2024 16:04:28 -0600 Subject: [PATCH] Added support for star permissions for extended reservations --- server/src/api/v1.py | 4 +++- server/tests/test_v1_authorization.py | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/server/src/api/v1.py b/server/src/api/v1.py index b8255c94..bd7c0a27 100644 --- a/server/src/api/v1.py +++ b/server/src/api/v1.py @@ -170,7 +170,9 @@ def check_token_reservation_timeout( return True decoded_jwt = decode_jwt_token(auth_token, secret_key) max_reservation_time_dict = decoded_jwt.get("max_reservation_time", {}) - max_reservation_time = max_reservation_time_dict.get(queue, 0) + queue_reservation_time = max_reservation_time_dict.get(queue, 0) + star_reservation_time = max_reservation_time_dict.get("*", 0) + max_reservation_time = max(queue_reservation_time, star_reservation_time) return reservation_timeout <= max_reservation_time diff --git a/server/tests/test_v1_authorization.py b/server/tests/test_v1_authorization.py index 7dddd349..d157bcda 100644 --- a/server/tests/test_v1_authorization.py +++ b/server/tests/test_v1_authorization.py @@ -374,3 +374,25 @@ def test_normal_reservation_no_token(mongo_app): job = {"job_queue": "myqueue", "reserve_data": {"timeout": 21600}} job_response = app.post("/v1/job", json=job) assert 200 == job_response.status_code + + +def test_star_extended_reservation(mongo_app_with_permissions): + """ + Tests submission to generic queue with extended reservation + when client has star permissions + """ + app, mongo, client_id, client_key, _ = mongo_app_with_permissions + mongo.client_permissions.find_one_and_update( + {"client_id": client_id}, + {"$set": {"max_reservation_time": {"*": 30000}}}, + ) + authenticate_output = app.post( + "/v1/oauth2/token", + headers=create_auth_header(client_id, client_key), + ) + token = authenticate_output.data.decode("utf-8") + job = {"job_queue": "myrandomqueue", "reserve_data": {"timeout": 30000}} + job_response = app.post( + "/v1/job", json=job, headers={"Authorization": token} + ) + assert 200 == job_response.status_code