diff --git a/utils/apparmor/aare.py b/utils/apparmor/aare.py index 27012d050..c38423baf 100644 --- a/utils/apparmor/aare.py +++ b/utils/apparmor/aare.py @@ -47,6 +47,15 @@ class AARE: """returns a "printable" representation of object""" return type(self).__name__ + "('%s')" % self.regex + def __eq__(self, other): + """check if the given object is equal + Note that the == check is more strict than is_equal() - it doesn't accept if other is a string instead of AARE""" + + if isinstance(other, type(self)): + return self.regex == other.regex + + return False + def __deepcopy__(self, memo): # thanks to http://bugs.python.org/issue10076, we need to implement this ourself if self.orig_regex: diff --git a/utils/test/test-aare.py b/utils/test/test-aare.py index 4e51a143b..1593bfca2 100644 --- a/utils/test/test-aare.py +++ b/utils/test/test-aare.py @@ -211,6 +211,27 @@ class TestAAREIsEqual(AATest): aare_obj.is_equal(42) +class TestAAREIs_eq(AATest): + tests = ( + # regex is path? check for expected + (('/foo', True, '/foo'), True), + (('@{foo}', True, '@{foo}'), True), + (('/**', True, '/foo'), False), + ) + + def _run_test(self, params, expected): + regex, is_path, check_for = params + aare_obj_1 = AARE(regex, is_path) + aare_obj_2 = AARE(check_for, is_path) + + self.assertEqual(aare_obj_1 == aare_obj_2, expected) + self.assertFalse(aare_obj_1 == check_for) + + def test_is_eq_invalid_1(self): + aare_obj = AARE('/foo/**', True) + self.assertFalse(aare_obj == 42) + + class TestAAREIsPath(AATest): tests = ( # regex is path? match for expected