def _run_test(self, param, expected):
        obj = SignalRule.parse(self.rule)
        check_obj = SignalRule.parse(param)

        self.assertTrue(SignalRule.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])
Esempio n. 2
0
    def test_ruleset_2(self):
        ruleset = SignalRuleset()
        rules = [
            'signal send set=int,',
            'allow signal send,',
            'deny signal set=quit, # example comment',
        ]

        expected_raw = [
            '  signal send set=int,',
            '  allow signal send,',
            '  deny signal set=quit, # example comment',
            '',
        ]

        expected_clean = [
            '  deny signal set=quit, # example comment',
            '',
            '  allow signal send,',
            '  signal send set=int,',
            '',
        ]

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

        self.assertEqual(expected_raw, ruleset.get_raw(1))
        self.assertEqual(expected_clean, ruleset.get_clean(1))
Esempio n. 3
0
    def test_invalid_is_equal(self):
        obj = SignalRule.parse('signal send,')

        testobj = BaseRule()  # different type

        with self.assertRaises(AppArmorBug):
            obj.is_equal(testobj)
Esempio n. 4
0
    def _check_invalid_rawrule(self, rawrule):
        obj = None
        self.assertFalse(SignalRule.match(rawrule))
        with self.assertRaises(AppArmorException):
            obj = SignalRule(SignalRule.parse(rawrule))

        self.assertIsNone(obj, 'SignalRule handed back an object unexpectedly')
Esempio n. 5
0
    def test_borked_obj_is_covered_3(self):
        obj = SignalRule.parse('signal send set=quit peer=/foo,')

        testobj = SignalRule('send', 'quit', '/foo')
        testobj.peer = ''

        with self.assertRaises(AppArmorBug):
            obj.is_covered(testobj)
Esempio n. 6
0
    def _run_test(self, rawrule, expected):
        self.assertTrue(SignalRule.match(rawrule))
        obj = SignalRule.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')
Esempio n. 7
0
    def test_ruleset_1(self):
        ruleset = SignalRuleset()
        rules = [
            'signal set=int,',
            'signal send,',
        ]

        expected_raw = [
            'signal set=int,',
            'signal send,',
            '',
        ]

        expected_clean = [
            'signal send,',
            'signal set=int,',
            '',
        ]

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

        self.assertEqual(expected_raw, ruleset.get_raw())
        self.assertEqual(expected_clean, ruleset.get_clean())
Esempio n. 8
0
 def _run_test(self, rawrule, expected):
     self.assertTrue(SignalRule.match(rawrule))
     obj = SignalRule.parse(rawrule)
     self.assertEqual(rawrule.strip(), obj.raw_rule)
     self._compare_obj(obj, expected)
Esempio n. 9
0
 def _run_test(self, rawrule, expected):
     self.assertTrue(SignalRule.match(
         rawrule))  # the above invalid rules still match the main regex!
     with self.assertRaises(expected):
         SignalRule.parse(rawrule)