mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
acl.ClientACL: add unit tests (#33684)
This commit is contained in:
parent
a74f1b8077
commit
6080846cce
2 changed files with 62 additions and 0 deletions
1
tests/unit/acl/__init__.py
Normal file
1
tests/unit/acl/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
# -*- coding: utf-8 -*-
|
61
tests/unit/acl/client_test.py
Normal file
61
tests/unit/acl/client_test.py
Normal file
|
@ -0,0 +1,61 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
|
||||
# Import Salt Libs
|
||||
from salt import acl
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from salttesting import TestCase, skipIf
|
||||
from salttesting.mock import (
|
||||
NO_MOCK,
|
||||
NO_MOCK_REASON,
|
||||
)
|
||||
from salttesting.helpers import ensure_in_syspath
|
||||
|
||||
ensure_in_syspath('../../')
|
||||
|
||||
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
class ClientACLTestCase(TestCase):
|
||||
'''
|
||||
Unit tests for salt.acl.ClientACL
|
||||
'''
|
||||
def setUp(self):
|
||||
self.blacklist = {
|
||||
'users': ['joker', 'penguin'],
|
||||
'modules': ['cmd.run', 'test.fib'],
|
||||
}
|
||||
|
||||
def test_user_is_blacklisted(self):
|
||||
'''
|
||||
test user_is_blacklisted
|
||||
'''
|
||||
client_acl = acl.ClientACL(self.blacklist)
|
||||
|
||||
self.assertTrue(client_acl.user_is_blacklisted('joker'))
|
||||
self.assertTrue(client_acl.user_is_blacklisted('penguin'))
|
||||
|
||||
self.assertFalse(client_acl.user_is_blacklisted('batman'))
|
||||
self.assertFalse(client_acl.user_is_blacklisted('robin'))
|
||||
|
||||
def test_cmd_is_blacklisted(self):
|
||||
'''
|
||||
test cmd_is_blacklisted
|
||||
'''
|
||||
client_acl = acl.ClientACL(self.blacklist)
|
||||
|
||||
self.assertTrue(client_acl.cmd_is_blacklisted('cmd.run'))
|
||||
self.assertTrue(client_acl.cmd_is_blacklisted('test.fib'))
|
||||
|
||||
self.assertFalse(client_acl.cmd_is_blacklisted('cmd.shell'))
|
||||
self.assertFalse(client_acl.cmd_is_blacklisted('test.versions'))
|
||||
|
||||
self.assertTrue(client_acl.cmd_is_blacklisted(['cmd.run', 'state.sls']))
|
||||
self.assertFalse(client_acl.cmd_is_blacklisted(['state.highstate', 'state.sls']))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from integration import run_tests
|
||||
run_tests(ClientACLTestCase, needs_daemon=False)
|
Loading…
Add table
Reference in a new issue