def test_empty_ruleset(self):
     ruleset = PtraceRuleset()
     ruleset_2 = PtraceRuleset()
     self.assertEqual([], ruleset.get_raw(2))
     self.assertEqual([], ruleset.get_clean(2))
     self.assertEqual([], ruleset_2.get_raw(2))
     self.assertEqual([], ruleset_2.get_clean(2))
class PtraceGlobTestAATest(AATest):
    def setUp(self):
        self.maxDiff = None
        self.ruleset = PtraceRuleset()

    def test_glob_1(self):
        self.assertEqual(self.ruleset.get_glob('ptrace read,'), 'ptrace,')

    # not supported or used yet
    # def test_glob_2(self):
    #     self.assertEqual(self.ruleset.get_glob('ptrace read raw,'), 'ptrace read,')

    def test_glob_ext(self):
        with self.assertRaises(NotImplementedError):
            # get_glob_ext is not available for ptrace rules
            self.ruleset.get_glob_ext('ptrace read peer=/foo,')
Beispiel #3
0
    def test_empty_ruleset(self):
        ruleset = PtraceRuleset()
        ruleset_2 = PtraceRuleset()
        self.assertEqual([], ruleset.get_raw(2))
        self.assertEqual([], ruleset.get_clean(2))
        self.assertEqual([], ruleset_2.get_raw(2))
        self.assertEqual([], ruleset_2.get_clean(2))

        # test __repr__() for empty ruleset
        as_string = '%s' % ruleset
        self.assertEqual(as_string, '<PtraceRuleset (empty) />')
    def test_ruleset_2(self):
        ruleset = PtraceRuleset()
        rules = [
            'ptrace read peer=/foo,',
            'allow ptrace read,',
            'deny ptrace peer=/bar, # example comment',
        ]

        expected_raw = [
            '  ptrace read peer=/foo,',
            '  allow ptrace read,',
            '  deny ptrace peer=/bar, # example comment',
            '',
        ]

        expected_clean = [
            '  deny ptrace peer=/bar, # example comment',
            '',
            '  allow ptrace read,',
            '  ptrace read peer=/foo,',
            '',
        ]

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

        self.assertEqual(expected_raw, ruleset.get_raw(1))
        self.assertEqual(expected_clean, ruleset.get_clean(1))
Beispiel #5
0
    def test_ruleset_1(self):
        ruleset = PtraceRuleset()
        rules = [
            'ptrace peer=/foo,',
            'ptrace read,',
        ]

        expected_raw = [
            'ptrace peer=/foo,',
            'ptrace read,',
            '',
        ]

        expected_clean = [
            'ptrace peer=/foo,',
            'ptrace read,',
            '',
        ]

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

        self.assertEqual(expected_raw, ruleset.get_raw())
        self.assertEqual(expected_clean, ruleset.get_clean())

        # test __repr__() for non-empty ruleset
        as_string = '%s' % ruleset
        self.assertEqual(
            as_string,
            '<PtraceRuleset>\n  ptrace peer=/foo,\n  ptrace read,\n</PtraceRuleset>'
        )
    def test_ruleset_1(self):
        ruleset = PtraceRuleset()
        rules = [
            'ptrace peer=/foo,',
            'ptrace read,',
        ]

        expected_raw = [
            'ptrace peer=/foo,',
            'ptrace read,',
            '',
        ]

        expected_clean = [
            'ptrace peer=/foo,',
            'ptrace read,',
            '',
        ]

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

        self.assertEqual(expected_raw, ruleset.get_raw())
        self.assertEqual(expected_clean, ruleset.get_clean())
 def setUp(self):
     self.maxDiff = None
     self.ruleset = PtraceRuleset()