2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-22 10:07:12 +00:00
apparmor/utils/test/test-ptrace_parse.py
Christian Boltz c303214286 Adjust test-ptrace_parse.py to use PtraceRule
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@canonical.com>
2015-12-27 01:16:55 +01:00

38 lines
1.4 KiB
Python

#! /usr/bin/env python
# ------------------------------------------------------------------
#
# Copyright (C) 2014 Canonical Ltd.
#
# 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.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,'),
('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__':
unittest.main(verbosity=2)