mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-08-22 18:17:09 +00:00
Merge Split test classes
Create separate classes for tests not fitting under *TestParseInvalid MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1736 Approved-by: Georgia Garcia <georgia.garcia@canonical.com> Merged-by: Christian Boltz <apparmor@cboltz.de>
This commit is contained in:
commit
1c9dc33949
@ -61,6 +61,8 @@ class IOUringTestParseInvalid(AATest):
|
|||||||
def _run_test(self, rawrule, expected):
|
def _run_test(self, rawrule, expected):
|
||||||
self.parseInvalidRule(IOUringRule, rawrule, expected)
|
self.parseInvalidRule(IOUringRule, rawrule, expected)
|
||||||
|
|
||||||
|
|
||||||
|
class IOUringTestIsEqual(AATest):
|
||||||
def test_diff_non_iouringrule(self):
|
def test_diff_non_iouringrule(self):
|
||||||
exp = namedtuple('exp', ('audit', 'deny', 'priority'))
|
exp = namedtuple('exp', ('audit', 'deny', 'priority'))
|
||||||
obj = IOUringRule(('sqpoll'), IOUringRule.ALL)
|
obj = IOUringRule(('sqpoll'), IOUringRule.ALL)
|
||||||
|
@ -138,6 +138,8 @@ class MountTestParseInvalid(AATest):
|
|||||||
def _run_test(self, rawrule, expected):
|
def _run_test(self, rawrule, expected):
|
||||||
self.parseInvalidRule(MountRule, rawrule, expected)
|
self.parseInvalidRule(MountRule, rawrule, expected)
|
||||||
|
|
||||||
|
|
||||||
|
class MountTestInvalid(AATest):
|
||||||
def test_invalid_priority_1(self):
|
def test_invalid_priority_1(self):
|
||||||
with self.assertRaises(TypeError):
|
with self.assertRaises(TypeError):
|
||||||
MountRule('mount', MountRule.ALL, MountRule.ALL, MountRule.ALL, MountRule.ALL, priority=MountRule.ALL)
|
MountRule('mount', MountRule.ALL, MountRule.ALL, MountRule.ALL, MountRule.ALL, priority=MountRule.ALL)
|
||||||
@ -146,17 +148,11 @@ class MountTestParseInvalid(AATest):
|
|||||||
with self.assertRaises(AppArmorException):
|
with self.assertRaises(AppArmorException):
|
||||||
MountRule('mount', MountRule.ALL, MountRule.ALL, MountRule.ALL, MountRule.ALL, priority='invalid')
|
MountRule('mount', MountRule.ALL, MountRule.ALL, MountRule.ALL, MountRule.ALL, priority='invalid')
|
||||||
|
|
||||||
def test_diff_non_mountrule(self):
|
def test_invalid_fstype_equals_or_in(self):
|
||||||
exp = namedtuple('exp', ('audit', 'deny', 'priority'))
|
|
||||||
obj = MountRule('mount', ('=', ['ext4']), MountRule.ALL, MountRule.ALL, MountRule.ALL)
|
|
||||||
with self.assertRaises(AppArmorBug):
|
|
||||||
obj.is_equal(exp(False, False, None), False)
|
|
||||||
|
|
||||||
def test_diff_invalid_fstype_equals_or_in(self):
|
|
||||||
with self.assertRaises(AppArmorBug):
|
with self.assertRaises(AppArmorBug):
|
||||||
MountRule('mount', ('ext3', 'ext4'), MountRule.ALL, MountRule.ALL, MountRule.ALL) # fstype[0] should be '=' or 'in'
|
MountRule('mount', ('ext3', 'ext4'), MountRule.ALL, MountRule.ALL, MountRule.ALL) # fstype[0] should be '=' or 'in'
|
||||||
|
|
||||||
def test_diff_invalid_fstype_aare_2(self):
|
def test_invalid_fstype_aare_2(self):
|
||||||
fslists = [
|
fslists = [
|
||||||
['invalid_{_regex'],
|
['invalid_{_regex'],
|
||||||
['ext4', 'invalid_}_regex'],
|
['ext4', 'invalid_}_regex'],
|
||||||
@ -166,24 +162,14 @@ class MountTestParseInvalid(AATest):
|
|||||||
with self.assertRaises(AppArmorException):
|
with self.assertRaises(AppArmorException):
|
||||||
MountRule('mount', ('=', fslist), MountRule.ALL, MountRule.ALL, MountRule.ALL)
|
MountRule('mount', ('=', fslist), MountRule.ALL, MountRule.ALL, MountRule.ALL)
|
||||||
|
|
||||||
def test_diff_invalid_options_equals_or_in(self):
|
def test_invalid_options_equals_or_in(self):
|
||||||
with self.assertRaises(AppArmorBug):
|
with self.assertRaises(AppArmorBug):
|
||||||
MountRule('mount', MountRule.ALL, ('rbind', 'rw'), MountRule.ALL, MountRule.ALL) # fstype[0] should be '=' or 'in'
|
MountRule('mount', MountRule.ALL, ('rbind', 'rw'), MountRule.ALL, MountRule.ALL) # fstype[0] should be '=' or 'in'
|
||||||
|
|
||||||
def test_diff_invalid_options_keyword(self):
|
def test_invalid_options_keyword(self):
|
||||||
with self.assertRaises(AppArmorException):
|
with self.assertRaises(AppArmorException):
|
||||||
MountRule('mount', MountRule.ALL, ('=', 'invalid'), MountRule.ALL, MountRule.ALL) # fstype[0] should be '=' or 'in'
|
MountRule('mount', MountRule.ALL, ('=', 'invalid'), MountRule.ALL, MountRule.ALL) # fstype[0] should be '=' or 'in'
|
||||||
|
|
||||||
def test_diff_fstype(self):
|
|
||||||
obj1 = MountRule('mount', ('=', ['ext4']), MountRule.ALL, MountRule.ALL, MountRule.ALL)
|
|
||||||
obj2 = MountRule('mount', MountRule.ALL, MountRule.ALL, MountRule.ALL, MountRule.ALL)
|
|
||||||
self.assertFalse(obj1.is_equal(obj2, False))
|
|
||||||
|
|
||||||
def test_diff_source(self):
|
|
||||||
obj1 = MountRule('mount', MountRule.ALL, MountRule.ALL, '/foo', MountRule.ALL)
|
|
||||||
obj2 = MountRule('mount', MountRule.ALL, MountRule.ALL, '/bar', MountRule.ALL)
|
|
||||||
self.assertFalse(obj1.is_equal(obj2, False))
|
|
||||||
|
|
||||||
def test_invalid_umount_with_source(self):
|
def test_invalid_umount_with_source(self):
|
||||||
with self.assertRaises(AppArmorException):
|
with self.assertRaises(AppArmorException):
|
||||||
MountRule('umount', MountRule.ALL, MountRule.ALL, '/foo', MountRule.ALL) # Umount and remount shall not have a source
|
MountRule('umount', MountRule.ALL, MountRule.ALL, '/foo', MountRule.ALL) # Umount and remount shall not have a source
|
||||||
@ -192,11 +178,12 @@ class MountTestParseInvalid(AATest):
|
|||||||
with self.assertRaises(AppArmorException):
|
with self.assertRaises(AppArmorException):
|
||||||
MountRule('remount', MountRule.ALL, MountRule.ALL, '/foo', MountRule.ALL)
|
MountRule('remount', MountRule.ALL, MountRule.ALL, '/foo', MountRule.ALL)
|
||||||
|
|
||||||
def test_invalid_mount_changing_propagation(self):
|
def test_invalid_mount_changing_propagation_1(self):
|
||||||
# Rules changing propagation type can either specify a source or a dest (these are equivalent for apparmor_parser in this specific case) but not both.
|
# Rules changing propagation type can either specify a source or a dest (these are equivalent for apparmor_parser in this specific case) but not both.
|
||||||
with self.assertRaises(AppArmorException):
|
with self.assertRaises(AppArmorException):
|
||||||
MountRule('mount', MountRule.ALL, ('=', ('runbindable')), '/foo', '/bar')
|
MountRule('mount', MountRule.ALL, ('=', ('runbindable')), '/foo', '/bar')
|
||||||
|
|
||||||
|
def test_invalid_mount_changing_propagation_2(self):
|
||||||
# Rules changing propagation type cannot specify a fstype.
|
# Rules changing propagation type cannot specify a fstype.
|
||||||
with self.assertRaises(AppArmorException):
|
with self.assertRaises(AppArmorException):
|
||||||
MountRule('mount', ('=', ('ext4')), ('=', ('runbindable')), MountRule.ALL, '/foo')
|
MountRule('mount', ('=', ('ext4')), ('=', ('runbindable')), MountRule.ALL, '/foo')
|
||||||
@ -213,6 +200,24 @@ class MountTestParseInvalid(AATest):
|
|||||||
obj.is_covered(obj)
|
obj.is_covered(obj)
|
||||||
|
|
||||||
|
|
||||||
|
class MountTestIsEqual(AATest):
|
||||||
|
def test_diff_non_mountrule(self):
|
||||||
|
exp = namedtuple('exp', ('audit', 'deny', 'priority'))
|
||||||
|
obj = MountRule('mount', ('=', ['ext4']), MountRule.ALL, MountRule.ALL, MountRule.ALL)
|
||||||
|
with self.assertRaises(AppArmorBug):
|
||||||
|
obj.is_equal(exp(False, False, None), False)
|
||||||
|
|
||||||
|
def test_diff_fstype(self):
|
||||||
|
obj1 = MountRule('mount', ('=', ['ext4']), MountRule.ALL, MountRule.ALL, MountRule.ALL)
|
||||||
|
obj2 = MountRule('mount', MountRule.ALL, MountRule.ALL, MountRule.ALL, MountRule.ALL)
|
||||||
|
self.assertFalse(obj1.is_equal(obj2, False))
|
||||||
|
|
||||||
|
def test_diff_source(self):
|
||||||
|
obj1 = MountRule('mount', MountRule.ALL, MountRule.ALL, '/foo', MountRule.ALL)
|
||||||
|
obj2 = MountRule('mount', MountRule.ALL, MountRule.ALL, '/bar', MountRule.ALL)
|
||||||
|
self.assertFalse(obj1.is_equal(obj2, False))
|
||||||
|
|
||||||
|
|
||||||
class MountTestGlob(AATest):
|
class MountTestGlob(AATest):
|
||||||
def test_glob(self):
|
def test_glob(self):
|
||||||
globList = [(
|
globList = [(
|
||||||
|
@ -74,6 +74,8 @@ class MessageQueueTestParseInvalid(AATest):
|
|||||||
def _run_test(self, rawrule, expected):
|
def _run_test(self, rawrule, expected):
|
||||||
self.parseInvalidRule(MessageQueueRule, rawrule, expected)
|
self.parseInvalidRule(MessageQueueRule, rawrule, expected)
|
||||||
|
|
||||||
|
|
||||||
|
class MessageQueueTestIsEqual(AATest):
|
||||||
def test_diff_non_mqueuerule(self):
|
def test_diff_non_mqueuerule(self):
|
||||||
exp = namedtuple('exp', ('audit', 'deny', 'priority'))
|
exp = namedtuple('exp', ('audit', 'deny', 'priority'))
|
||||||
obj = MessageQueueRule(('open'), 'posix', 'bar', '/foo')
|
obj = MessageQueueRule(('open'), 'posix', 'bar', '/foo')
|
||||||
|
@ -78,6 +78,8 @@ class UnixTestParseInvalid(AATest):
|
|||||||
def _run_test(self, rawrule, expected):
|
def _run_test(self, rawrule, expected):
|
||||||
self.parseInvalidRule(UnixRule, rawrule, expected)
|
self.parseInvalidRule(UnixRule, rawrule, expected)
|
||||||
|
|
||||||
|
|
||||||
|
class UnixTestInvalid(AATest):
|
||||||
def test_invalid_priority_1(self):
|
def test_invalid_priority_1(self):
|
||||||
with self.assertRaises(TypeError):
|
with self.assertRaises(TypeError):
|
||||||
UnixRule(UnixRule.ALL, UnixRule.ALL, UnixRule.ALL, UnixRule.ALL, False, False, False, '', priority=UnixRule.ALL)
|
UnixRule(UnixRule.ALL, UnixRule.ALL, UnixRule.ALL, UnixRule.ALL, False, False, False, '', priority=UnixRule.ALL)
|
||||||
|
@ -56,6 +56,8 @@ class UserNamespaceTestParseInvalid(AATest):
|
|||||||
def _run_test(self, rawrule, expected):
|
def _run_test(self, rawrule, expected):
|
||||||
self.parseInvalidRule(UserNamespaceRule, rawrule, expected)
|
self.parseInvalidRule(UserNamespaceRule, rawrule, expected)
|
||||||
|
|
||||||
|
|
||||||
|
class UserNamespaceTestIsEqual(AATest):
|
||||||
def test_diff_non_usernsrule(self):
|
def test_diff_non_usernsrule(self):
|
||||||
exp = namedtuple('exp', ('audit', 'deny', 'priority'))
|
exp = namedtuple('exp', ('audit', 'deny', 'priority'))
|
||||||
obj = UserNamespaceRule(('create'))
|
obj = UserNamespaceRule(('create'))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user