apparmor/utils/test/test-profile-storage.py
Christian Boltz c2a420d32b
let var_transform() sort variable content
This is needed to get a reproducible output.

Also adjust the tests in test-profile-storage.py and add some example
variable to cleanprof.in and cleanprof.out
2018-05-31 22:00:36 +02:00

52 lines
1.6 KiB
Python

#! /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, var_transform
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'
class AaTest_var_transform(AATest):
tests = [
(['foo', ''], '"" foo' ),
(['foo', 'bar'], 'bar foo' ),
([''], '""' ),
(['bar baz', 'foo'], '"bar baz" foo' ),
]
def _run_test(self, params, expected):
self.assertEqual(var_transform(params), expected)
setup_all_loops(__name__)
if __name__ == '__main__':
unittest.main(verbosity=1)