コード例 #1
0
    def _check_invalid_rawrule(self, rawrule, matches_regex = False):
        obj = None
        self.assertEqual(AbiRule.match(rawrule), matches_regex)
        with self.assertRaises(AppArmorException):
            obj = AbiRule.parse(rawrule)

        self.assertIsNone(obj, 'AbiRule handed back an object unexpectedly')
コード例 #2
0
    def test_write_manually(self):
        obj = AbiRule('abs/foo', False, True, comment=' # cmt')

        expected = '    abi <abs/foo>, # cmt'

        self.assertEqual(expected, obj.get_clean(2), 'unexpected clean rule')
        self.assertEqual(expected, obj.get_raw(2), 'unexpected raw rule')
コード例 #3
0
    def _run_test(self, rawrule, expected):
        self.assertTrue(AbiRule.match(rawrule))
        obj = AbiRule.parse(rawrule)
        clean = obj.get_clean()
        raw = obj.get_raw()

        self.assertEqual(expected.strip(), clean, 'unexpected clean rule')
        self.assertEqual(rawrule.strip(), raw, 'unexpected raw rule')
コード例 #4
0
    def _run_test(self, param, expected):
        obj = AbiRule.parse(self.rule)
        check_obj = AbiRule.parse(param)

        self.assertTrue(AbiRule.match(param))

        self.assertEqual(obj.is_equal(check_obj), expected[0], 'Mismatch in is_equal, expected %s' % expected[0])
        self.assertEqual(obj.is_equal(check_obj, True), expected[1], 'Mismatch in is_equal/strict, expected %s' % expected[1])

        self.assertEqual(obj.is_covered(check_obj), expected[2], 'Mismatch in is_covered, expected %s' % expected[2])
        self.assertEqual(obj.is_covered(check_obj, True, True), expected[3], 'Mismatch in is_covered/exact, expected %s' % expected[3])
コード例 #5
0
class AbiFromInit(AbiTest):
    tests = [
        # AbiRule object                        ifexists    ismagic                       comment      path                    ifexists    ismagic
        (AbiRule('abi/4.19',                    False,      False)                  , exp('',          'abi/4.19',             False,      False    )),
        (AbiRule('foo',                         False,      False)                  , exp('',          'foo',                  False,      False    )),
        (AbiRule('bar',                         False,      True)                   , exp('',          'bar',                  False,      True     )),
        (AbiRule('comment',                     False,      False, comment='# cmt') , exp('# cmt',     'comment',              False,      False    )),
    ]

    def _run_test(self, obj, expected):
        self._compare_obj(obj, expected)
コード例 #6
0
 def testAdd_abi_2(self):
     self.pl.add_abi('/etc/apparmor.d/bin.foo',
                     AbiRule('abi/4.19', False, True))
     self.pl.add_abi('/etc/apparmor.d/bin.foo',
                     AbiRule('foo', False, False))
     self.assertEqual(list(self.pl.files.keys()),
                      ['/etc/apparmor.d/bin.foo'])
     self.assertEqual(self.pl.get_clean('/etc/apparmor.d/bin.foo'),
                      ['abi <abi/4.19>,', 'abi "foo",', ''])
     self.assertEqual(self.pl.get_raw('/etc/apparmor.d/bin.foo'),
                      ['abi <abi/4.19>,', 'abi "foo",', ''])
コード例 #7
0
 def test_dedup_abi_1(self):
     self.pl.add_abi('/etc/apparmor.d/bin.foo',
                     AbiRule.parse('abi <abi/4.19>,'))
     self.pl.add_abi('/etc/apparmor.d/bin.foo',
                     AbiRule.parse('   abi     <abi/4.19>  ,  # comment'))
     self.assertEqual(list(self.pl.files.keys()),
                      ['/etc/apparmor.d/bin.foo'])
     deleted = self.pl.delete_preamble_duplicates('/etc/apparmor.d/bin.foo')
     self.assertEqual(deleted, 1)
     self.assertEqual(self.pl.get_clean('/etc/apparmor.d/bin.foo'),
                      ['abi <abi/4.19>,', ''])
     self.assertEqual(self.pl.get_raw('/etc/apparmor.d/bin.foo'),
                      ['abi <abi/4.19>,', ''])
コード例 #8
0
    def test_ruleset_1(self):
        ruleset = AbiRuleset()
        rules = [
            ' abi  <foo>  ,',
            ' abi   "/bar", ',
        ]

        expected_raw = [
            'abi  <foo>  ,',
            'abi   "/bar",',
            '',
        ]

        expected_clean = [
            'abi "/bar",',
            'abi <foo>,',
            '',
        ]

        expected_clean_unsorted = [
            'abi <foo>,',
            'abi "/bar",',
            '',
        ]

        for rule in rules:
            ruleset.add(AbiRule.parse(rule))

        self.assertEqual(expected_raw, ruleset.get_raw())
        self.assertEqual(expected_clean, ruleset.get_clean())
        self.assertEqual(expected_clean_unsorted, ruleset.get_clean_unsorted())
コード例 #9
0
 def _run_test(self, params, expected):
     with self.assertRaises(expected):
         AbiRule(params[0], params[1], params[2])
コード例 #10
0
 def test_missing_params_3(self):
     with self.assertRaises(TypeError):
         AbiRule('foo', False)
コード例 #11
0
 def test_audit_true(self):
     with self.assertRaises(AppArmorBug):
         AbiRule('foo', False, False, audit=True)
コード例 #12
0
 def _run_test(self, rawrule, expected):
     self.assertTrue(AbiRule.match(rawrule))  # the above invalid rules still match the main regex!
     with self.assertRaises(expected):
         AbiRule.parse(rawrule)
コード例 #13
0
 def _run_test(self, rawrule, expected):
     self.assertTrue(AbiRule.match(rawrule))
     obj = AbiRule.parse(rawrule)
     self.assertEqual(rawrule.strip(), obj.raw_rule)
     self._compare_obj(obj, expected)
コード例 #14
0
 def _run_test(self, params, expected):
     obj = AbiRule._parse(params)
     self.assertEqual(obj.logprof_header(), expected)
コード例 #15
0
 def test_deny_true(self):
     with self.assertRaises(AppArmorBug):
         AbiRule('foo', False, False, deny=True)
コード例 #16
0
 def test_missing_params_1(self):
     with self.assertRaises(TypeError):
         AbiRule()
コード例 #17
0
 def test_ifexists_true(self):
     with self.assertRaises(AppArmorBug):
         AbiRule('foo', True, False)