apparmor/utils/test
John Johansen b85046648b parser: fix rule flag generation change_mount type rules
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1048
made it so rules like

  mount slave /snap/bin/** -> /**,

  mount /snap/bin/** -> /**,

would get passed into change_mount_type rule generation when they
shouldn't have been. This would result in two different errors.

1. If kernel mount flags were present on the rule. The error would
   be caught causing an error to be returned, causing profile compilation
   to fail.

2. If the rule did not contain explicit flags then rule would generate
   change_mount_type permissions based on souly the mount point. And
   the implied set of flags. However this is incorrect as it should
   not generate change_mount permissions for this type of rule. Not
   only does it ignore the source/device type condition but it
   generates permissions that were never intended.

   When used in combination with a deny prefix this overly broad
   rule can result in almost all mount rules being denied, as the
   denial takes priority over the allow mount rules.

Fixes: https://bugs.launchpad.net/apparmor/+bug/2023814
Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1211989
Fixes: 9d3f8c6cc ("parser: fix parsing of source as mount point for propagation type flags")
Fixes: MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1048

Signed-off-by: John Johansen <john.johansen@canonical.com>
(cherry picked from commit 86d193e183)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-06-21 01:20:34 -07:00
..
wtmp-examples Add truncated and ancient wtmp example to tests 2021-11-08 12:54:19 -08:00
cleanprof_test.in Let aa-cleanprof remove duplicate preamble rules 2020-05-20 18:54:53 +02:00
cleanprof_test.out Store variables in active_profiles (ProfileList) 2020-05-27 13:32:44 +02:00
common_test.py utils: Require apparmor.aa users to call init_aa() 2017-03-02 21:21:53 +00:00
easyprof.conf This patchset is broken into 4 parts: 2012-05-07 22:37:48 -07:00
fake_ldd utils: fixup test-aa.py tests that fail due to usr-merge 2019-02-12 23:17:59 -08:00
logprof.conf Drop profile repo code from utils 2020-05-05 13:09:16 +02:00
Makefile reviewed edits 2022-07-19 22:33:52 +02:00
minitools_test.py change_profile_flags: use ', ' as flags delimiter 2018-07-25 21:33:22 +02:00
README.md use new build_platlib path with setuptools >= 61.2 2022-07-19 22:32:32 +02:00
runtests-py2.sh utils/tests: fix bashisms in runtests-py2.sh 2014-09-03 13:00:33 -07:00
runtests-py3.sh fix utils/test/runtests-py*.sh exitcode 2014-10-03 11:48:21 +02:00
severity.db Update perl abstraction, logprof.conf, severity.db and tests for Debian/Ubuntu 2014-08-20 19:14:24 -05:00
severity_broken.db Update perl abstraction, logprof.conf, severity.db and tests for Debian/Ubuntu 2014-08-20 19:14:24 -05:00
test-aa-cli-bootstrap.py Add tests for shared aa library functions used in command line scripts 2019-04-21 18:37:10 +03:00
test-aa-decode.py Bugfix aa-decode test: Get stderr correctly, don't ignore stderr contents 2019-02-05 00:15:13 +02:00
test-aa-easyprof.py Replace deprecated assertEquals with assertEqual 2019-02-26 21:27:00 +01:00
test-aa-notify.py Merge make test-aa-notify test_help_contents () less strict 2022-02-15 11:19:29 -08:00
test-aa.py Add checks to load_include() to ensure absolute paths 2020-06-05 20:02:33 +02:00
test-aare.py test that '\*' from audit.log gets correctly escaped 2020-04-13 19:46:05 +02:00
test-abi.py Add AbiRule and testsuite 2020-05-09 21:02:06 +02:00
test-alias.py Add AliasRule and AliasRuleset classes 2020-05-27 14:05:38 +02:00
test-baserule.py make utils tests less verbose 2018-04-08 20:18:30 +02:00
test-capability.py libapparmor: add support for class in logparsing 2023-02-24 04:17:16 -08:00
test-change_profile.py libapparmor: add support for class in logparsing 2023-02-24 04:17:16 -08:00
test-common.py Fix comment in split_name() tests 2021-01-10 03:36:20 -08:00
test-config.py Drop profile repo code from utils 2020-05-05 13:09:16 +02:00
test-dbus.py libapparmor: add support for class in logparsing 2023-02-24 04:17:16 -08:00
test-example.py add an example for setup_aa() to test-example.py 2019-02-10 23:24:29 +01:00
test-file.py libapparmor: add support for class in logparsing 2023-02-24 04:17:16 -08:00
test-include.py IncludeRule: sort files in included directory 2020-05-28 20:17:29 +02:00
test-libapparmor-test_multi.py Add change_profile support to aa-logprof 2020-09-20 17:07:18 +02:00
test-logparser.py libapparmor: add support for class in logparsing 2023-02-24 04:17:16 -08:00
test-mount_parse.py make utils tests less verbose 2018-04-08 20:18:30 +02:00
test-network.py libapparmor: add support for class in logparsing 2023-02-24 04:17:16 -08:00
test-notify.py Add tests for sane_timestamp 2021-11-08 12:54:19 -08:00
test-parser-simple-tests.py parser: fix rule flag generation change_mount type rules 2023-06-21 01:20:34 -07:00
test-pivot_root_parse.py make utils tests less verbose 2018-04-08 20:18:30 +02:00
test-profile-list.py Add missing test for ProfileList add_alias() 2021-01-10 03:36:48 -08:00
test-profile-storage.py add_or_remove_flag(): allow to add or remove multiple flags 2020-09-24 23:21:54 +02:00
test-ptrace.py libapparmor: add support for class in logparsing 2023-02-24 04:17:16 -08:00
test-regex_matches.py add re_match_include_parse() test with invalid rule name 2021-01-10 14:45:27 -08:00
test-rlimit.py Remove superfluous self-cast in Invalid*Test 2020-05-02 22:13:34 +02:00
test-severity.py severity: replace load_variables() with set_variables() 2020-05-27 13:32:44 +02:00
test-signal.py libapparmor: add support for class in logparsing 2023-02-24 04:17:16 -08:00
test-translations.py Merge Fix hotkey conflict in utils de.po and id.po 2020-11-01 01:29:57 -08:00
test-unix_parse.py make utils tests less verbose 2018-04-08 20:18:30 +02:00
test-variable.py Detect invalid trailing commas in variable definitions 2020-05-27 13:32:44 +02:00

Running individual tests

Python's unittest allows individual tests to be executed by specifying the class name and the test on the command line. When running tests individually, the unittest framework executes the "setUp" and "tearDown" methods automatically. For more information, refer to the unittest documentation.

Make sure to set the environment variables pointing to the in-tree apparmor modules, and the in-tree libapparmor and its python wrapper:

$ export PYTHONPATH=..:../../libraries/libapparmor/swig/python/build/$(/usr/bin/python3 ../../libraries/libapparmor/swig/python/test/buildpath.py)
$ export __AA_CONFDIR=.

To execute the test individually, run:

$ python3 ./test-tile.py ClassFoo.test_bar