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:
@@ -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):
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user