Skip to content

Commit

Permalink
fix test_audit_sudo tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yocalebo committed Dec 2, 2024
1 parent 99b5415 commit 012d98b
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,12 +1,13 @@
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 datetime import datetime, 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 @@ -20,7 +21,7 @@


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


Expand Down Expand Up @@ -181,15 +182,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 012d98b

Please sign in to comment.