[apparmor] [patch] Adjust test-signal_parse.py to use SignalRule

Kshitij Gupta kgupta8592 at gmail.com
Wed Nov 18 22:09:49 UTC 2015


On Fri, Oct 23, 2015 at 6:43 PM, Christian Boltz <apparmor at cboltz.de> wrote:

> Hello,
>
> the tests in test-signal_parse.py used aa.parse_signal_rule(), which is
> based on Raw_Signal_Rule (= regex check + "just store it").
>
> This patch changes the tests to test against SignalRule.get_clean().
> Since get_clean does some cleanups, the expected result slightly differs
> from the original rule.
>
> Finally switch to the AATest class and setup_all_loops() we use in most
> tests.
>
>
> Also change test-regex_matches.py to import RE_PROFILE_SIGNAL directly
> from apparmor.regex instead of apparmor.aa (where it will vanish soon).
>
>
>
> [ 08-adjust-tests-to-use-SignalRule.diff ]
>
> === modified file ./utils/test/test-regex_matches.py
> --- utils/test/test-regex_matches.py    2015-10-23 01:35:57.903695924 +0200
> +++ utils/test/test-regex_matches.py    2015-10-23 01:34:43.484064929 +0200
> @@ -14,7 +14,7 @@
>  from common_test import AATest, setup_all_loops
>  from apparmor.common import AppArmorBug, AppArmorException
>
> -from apparmor.regex import strip_quotes, parse_profile_start_line,
> re_match_include, RE_PROFILE_START, RE_PROFILE_CAP
> +from apparmor.regex import strip_quotes, parse_profile_start_line,
> re_match_include, RE_PROFILE_START, RE_PROFILE_CAP, RE_PROFILE_SIGNAL
>
>
>  class AARegexTest(AATest):
> @@ -296,7 +296,7 @@
>      '''Tests for RE_PROFILE_SIGNAL'''
>
>      def AASetup(self):
> -        self.regex = aa.RE_PROFILE_SIGNAL
> +        self.regex = RE_PROFILE_SIGNAL
>
>      tests = [
>          ('   signal,',                                  (None,    None,
> 'signal,',                                  None,
>      None)),
> === modified file ./utils/test/test-signal_parse.py
> --- utils/test/test-signal_parse.py     2014-10-15 20:19:34.705810000 +0200
> +++ utils/test/test-signal_parse.py     2015-10-23 00:14:42.834347424 +0200
> @@ -9,30 +9,34 @@
>  #
>  # ------------------------------------------------------------------
>
> -import apparmor.aa as aa
>  import unittest
> -from common_test import AAParseTest, setup_regex_tests
> +from common_test import AATest, setup_all_loops
> +
> +from apparmor.rule.signal import SignalRule
> +
> +class AAParseSignalTest(AATest):
> +    def _run_test(self, params, expected):
> +        parsed = SignalRule.parse(params)
> +        self.assertEqual(expected, parsed.get_clean())
>
> -class AAParseSignalTest(AAParseTest):
> -    def setUp(self):
> -        self.parse_function = aa.parse_signal_rule
>
>      tests = [
> -        ('signal,', 'signal base keyword rule'),
> -        ('signal (receive),', 'signal receive rule'),
> -        ('signal (send),', 'signal send rule'),
> -        ('signal (send receive),', 'signal multiple perms rule'),
> -        ('signal r,', 'signal r rule'),
> -        ('signal w,', 'signal w rule'),
> -        ('signal rw,', 'signal rw rule'),
> -        ('signal send set=("hup"),', 'signal set rule 1'),
> -        ('signal (receive) set=kill,', 'signal set rule 2'),
> -        ('signal w set=(quit int),', 'signal set rule 3'),
> -        ('signal receive peer=foo,', 'signal peer rule 1'),
> -        ('signal (send receive) peer=/usr/bin/bar,', 'signal peer rule
> 2'),
> -        ('signal wr set=(pipe, usr1) peer=/sbin/baz,', 'signal peer rule
> 3'),
> +        ('signal,',                     'signal,'),
> +        ('signal (receive),',           'signal receive,'),
> +        ('signal (send),',              'signal send,'),
> +        ('signal (send receive),',      'signal (receive send),'),
> +        ('signal r,',                   'signal r,'),
> +        ('signal w,',                   'signal w,'),
> +        ('signal rw,',                  'signal rw,'),
> +        ('signal send set=("hup"),',    'signal send set=hup,'),
> +        ('signal (receive) set=kill,',  'signal receive set=kill,'),
> +        ('signal w set=(quit int),',    'signal w set=(int quit),'),
> +        ('signal receive peer=foo,',    'signal receive peer=foo,'),
> +        ('signal (send receive) peer=/usr/bin/bar,',    'signal (receive
> send) peer=/usr/bin/bar,'),
> +        ('signal wr set=(pipe, usr1) peer=/sbin/baz,',  'signal wr
> set=(pipe usr1) peer=/sbin/baz,'),
>      ]
>
> +
> +setup_all_loops(__name__)
>  if __name__ == '__main__':
> -    setup_regex_tests(AAParseSignalTest)
>      unittest.main(verbosity=2)
>
> Thanks for the patch.

Acked-by: Kshitij Gupta <kgupta8592 at gmail.com>

>
> Regards,
>
> Christian Boltz
> --
> > Wrong ;-)
> Ah, diplomacy at its finest.
> [> Christian Boltz and Steve Beattie in apparmor]
>
>
> --
> AppArmor mailing list
> AppArmor at lists.ubuntu.com
> Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/apparmor
>



-- 
Regards,

Kshitij Gupta
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/apparmor/attachments/20151119/639f6324/attachment.html>


More information about the AppArmor mailing list