Hello, aa_test.py doesn't run in 'make check' because its filename doesn't match the 'test-*.py' pattern, so this move means the tests now actually get run.
While on it, migrate test-aamode.py to use the AATest base class, and migrate the str_to_mode() tests to a tests[] array. After this move, aa_test.py doesn't do anything anymore, so delete it. [ 04-move-str_to_mode-tests-to-test-aamode.diff ] === modified file ./utils/test/aa_test.py --- utils/test/aa_test.py 2016-10-09 20:05:47.584426947 +0200 +++ utils/test/aa_test.py 2016-10-09 20:10:14.970841649 +0200 @@ -1,47 +1 @@ -# ---------------------------------------------------------------------- -# Copyright (C) 2013 Kshitij Gupta <[email protected]> -# -# 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 as published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# ---------------------------------------------------------------------- -import unittest -import apparmor.aamode - -class Test(unittest.TestCase): - - def setUp(self): - self.MODE_TEST = {'x': apparmor.aamode.AA_MAY_EXEC, - 'w': apparmor.aamode.AA_MAY_WRITE, - 'r': apparmor.aamode.AA_MAY_READ, - 'a': apparmor.aamode.AA_MAY_APPEND, - 'l': apparmor.aamode.AA_MAY_LINK, - 'k': apparmor.aamode.AA_MAY_LOCK, - 'm': apparmor.aamode.AA_EXEC_MMAP, - 'i': apparmor.aamode.AA_EXEC_INHERIT, - 'u': apparmor.aamode.AA_EXEC_UNCONFINED | apparmor.aamode.AA_EXEC_UNSAFE, - 'U': apparmor.aamode.AA_EXEC_UNCONFINED, - 'p': apparmor.aamode.AA_EXEC_PROFILE | apparmor.aamode.AA_EXEC_UNSAFE, - 'P': apparmor.aamode.AA_EXEC_PROFILE, - 'c': apparmor.aamode.AA_EXEC_CHILD | apparmor.aamode.AA_EXEC_UNSAFE, - 'C': apparmor.aamode.AA_EXEC_CHILD, - } - - def test_string_to_modes(self): - - for string in self.MODE_TEST.keys(): - mode = self.MODE_TEST[string] | apparmor.aamode.AA_OTHER(self.MODE_TEST[string]) - #print("mode: %s string: %s str_to_mode(string): %s" % (mode, string, apparmor.aamode.str_to_mode(string))) - self.assertEqual(mode, apparmor.aamode.str_to_mode(string), 'mode is %s and string is %s'%(mode, string)) - - -if __name__ == "__main__": - #import sys;sys.argv = ['', 'Test.testName'] - unittest.main(verbosity=2) === modified file ./utils/test/test-aamode.py --- utils/test/test-aamode.py 2016-10-01 21:00:58.949770000 +0200 +++ utils/test/test-aamode.py 2016-10-09 20:25:13.990512734 +0200 @@ -1,7 +1,7 @@ #! /usr/bin/python3 # ------------------------------------------------------------------ # -# Copyright (C) 2014 Christian Boltz +# Copyright (C) 2014-2016 Christian Boltz # # This program is free software; you can redistribute it and/or # modify it under the terms of version 2 of the GNU General Public @@ -10,11 +10,14 @@ # ------------------------------------------------------------------ import unittest +from common_test import AATest, setup_all_loops -from apparmor.aamode import split_log_mode, sub_str_to_mode, validate_log_mode +import apparmor.aamode + +from apparmor.aamode import split_log_mode, str_to_mode, sub_str_to_mode, validate_log_mode from apparmor.common import AppArmorBug -class AamodeTest_split_log_mode(unittest.TestCase): +class AamodeTest_split_log_mode(AATest): def test_split_log_mode_1(self): self.assertEqual(split_log_mode(''), ('', '')) def test_split_log_mode_2(self): @@ -31,7 +34,30 @@ with self.assertRaises(AppArmorBug): split_log_mode('r::w::r') +class AamodeTest_str_to_mode(AATest): + tests = [ + ('x', apparmor.aamode.AA_MAY_EXEC), + ('w', apparmor.aamode.AA_MAY_WRITE), + ('r', apparmor.aamode.AA_MAY_READ), + ('a', apparmor.aamode.AA_MAY_APPEND), + ('l', apparmor.aamode.AA_MAY_LINK), + ('k', apparmor.aamode.AA_MAY_LOCK), + ('m', apparmor.aamode.AA_EXEC_MMAP), + ('i', apparmor.aamode.AA_EXEC_INHERIT), + ('u', apparmor.aamode.AA_EXEC_UNCONFINED | apparmor.aamode.AA_EXEC_UNSAFE), + ('U', apparmor.aamode.AA_EXEC_UNCONFINED), + ('p', apparmor.aamode.AA_EXEC_PROFILE | apparmor.aamode.AA_EXEC_UNSAFE), + ('P', apparmor.aamode.AA_EXEC_PROFILE), + ('c', apparmor.aamode.AA_EXEC_CHILD | apparmor.aamode.AA_EXEC_UNSAFE), + ('C', apparmor.aamode.AA_EXEC_CHILD), + ] + + def _run_test(self, params, expected): + mode = expected | apparmor.aamode.AA_OTHER(expected) + #print("mode: %s params: %s str_to_mode(params): %s" % (mode, params, apparmor.aamode.str_to_mode(params))) + self.assertEqual(mode, str_to_mode(params), 'mode is %s and expected string is %s'%(mode, expected)) + -class AamodeTest_sub_str_to_mode(unittest.TestCase): +class AamodeTest_sub_str_to_mode(AATest): def test_sub_str_to_mode_1(self): self.assertEqual(sub_str_to_mode(''), set()) def test_sub_str_to_mode_2(self): @@ -62,7 +88,7 @@ -class AamodeTest_validate_log_mode(unittest.TestCase): +class AamodeTest_validate_log_mode(AATest): def test_validate_log_mode_1(self): self.assertTrue(validate_log_mode('a')) def test_validate_log_mode_2(self): @@ -81,5 +107,7 @@ def test_validate_log_mode_invalid_4(self): self.assertFalse(validate_log_mode('')) + +setup_all_loops(__name__) if __name__ == '__main__': unittest.main(verbosity=2) Regards, Christian Boltz -- > Heute habe ich die CPU gepflegt und wollte danach > den PC starten / booten. Es gab kein Bild. Was heißt das denn genau? Maniküre, Pediküre, UV-Bad, Cremen, ... ;) [> Frank und T. Ermlich in opensuse-de]
signature.asc
Description: This is a digitally signed message part.
-- AppArmor mailing list [email protected] Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/apparmor
