mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-08-31 06:16:03 +00:00
[2/3] Make ProfileStorage a class
Move ProfileStorage() from aa.py to the new profile_storage.py and make it a class. The variable name in __init__() changes (profile -> self.data), but the content stays the same. The ProfileStorage class acts like a dict(), but has some additional checks for unknown keys in place. Also add some tests to make sure unknown keys really raise an exception. Acked-by: Seth Arnold <seth.arnold@canonical.com>
This commit is contained in:
41
utils/test/test-profile-storage.py
Normal file
41
utils/test/test-profile-storage.py
Normal file
@@ -0,0 +1,41 @@
|
||||
#! /usr/bin/python3
|
||||
# ------------------------------------------------------------------
|
||||
#
|
||||
# Copyright (C) 2017 Christian Boltz <apparmor@cboltz.de>
|
||||
#
|
||||
# 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 published by the Free Software Foundation.
|
||||
#
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
import unittest
|
||||
from common_test import AATest, setup_all_loops
|
||||
|
||||
from apparmor.common import AppArmorBug
|
||||
from apparmor.profile_storage import ProfileStorage
|
||||
|
||||
class TestUnknownKey(AATest):
|
||||
def AASetup(self):
|
||||
self.storage = ProfileStorage('/test/foo', 'hat', 'TEST')
|
||||
|
||||
def test_read(self):
|
||||
with self.assertRaises(AppArmorBug):
|
||||
self.storage['foo']
|
||||
|
||||
def test_get(self):
|
||||
with self.assertRaises(AppArmorBug):
|
||||
self.storage.get('foo')
|
||||
|
||||
def test_get_with_fallback(self):
|
||||
with self.assertRaises(AppArmorBug):
|
||||
self.storage.get('foo', 'bar')
|
||||
|
||||
def test_set(self):
|
||||
with self.assertRaises(AppArmorBug):
|
||||
self.storage['foo'] = 'bar'
|
||||
|
||||
|
||||
setup_all_loops(__name__)
|
||||
if __name__ == '__main__':
|
||||
unittest.main(verbosity=2)
|
Reference in New Issue
Block a user