mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-08-29 13:28:19 +00:00
utils: wrap ValueError in AppArmorBug w/better reporting
This patch converts a ValueError raised when parsing of a permission mode fails into an AppArmorBug with better diagnostic information, and adds a test case to confirm that the exception is raised. Signed-off-by: Steve Beattie <steve@nxnw.org> Acked-by: Christian Boltz <apparmor@cboltz.de>
This commit is contained in:
parent
b1c28c7a23
commit
ad17e03b9d
@ -12,6 +12,7 @@
|
|||||||
#
|
#
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
import re
|
import re
|
||||||
|
from apparmor.common import AppArmorBug
|
||||||
|
|
||||||
def AA_OTHER(mode):
|
def AA_OTHER(mode):
|
||||||
other = set()
|
other = set()
|
||||||
@ -103,11 +104,14 @@ def split_log_mode(mode):
|
|||||||
other = ''
|
other = ''
|
||||||
|
|
||||||
if "::" in mode:
|
if "::" in mode:
|
||||||
|
try:
|
||||||
user, other = mode.split("::")
|
user, other = mode.split("::")
|
||||||
|
except ValueError as e:
|
||||||
|
raise AppArmorBug("Got ValueError '%s' when splitting %s" % (str(e), mode))
|
||||||
else:
|
else:
|
||||||
user = mode
|
user = mode
|
||||||
other = mode
|
other = mode
|
||||||
#print ('split_logmode:', user, mode)
|
|
||||||
return user, other
|
return user, other
|
||||||
|
|
||||||
def mode_contains(mode, subset):
|
def mode_contains(mode, subset):
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from apparmor.aamode import split_log_mode, sub_str_to_mode
|
from apparmor.aamode import split_log_mode, sub_str_to_mode
|
||||||
|
from apparmor.common import AppArmorBug
|
||||||
|
|
||||||
class AamodeTest_split_log_mode(unittest.TestCase):
|
class AamodeTest_split_log_mode(unittest.TestCase):
|
||||||
def test_split_log_mode_1(self):
|
def test_split_log_mode_1(self):
|
||||||
@ -26,6 +27,9 @@ class AamodeTest_split_log_mode(unittest.TestCase):
|
|||||||
self.assertEqual(split_log_mode('r::w'), ('r', 'w'))
|
self.assertEqual(split_log_mode('r::w'), ('r', 'w'))
|
||||||
def test_split_log_mode_6(self):
|
def test_split_log_mode_6(self):
|
||||||
self.assertEqual(split_log_mode('rw::rw'), ('rw', 'rw'))
|
self.assertEqual(split_log_mode('rw::rw'), ('rw', 'rw'))
|
||||||
|
def test_split_log_mode_invalid_1(self):
|
||||||
|
with self.assertRaises(AppArmorBug):
|
||||||
|
split_log_mode('r::w::r')
|
||||||
|
|
||||||
class AamodeTest_sub_str_to_mode(unittest.TestCase):
|
class AamodeTest_sub_str_to_mode(unittest.TestCase):
|
||||||
def test_sub_str_to_mode_1(self):
|
def test_sub_str_to_mode_1(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user