mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-08-22 01:57:43 +00:00
If USE_SYSTEM=1 then we can't assume all the various profiles have been installed and therefore that the counts of the profiles will be as expected. In that case, simply testing that parsing the profiles occurs without errors is sufficient. Signed-off-by: Alex Murray <alex.murray@canonical.com> MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/924 Merged-by: Alex Murray <alex.murray@canonical.com>
51 lines
1.9 KiB
Python
51 lines
1.9 KiB
Python
#! /usr/bin/python3
|
|
# ------------------------------------------------------------------
|
|
#
|
|
# Copyright (C) 2020 Christian Boltz <apparmor@cboltz.de>
|
|
#
|
|
# 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 os
|
|
import unittest
|
|
|
|
import apparmor.aa as aa
|
|
from common_test import AATest, setup_aa, setup_all_loops
|
|
|
|
|
|
class TestFoo(AATest):
|
|
# Make sure the python code can parse all profiles shipped with AppArmor.
|
|
# If this fails, read_profiles() / read_inactive_profiles() will raise an exception.
|
|
#
|
|
# Checking for the number of read profiles is mostly done to ensure *something* is read
|
|
# (to make sure an empty or non-existing directory won't make this test useless).
|
|
|
|
def test_active_profiles(self):
|
|
aa.read_profiles()
|
|
|
|
# when using system apparmor then we haven't necessarily installed all
|
|
# the profiles so checking against a specific number may fail - instead
|
|
# it is sufficient that profiles were read without an exception being
|
|
# thrown above
|
|
if os.getenv("USE_SYSTEM", "0") != "1":
|
|
self.assertGreaterEqual(len(aa.active_profiles.profile_names), 42)
|
|
|
|
def test_extra_profiles(self):
|
|
aa.read_inactive_profiles()
|
|
|
|
# when using system apparmor then we haven't necessarily installed all
|
|
# the profiles so checking against a specific number may fail - instead
|
|
# it is sufficient that profiles were read without an exception being
|
|
# thrown above
|
|
if os.getenv("USE_SYSTEM", "0") != "1":
|
|
self.assertGreaterEqual(len(aa.extra_profiles.profile_names), 100)
|
|
|
|
|
|
setup_aa(aa)
|
|
setup_all_loops(__name__)
|
|
if __name__ == '__main__':
|
|
unittest.main(verbosity=1)
|