From df0358062d233def02f99a2ad25dfd564a234c22 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Thu, 27 Feb 2025 12:14:31 -0800 Subject: [PATCH] utils: test: expand mechanism for ignoring profiles in tests The utils cannot parse some of the newer profile constructs yet, so generalize a pre-existing mechanism for skipping profiles to use that mechanism in the other tests that need it Signed-off-by: Ryan Lee --- utils/test/common_test.py | 7 +++++++ utils/test/test-logprof.py | 5 +++-- utils/test/test-minitools.py | 5 +++-- utils/test/test-profile-list.py | 6 ++++-- utils/test/test-profiles.py | 9 +-------- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/utils/test/common_test.py b/utils/test/common_test.py index 75e6ceea0..3931c0d89 100755 --- a/utils/test/common_test.py +++ b/utils/test/common_test.py @@ -24,6 +24,13 @@ import unittest # print("Please press the Y button on the keyboard.") # self.assertEqual(apparmor.common.readkey().lower(), 'y', 'Error reading key from shell!') +# If a profile can't be parsed by the tools, add it to skip_active_profiles or skip_extra_profiles. +# Add only the filename (without path), for example 'usr.bin.foo'. +# These skip lists are meant as a temporary solution, and should be empty on release. +skip_active_profiles = [] + +skip_extra_profiles = [] + class AATest(unittest.TestCase): def setUp(self): diff --git a/utils/test/test-logprof.py b/utils/test/test-logprof.py index f82179844..9800bb2d3 100644 --- a/utils/test/test-logprof.py +++ b/utils/test/test-logprof.py @@ -16,7 +16,7 @@ import sys import unittest # import apparmor.aa as aa # see the setup_aa() call for details -from common_test import AATest, read_file, setup_all_loops # , setup_aa +from common_test import AATest, read_file, setup_all_loops, skip_active_profiles # , setup_aa class TestLogprof(AATest): @@ -35,7 +35,8 @@ class TestLogprof(AATest): # copy the local profiles to the test directory self.profile_dir = self.tmpdir + '/profiles' - shutil.copytree('../../profiles/apparmor.d/', self.profile_dir, symlinks=True) + shutil.copytree('../../profiles/apparmor.d/', self.profile_dir, + symlinks=True, ignore=shutil.ignore_patterns(*skip_active_profiles)) def AATeardown(self): self._terminate() diff --git a/utils/test/test-minitools.py b/utils/test/test-minitools.py index bd2986399..e58017fe0 100755 --- a/utils/test/test-minitools.py +++ b/utils/test/test-minitools.py @@ -18,7 +18,7 @@ import sys import unittest import apparmor.aa as apparmor -from common_test import AATest, read_file, write_file, setup_aa, setup_all_loops +from common_test import AATest, read_file, write_file, setup_aa, setup_all_loops, skip_active_profiles # Use the same python as the one this script is being run with python_interpreter = sys.executable @@ -34,7 +34,8 @@ class MinitoolsTest(AATest): # copy the local profiles to the test directory # Should be the set of cleanprofile self.profile_dir = self.tmpdir + '/profiles' - shutil.copytree('../../profiles/apparmor.d/', self.profile_dir, symlinks=True) + shutil.copytree('../../profiles/apparmor.d/', self.profile_dir, + symlinks=True, ignore=shutil.ignore_patterns(*skip_active_profiles)) apparmor.profile_dir = self.profile_dir diff --git a/utils/test/test-profile-list.py b/utils/test/test-profile-list.py index 0f81763fc..1da177972 100644 --- a/utils/test/test-profile-list.py +++ b/utils/test/test-profile-list.py @@ -24,7 +24,7 @@ from apparmor.rule.alias import AliasRule from apparmor.rule.boolean import BooleanRule from apparmor.rule.include import IncludeRule from apparmor.rule.variable import VariableRule -from common_test import AATest, setup_aa, setup_all_loops, write_file +from common_test import AATest, setup_aa, setup_all_loops, write_file, skip_active_profiles class TestAdd_profile(AATest): @@ -428,7 +428,9 @@ class AaTest_get_all_merged_variables(AATest): # load the profiles and abstractions apparmor.aa.profile_dir = self.profile_dir apparmor.aa.loadincludes() - apparmor.aa.read_profiles() + # Keep this synced with the list in test-logprof.py and + # test-minitools.py + apparmor.aa.read_profiles(skip_profiles=skip_active_profiles) def test_unchanged(self): self._load_profiles() diff --git a/utils/test/test-profiles.py b/utils/test/test-profiles.py index b8300a0c5..c0b3e080c 100644 --- a/utils/test/test-profiles.py +++ b/utils/test/test-profiles.py @@ -12,14 +12,7 @@ import unittest import apparmor.aa as aa -from common_test import AATest, setup_aa, setup_all_loops - -# If a profile can't be parsed by the tools, add it to skip_active_profiles or skip_extra_profiles. -# Add only the filename (without path), for example 'usr.bin.foo'. -# These skip lists are meant as a temporary solution, and should be empty on release. -skip_active_profiles = [] - -skip_extra_profiles = [] +from common_test import AATest, setup_aa, setup_all_loops, skip_active_profiles, skip_extra_profiles class TestFoo(AATest):