From 58f5c2b7e865a324e8923bb01c874ac5c1ba4dbc Mon Sep 17 00:00:00 2001 From: Christian Boltz Date: Sun, 15 Jun 2025 17:54:50 +0200 Subject: [PATCH] ChangeProfileTestParseInvalid: allow tests that match the regex (even if the existing tests all don't match it) --- utils/test/test-change_profile.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/utils/test/test-change_profile.py b/utils/test/test-change_profile.py index 717609545..7e4386512 100644 --- a/utils/test/test-change_profile.py +++ b/utils/test/test-change_profile.py @@ -1,6 +1,6 @@ #!/usr/bin/python3 # ---------------------------------------------------------------------- -# Copyright (C) 2015 Christian Boltz +# Copyright (C) 2015-2025 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 @@ -84,15 +84,17 @@ class ChangeProfileTestParse(ChangeProfileTest): class ChangeProfileTestParseInvalid(ChangeProfileTest): tests = ( - ('change_profile -> ,', AppArmorException), - ('change_profile foo -> ,', AppArmorException), - ('change_profile notsafe,', AppArmorException), - ('change_profile safety -> /bar,', AppArmorException), + # rule exception, matches regex? + ('change_profile -> ,', (AppArmorException, False)), + ('change_profile foo -> ,', (AppArmorException, False)), + ('change_profile notsafe,', (AppArmorException, False)), + ('change_profile safety -> /bar,', (AppArmorException, False)), ) def _run_test(self, rawrule, expected): - self.assertFalse(ChangeProfileRule.match(rawrule)) - with self.assertRaises(expected): + exp_exception, matches_regex = expected + self.assertEqual(matches_regex, ChangeProfileRule.match(rawrule)) # does the invalid rules still match the main regex? + with self.assertRaises(exp_exception): ChangeProfileRule.create_instance(rawrule)