2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-31 06:16:03 +00:00

utils: fix Severity(None) condition

This patch fixes Severity.__init__() when it is not given an argument to
raise an AppArmor exception rather than returning a Severity object in
an incompletely initialized state. It also adjusts a test case covering
this situation.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
This commit is contained in:
Steve Beattie
2014-11-06 12:37:02 -08:00
parent e26f139025
commit 3bf5e5b1d9
2 changed files with 3 additions and 3 deletions

View File

@@ -29,7 +29,7 @@ class Severity(object):
# For variable expansions for the profile
self.severity['VARIABLES'] = dict()
if not dbname:
return None
raise AppArmorException("No severity db file given")
with open_file_read(dbname) as database: # open(dbname, 'r')
for lineno, line in enumerate(database, start=1):

View File

@@ -206,8 +206,8 @@ class SeverityDBTest(unittest.TestCase):
self.assertRaises(IOError, severity.Severity, 'severity.db.does.not.exist')
def test_no_arg_to_severity(self):
sev_db = severity.Severity()
self.assertIsNone(sev_db, 'expected None, got %s' % (sev_db))
with self.assertRaises(AppArmorException):
severity.Severity()
if __name__ == "__main__":
unittest.main(verbosity=2)