Skip to content

Commit

Permalink
fix test_audit_sudo tests (#15060)
Browse files Browse the repository at this point in the history
  • Loading branch information
yocalebo authored Dec 2, 2024
1 parent 262ba1b commit 4dd477b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions tests/api2/test_audit_sudo.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import contextlib
import datetime
import secrets
import string
import time

import pytest

from middlewared.test.integration.assets.account import user
from middlewared.test.integration.utils import call, ssh
from middlewared.test.integration.utils.time_utils import utc_now
from datetime import timezone

EVENT_KEYS = {'timestamp', 'message_timestamp', 'service_data', 'username', 'service', 'audit_id', 'address', 'event_data', 'event', 'session', 'success'}
ACCEPT_KEYS = {'command', 'submituser', 'lines', 'submithost', 'uuid', 'runenv', 'server_time', 'runcwd', 'submitcwd', 'runuid', 'runargv', 'columns', 'runuser', 'submit_time'}
Expand All @@ -21,7 +22,7 @@


def get_utc():
utc_time = int(utc_now().replace(tzinfo=timezone.utc).timestamp())
utc_time = int(utc_now().replace(tzinfo=datetime.timezone.utc).timestamp())
return utc_time


Expand Down Expand Up @@ -182,15 +183,15 @@ def allowed_none(self):
# Now create an event and do some basic checking to ensure it failed
with pytest.raises(AssertionError) as ve:
self.sudo_command('ls /etc')
assert 'is not allowed to execute ' in str(ve), str(ve)
assert f'{self.USER} is not in the sudoers file.' in str(ve), str(ve)
assert count + 1 == wait_for_events(self.USER, count + 1)
event = user_sudo_events(self.USER)[-1]
reject = assert_reject(event)
assert reject['submituser'] == self.USER
assert reject['command'] == LS_COMMAND
assert reject['runuser'] == 'root'
assert reject['runargv'].split(',') == ['ls', '/etc']
assert reject['reason'] == 'command not allowed'
assert reject['reason'] == 'user NOT in sudoers'
# NAS-130373
assert_timestamp(event, reject)

Expand Down

0 comments on commit 4dd477b

Please sign in to comment.