mirror of
https://gitlab.com/apparmor/apparmor.git
synced 2025-03-04 16:35:02 +01:00
Implement __deepcopy__() for aare
Thanks to http://bugs.python.org/issue10076, we need to implement this ourself :-/ Also add some tests to ensure __deepcopy__() works as expected. I found this bug while testing the dbus patch series, which crashed aa-cleanprof with TypeError: cannot deepcopy this pattern object Acked-by: John Johansen <john.johansen@canonical.com>
This commit is contained in:
parent
7a25fef5f6
commit
514977f779
2 changed files with 27 additions and 0 deletions
|
@ -46,6 +46,13 @@ class AARE(object):
|
||||||
'''returns a "printable" representation of AARE'''
|
'''returns a "printable" representation of AARE'''
|
||||||
return "AARE('%s')" % self.regex
|
return "AARE('%s')" % self.regex
|
||||||
|
|
||||||
|
def __deepcopy__(self, memo):
|
||||||
|
# thanks to http://bugs.python.org/issue10076, we need to implement this ourself
|
||||||
|
if self.orig_regex:
|
||||||
|
return AARE(self.orig_regex, is_path=False, log_event=True)
|
||||||
|
else:
|
||||||
|
return AARE(self.regex, is_path=False)
|
||||||
|
|
||||||
def match(self, expression):
|
def match(self, expression):
|
||||||
'''check if the given expression (string or AARE) matches the regex'''
|
'''check if the given expression (string or AARE) matches the regex'''
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
import unittest
|
import unittest
|
||||||
from common_test import AATest, setup_all_loops
|
from common_test import AATest, setup_all_loops
|
||||||
|
|
||||||
|
from copy import deepcopy
|
||||||
import re
|
import re
|
||||||
from apparmor.common import convert_regexp, AppArmorBug, AppArmorException
|
from apparmor.common import convert_regexp, AppArmorBug, AppArmorException
|
||||||
from apparmor.aare import AARE, convert_expression_to_aare
|
from apparmor.aare import AARE, convert_expression_to_aare
|
||||||
|
@ -223,6 +224,25 @@ class TestAARERepr(AATest):
|
||||||
obj = AARE('/foo', True)
|
obj = AARE('/foo', True)
|
||||||
self.assertEqual(str(obj), "AARE('/foo')")
|
self.assertEqual(str(obj), "AARE('/foo')")
|
||||||
|
|
||||||
|
class TestAAREDeepcopy(AATest):
|
||||||
|
tests = [
|
||||||
|
# regex is path? log event expected (dummy value)
|
||||||
|
(AARE('/foo', False) , True),
|
||||||
|
(AARE('/foo', False, True) , True),
|
||||||
|
(AARE('/foo', True) , True),
|
||||||
|
(AARE('/foo', True, True) , True),
|
||||||
|
]
|
||||||
|
|
||||||
|
def _run_test(self, params, expected):
|
||||||
|
dup = deepcopy(params)
|
||||||
|
|
||||||
|
self.assertTrue(params.match('/foo'))
|
||||||
|
self.assertTrue(dup.match('/foo'))
|
||||||
|
|
||||||
|
self.assertEqual(params.regex, dup.regex)
|
||||||
|
self.assertEqual(params.orig_regex, dup.orig_regex)
|
||||||
|
self.assertEqual(params.orig_regex, dup.orig_regex)
|
||||||
|
|
||||||
|
|
||||||
setup_all_loops(__name__)
|
setup_all_loops(__name__)
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Add table
Reference in a new issue