[apparmor] [patch] [3/7] Adjust test-ptrace_parse.py to use PtraceRule
John Johansen
john.johansen at canonical.com
Sat Dec 26 23:35:11 UTC 2015
On 12/08/2015 11:32 AM, Christian Boltz wrote:
> Hello,
>
> the tests in test-ptrace_parse.py used aa.parse_ptrace_rule(), which is
> based on Raw_Ptrace_Rule (= regex check + "just store it").
>
> This patch changes the tests to test against PtraceRule.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).
>
>
Acked-by: John Johansen <john.johansen at canonical.com>
>
> [ 30-change-test-ptrace_parse-to-PtraceRule.diff ]
>
> --- utils/test/test-ptrace_parse.py 2014-10-15 20:19:34.705810000 +0200
> +++ utils/test/test-ptrace_parse.py 2015-11-23 23:35:50.949678241 +0100
> @@ -9,27 +9,29 @@
> #
> # ------------------------------------------------------------------
>
> -import apparmor.aa as aa
> import unittest
> -from common_test import AAParseTest, setup_regex_tests
> +from common_test import AATest, setup_all_loops
>
> -class AAParsePtraceTest(AAParseTest):
> - def setUp(self):
> - self.parse_function = aa.parse_ptrace_rule
> +from apparmor.rule.ptrace import PtraceRule
> +
> +class AAParsePtraceTest(AATest):
> + def _run_test(self, params, expected):
> + rule_obj = PtraceRule.parse(params)
> + self.assertEqual(rule_obj.get_clean(), expected)
>
> tests = [
> - ('ptrace,', 'ptrace base keyword rule'),
> - ('ptrace (readby),', 'ptrace readby rule'),
> - ('ptrace (trace),', 'ptrace trace rule'),
> - ('ptrace (trace read),', 'ptrace multi-perm rule'),
> - ('ptrace r,', 'ptrace r rule'),
> - ('ptrace w,', 'ptrace w rule'),
> - ('ptrace rw,', 'ptrace rw rule'),
> - ('ptrace read peer=foo,', 'ptrace peer rule 1'),
> - ('ptrace (trace read) peer=/usr/bin/bar,', 'ptrace peer rule 2'),
> - ('ptrace wr peer=/sbin/baz,', 'ptrace peer rule 3'),
> + ('ptrace,', 'ptrace,'),
> + ('ptrace (readby),', 'ptrace readby,'),
> + ('ptrace (trace),', 'ptrace trace,'),
> + ('ptrace (trace read),', 'ptrace (read trace),'),
> + ('ptrace r,', 'ptrace r,'),
> + ('ptrace w,', 'ptrace w,'),
> + ('ptrace rw,', 'ptrace rw,'),
> + ('ptrace read peer=foo,', 'ptrace read peer=foo,'),
> + ('ptrace (trace read) peer=/usr/bin/bar,', 'ptrace (read trace) peer=/usr/bin/bar,'),
> + ('ptrace wr peer=/sbin/baz,', 'ptrace wr peer=/sbin/baz,'),
> ]
>
> +setup_all_loops(__name__)
> if __name__ == '__main__':
> - setup_regex_tests(AAParsePtraceTest)
> unittest.main(verbosity=2)
> --- utils/test/test-regex_matches.py 2015-11-23 21:52:31.595734935 +0100
> +++ utils/test/test-regex_matches.py 2015-11-23 23:39:24.316157430 +0100
> @@ -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, RE_PROFILE_SIGNAL
> +from apparmor.regex import strip_quotes, parse_profile_start_line, re_match_include, RE_PROFILE_START, RE_PROFILE_CAP, RE_PROFILE_PTRACE, RE_PROFILE_SIGNAL
>
>
> class AARegexTest(AATest):
> @@ -318,7 +318,7 @@
> '''Tests for RE_PROFILE_PTRACE'''
>
> def AASetup(self):
> - self.regex = aa.RE_PROFILE_PTRACE
> + self.regex = RE_PROFILE_PTRACE
>
> tests = [
> # audit allow rule rule details comment
>
>
> Regards,
>
> Christian Boltz
>
More information about the AppArmor
mailing list