mirror of
https://gitlab.com/apparmor/apparmor.git
synced 2025-03-04 16:35:02 +01:00

As Kshitij mentioned, abstract methods should use NotImplementedError instead of AppArmorBug. While changing this, I noticed that __repr__() needs to be robust against NotImplementedError because get_raw() is not available in BaseRule. Therefore the patch changes __repr__() to catch NotImplementedError. Of course the change to NotImplementedError also needs several adjustments in the tests. Acked-by: Kshitij Gupta <kgupta8592@gmail.com> (long before branching off 2.10, therefore I'll also commit to 2.10)
74 lines
2.3 KiB
Python
74 lines
2.3 KiB
Python
#! /usr/bin/env python
|
|
# ------------------------------------------------------------------
|
|
#
|
|
# Copyright (C) 2015 Christian Boltz <apparmor@cboltz.de>
|
|
#
|
|
# This program is free software; you can redistribute it and/or
|
|
# modify it under the terms of version 2 of the GNU General Public
|
|
# License published by the Free Software Foundation.
|
|
#
|
|
# ------------------------------------------------------------------
|
|
|
|
import unittest
|
|
from common_test import AATest, setup_all_loops
|
|
|
|
from apparmor.common import AppArmorBug
|
|
from apparmor.rule import BaseRule, parse_modifiers
|
|
import apparmor.severity as severity
|
|
|
|
import re
|
|
|
|
class TestBaserule(AATest):
|
|
def test_abstract__parse(self):
|
|
with self.assertRaises(NotImplementedError):
|
|
BaseRule._parse('foo')
|
|
|
|
def test_abstract__parse_2(self):
|
|
with self.assertRaises(NotImplementedError):
|
|
BaseRule.parse('foo')
|
|
|
|
def test_abstract__match(self):
|
|
with self.assertRaises(NotImplementedError):
|
|
BaseRule._match('foo')
|
|
|
|
def test_abstract__match2(self):
|
|
with self.assertRaises(NotImplementedError):
|
|
BaseRule.match('foo')
|
|
|
|
def test_abstract_get_clean(self):
|
|
obj = BaseRule()
|
|
with self.assertRaises(NotImplementedError):
|
|
obj.get_clean()
|
|
|
|
def test_is_equal_localvars(self):
|
|
obj = BaseRule()
|
|
with self.assertRaises(NotImplementedError):
|
|
obj.is_equal_localvars(BaseRule())
|
|
|
|
def test_is_covered_localvars(self):
|
|
obj = BaseRule()
|
|
with self.assertRaises(NotImplementedError):
|
|
obj.is_covered_localvars(None)
|
|
|
|
def test_parse_modifiers_invalid(self):
|
|
regex = re.compile('^\s*(?P<audit>audit\s+)?(?P<allow>allow\s+|deny\s+|invalid\s+)?')
|
|
matches = regex.search('audit invalid ')
|
|
|
|
with self.assertRaises(AppArmorBug):
|
|
parse_modifiers(matches)
|
|
|
|
def test_default_severity(self):
|
|
sev_db = severity.Severity('severity.db', 'unknown')
|
|
obj = BaseRule()
|
|
rank = obj.severity(sev_db)
|
|
self.assertEqual(rank, sev_db.NOT_IMPLEMENTED)
|
|
|
|
def test_logprof_header_localvars(self):
|
|
obj = BaseRule()
|
|
with self.assertRaises(NotImplementedError):
|
|
obj.logprof_header_localvars()
|
|
|
|
|
|
setup_all_loops(__name__)
|
|
if __name__ == '__main__':
|
|
unittest.main(verbosity=2)
|