Skip to content

Commit

Permalink
Added support for star permissions for extended reservations
Browse files Browse the repository at this point in the history
  • Loading branch information
val500 committed Dec 12, 2024
1 parent eb0972f commit 508cf36
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion server/src/api/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
22 changes: 22 additions & 0 deletions server/tests/test_v1_authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 508cf36

Please sign in to comment.