diff --git a/utils/test/test-io_uring.py b/utils/test/test-io_uring.py index 355d47d84..7e09b1ce9 100644 --- a/utils/test/test-io_uring.py +++ b/utils/test/test-io_uring.py @@ -61,6 +61,8 @@ class IOUringTestParseInvalid(AATest): def _run_test(self, rawrule, expected): self.parseInvalidRule(IOUringRule, rawrule, expected) + +class IOUringTestIsEqual(AATest): def test_diff_non_iouringrule(self): exp = namedtuple('exp', ('audit', 'deny', 'priority')) obj = IOUringRule(('sqpoll'), IOUringRule.ALL) diff --git a/utils/test/test-mount.py b/utils/test/test-mount.py index 62bdbea3b..37acf3c9e 100644 --- a/utils/test/test-mount.py +++ b/utils/test/test-mount.py @@ -138,6 +138,8 @@ class MountTestParseInvalid(AATest): def _run_test(self, rawrule, expected): self.parseInvalidRule(MountRule, rawrule, expected) + +class MountTestInvalid(AATest): def test_invalid_priority_1(self): with self.assertRaises(TypeError): MountRule('mount', MountRule.ALL, MountRule.ALL, MountRule.ALL, MountRule.ALL, priority=MountRule.ALL) @@ -146,17 +148,11 @@ class MountTestParseInvalid(AATest): with self.assertRaises(AppArmorException): MountRule('mount', MountRule.ALL, MountRule.ALL, MountRule.ALL, MountRule.ALL, priority='invalid') - 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_invalid_fstype_equals_or_in(self): + def test_invalid_fstype_equals_or_in(self): with self.assertRaises(AppArmorBug): 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 = [ ['invalid_{_regex'], ['ext4', 'invalid_}_regex'], @@ -166,24 +162,14 @@ class MountTestParseInvalid(AATest): with self.assertRaises(AppArmorException): 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): 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): 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): with self.assertRaises(AppArmorException): 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): 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. with self.assertRaises(AppArmorException): MountRule('mount', MountRule.ALL, ('=', ('runbindable')), '/foo', '/bar') + def test_invalid_mount_changing_propagation_2(self): # Rules changing propagation type cannot specify a fstype. with self.assertRaises(AppArmorException): MountRule('mount', ('=', ('ext4')), ('=', ('runbindable')), MountRule.ALL, '/foo') @@ -213,6 +200,24 @@ class MountTestParseInvalid(AATest): 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): def test_glob(self): globList = [( diff --git a/utils/test/test-mqueue.py b/utils/test/test-mqueue.py index 8c6483a7e..84c387670 100644 --- a/utils/test/test-mqueue.py +++ b/utils/test/test-mqueue.py @@ -74,6 +74,8 @@ class MessageQueueTestParseInvalid(AATest): def _run_test(self, rawrule, expected): self.parseInvalidRule(MessageQueueRule, rawrule, expected) + +class MessageQueueTestIsEqual(AATest): def test_diff_non_mqueuerule(self): exp = namedtuple('exp', ('audit', 'deny', 'priority')) obj = MessageQueueRule(('open'), 'posix', 'bar', '/foo') diff --git a/utils/test/test-unix.py b/utils/test/test-unix.py index abfbc66a5..7d6024765 100644 --- a/utils/test/test-unix.py +++ b/utils/test/test-unix.py @@ -78,6 +78,8 @@ class UnixTestParseInvalid(AATest): def _run_test(self, rawrule, expected): self.parseInvalidRule(UnixRule, rawrule, expected) + +class UnixTestInvalid(AATest): def test_invalid_priority_1(self): with self.assertRaises(TypeError): UnixRule(UnixRule.ALL, UnixRule.ALL, UnixRule.ALL, UnixRule.ALL, False, False, False, '', priority=UnixRule.ALL) diff --git a/utils/test/test-userns.py b/utils/test/test-userns.py index cab622ab2..9fc5290f6 100644 --- a/utils/test/test-userns.py +++ b/utils/test/test-userns.py @@ -56,6 +56,8 @@ class UserNamespaceTestParseInvalid(AATest): def _run_test(self, rawrule, expected): self.parseInvalidRule(UserNamespaceRule, rawrule, expected) + +class UserNamespaceTestIsEqual(AATest): def test_diff_non_usernsrule(self): exp = namedtuple('exp', ('audit', 'deny', 'priority')) obj = UserNamespaceRule(('create'))