2020-11-01 01:06:36 +01:00
|
|
|
#! /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 unittest
|
2022-08-07 20:32:07 -04:00
|
|
|
|
2020-11-01 01:06:36 +01:00
|
|
|
import apparmor.aa as aa
|
2022-08-07 20:32:07 -04:00
|
|
|
from common_test import AATest, setup_aa, setup_all_loops
|
2020-11-01 01:06:36 +01:00
|
|
|
|
2021-03-07 13:55:42 +01:00
|
|
|
# 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.
|
2022-08-07 12:26:24 -04:00
|
|
|
skip_active_profiles = []
|
|
|
|
|
|
|
|
skip_extra_profiles = []
|
2021-03-07 13:55:42 +01:00
|
|
|
|
|
|
|
|
2020-11-01 01:06:36 +01:00
|
|
|
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):
|
2021-03-07 13:55:42 +01:00
|
|
|
aa.read_profiles(skip_profiles=skip_active_profiles)
|
2020-11-01 01:06:36 +01:00
|
|
|
|
|
|
|
self.assertGreaterEqual(len(aa.active_profiles.profile_names), 42)
|
|
|
|
|
|
|
|
def test_extra_profiles(self):
|
2021-03-07 13:55:42 +01:00
|
|
|
aa.read_inactive_profiles(skip_profiles=skip_extra_profiles)
|
2020-11-01 01:06:36 +01:00
|
|
|
|
|
|
|
self.assertGreaterEqual(len(aa.extra_profiles.profile_names), 100)
|
|
|
|
|
2022-08-07 12:26:24 -04:00
|
|
|
|
2020-11-01 01:06:36 +01:00
|
|
|
setup_aa(aa)
|
|
|
|
setup_all_loops(__name__)
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main(verbosity=1)
|