Skip to content

Commit

Permalink
Use a proper job id for download token test (#15665)
Browse files Browse the repository at this point in the history
We now raise exception if job id does not match an existing
job for the user.

(cherry picked from commit 8103aba)

Co-authored-by: Andrew Walker <[email protected]>
  • Loading branch information
bugclerk and anodos325 authored Feb 10, 2025
1 parent d034a0c commit 89f1344
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions tests/api2/test_audit_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@
from middlewared.test.integration.utils.audit import expect_audit_log


@pytest.fixture(scope="module")
def job_with_pipe():
job_id, url = call("core.download", "config.save" , [], "debug.txz")
try:
yield job_id
finally:
call("core.job_abort", job_id)


@pytest.fixture(scope="module")
def download_token(job_with_pipe):
return call("auth.generate_token", 300, {"filename": "debug.txz", "job": job_with_pipe}, True)


@pytest.fixture(scope='function')
def sharing_admin_user(unprivileged_user_fixture):
privilege = call('privilege.query', [['local_groups.0.group', '=', unprivileged_user_fixture.group_name]])
Expand Down Expand Up @@ -315,9 +329,7 @@ def test_token_login_failed():
c.call("auth.login_with_token", "invalid_token")


def test_token_attributes_login_failed():
token = call("auth.generate_token", 300, {"filename": "debug.txz", "job": 1020}, True)

def test_token_attributes_login_failed(download_token):
with client(auth=None) as c:
with expect_audit_log([
{
Expand All @@ -326,15 +338,15 @@ def test_token_attributes_login_failed():
"credentials": {
"credentials": "TOKEN",
"credentials_data": {
"token": token,
"token": download_token,
},
},
"error": "Bad token",
},
"success": False,
}
], include_logins=True):
c.call("auth.login_with_token", token)
c.call("auth.login_with_token", download_token)


def test_api_key_login():
Expand Down

0 comments on commit 89f1344

Please sign in to comment.