mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-09-03 15:55:46 +00:00
Convert test-capability.py to AATest
I decided to use a "small" solution for now, which basically means s/unittest.TestCase/AATest/, cleanup of some setUp() and renaming the remaining setUp() functions to AASetup(). This doesn't mean an instant win (like in test-severity.py), but allows to add tests with a tests[] array. Acked-by: Steve Beattie <steve@nxnw.org>
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
from common_test import AATest, setup_all_loops
|
||||||
|
|
||||||
from apparmor.rule.capability import CapabilityRule, CapabilityRuleset
|
from apparmor.rule.capability import CapabilityRule, CapabilityRuleset
|
||||||
from apparmor.rule import BaseRule
|
from apparmor.rule import BaseRule
|
||||||
@@ -22,10 +23,7 @@ from apparmor.logparser import ReadLog
|
|||||||
|
|
||||||
# --- tests for single CapabilityRule --- #
|
# --- tests for single CapabilityRule --- #
|
||||||
|
|
||||||
class CapabilityTest(unittest.TestCase):
|
class CapabilityTest(AATest):
|
||||||
def setUp(self):
|
|
||||||
self.maxDiff = None
|
|
||||||
|
|
||||||
def _compare_obj_with_rawrule(self, rawrule, expected):
|
def _compare_obj_with_rawrule(self, rawrule, expected):
|
||||||
|
|
||||||
obj = CapabilityRule.parse(rawrule)
|
obj = CapabilityRule.parse(rawrule)
|
||||||
@@ -212,10 +210,7 @@ class CapabilityTest(unittest.TestCase):
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
class InvalidCapabilityTest(unittest.TestCase):
|
class InvalidCapabilityTest(AATest):
|
||||||
def setUp(self):
|
|
||||||
self.maxDiff = None
|
|
||||||
|
|
||||||
def _check_invalid_rawrule(self, rawrule):
|
def _check_invalid_rawrule(self, rawrule):
|
||||||
obj = None
|
obj = None
|
||||||
with self.assertRaises(AppArmorException):
|
with self.assertRaises(AppArmorException):
|
||||||
@@ -262,10 +257,7 @@ class InvalidCapabilityTest(unittest.TestCase):
|
|||||||
CapabilityRule(dict())
|
CapabilityRule(dict())
|
||||||
|
|
||||||
|
|
||||||
class WriteCapabilityTest(unittest.TestCase):
|
class WriteCapabilityTest(AATest):
|
||||||
def setUp(self):
|
|
||||||
self.maxDiff = None
|
|
||||||
|
|
||||||
def _check_write_rule(self, rawrule, cleanrule):
|
def _check_write_rule(self, rawrule, cleanrule):
|
||||||
obj = CapabilityRule.parse(rawrule)
|
obj = CapabilityRule.parse(rawrule)
|
||||||
clean = obj.get_clean()
|
clean = obj.get_clean()
|
||||||
@@ -292,10 +284,7 @@ class WriteCapabilityTest(unittest.TestCase):
|
|||||||
self.assertEqual(expected, obj.get_clean(2), 'unexpected clean rule')
|
self.assertEqual(expected, obj.get_clean(2), 'unexpected clean rule')
|
||||||
self.assertEqual(expected, obj.get_raw(2), 'unexpected raw rule')
|
self.assertEqual(expected, obj.get_raw(2), 'unexpected raw rule')
|
||||||
|
|
||||||
class CapabilityCoveredTest(unittest.TestCase):
|
class CapabilityCoveredTest(AATest):
|
||||||
def setUp(self):
|
|
||||||
self.maxDiff = None
|
|
||||||
|
|
||||||
def _is_covered(self, obj, rule_to_test):
|
def _is_covered(self, obj, rule_to_test):
|
||||||
self.assertTrue(CapabilityRule.match(rule_to_test))
|
self.assertTrue(CapabilityRule.match(rule_to_test))
|
||||||
return obj.is_covered(CapabilityRule.parse(rule_to_test))
|
return obj.is_covered(CapabilityRule.parse(rule_to_test))
|
||||||
@@ -432,10 +421,7 @@ class CapabilityCoveredTest(unittest.TestCase):
|
|||||||
|
|
||||||
# --- tests for CapabilityRuleset --- #
|
# --- tests for CapabilityRuleset --- #
|
||||||
|
|
||||||
class CapabilityRulesTest(unittest.TestCase):
|
class CapabilityRulesTest(AATest):
|
||||||
def setUp(self):
|
|
||||||
self.maxDiff = None
|
|
||||||
|
|
||||||
def test_empty_ruleset(self):
|
def test_empty_ruleset(self):
|
||||||
ruleset = CapabilityRuleset()
|
ruleset = CapabilityRuleset()
|
||||||
ruleset_2 = CapabilityRuleset()
|
ruleset_2 = CapabilityRuleset()
|
||||||
@@ -515,10 +501,8 @@ class CapabilityRulesTest(unittest.TestCase):
|
|||||||
self.assertEqual(expected_clean, ruleset.get_clean(1))
|
self.assertEqual(expected_clean, ruleset.get_clean(1))
|
||||||
|
|
||||||
|
|
||||||
class CapabilityRulesCoveredTest(unittest.TestCase):
|
class CapabilityRulesCoveredTest(AATest):
|
||||||
def setUp(self):
|
def AASetup(self):
|
||||||
self.maxDiff = None
|
|
||||||
|
|
||||||
self.ruleset = CapabilityRuleset()
|
self.ruleset = CapabilityRuleset()
|
||||||
rules = [
|
rules = [
|
||||||
'capability chown,',
|
'capability chown,',
|
||||||
@@ -611,9 +595,8 @@ class CapabilityRulesCoveredTest(unittest.TestCase):
|
|||||||
# parser = ReadLog('', '', '', '', '')
|
# parser = ReadLog('', '', '', '', '')
|
||||||
# self.assertEqual(True, self.ruleset.is_log_covered(parser.parse_event(event_base%'chgrp'), False)) # ignores allow/deny
|
# self.assertEqual(True, self.ruleset.is_log_covered(parser.parse_event(event_base%'chgrp'), False)) # ignores allow/deny
|
||||||
|
|
||||||
class CapabilityGlobTest(unittest.TestCase):
|
class CapabilityGlobTest(AATest):
|
||||||
def setUp(self):
|
def AASetup(self):
|
||||||
self.maxDiff = None
|
|
||||||
self.ruleset = CapabilityRuleset()
|
self.ruleset = CapabilityRuleset()
|
||||||
|
|
||||||
def test_glob(self):
|
def test_glob(self):
|
||||||
@@ -623,10 +606,8 @@ class CapabilityGlobTest(unittest.TestCase):
|
|||||||
with self.assertRaises(AppArmorBug):
|
with self.assertRaises(AppArmorBug):
|
||||||
self.ruleset.get_glob_ext('capability net_raw,')
|
self.ruleset.get_glob_ext('capability net_raw,')
|
||||||
|
|
||||||
class CapabilityDeleteTest(unittest.TestCase):
|
class CapabilityDeleteTest(AATest):
|
||||||
def setUp(self):
|
def AASetup(self):
|
||||||
self.maxDiff = None
|
|
||||||
|
|
||||||
self.ruleset = CapabilityRuleset()
|
self.ruleset = CapabilityRuleset()
|
||||||
rules = [
|
rules = [
|
||||||
'capability chown,',
|
'capability chown,',
|
||||||
@@ -974,5 +955,6 @@ class CapabilityDeleteTest(unittest.TestCase):
|
|||||||
self._check_test_delete_duplicates_in_profile(rules, expected_raw, expected_clean, expected_deleted)
|
self._check_test_delete_duplicates_in_profile(rules, expected_raw, expected_clean, expected_deleted)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
setup_all_loops(__name__)
|
||||||
|
if __name__ == '__main__':
|
||||||
unittest.main(verbosity=2)
|
unittest.main(verbosity=2)
|
||||||
|
Reference in New Issue
Block a user