Debian Codegraph @

python/sepolgen/tests/test_objectmodel.py

raw symbols SCIP
1 # Authors: Karl MacMillan <[email protected]>
2 #
3 # Copyright (C) 2006 Red Hat
4 # see file 'COPYING' for use and warranty information
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation; version 2 only
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 #
19
20 import unittest
21 import sepolgen.objectmodel
22
23 class TestInfoFlow(unittest.TestCase):
24 def test_from_file(self):
25 info = sepolgen.objectmodel.PermMappings()
26 fd = open("perm_map")
27 info.from_file(fd)
28 fd.close()
29
30 pm = info.get("filesystem", "mount")
31 self.assertEqual(pm.perm, "mount")
32 self.assertEqual(pm.dir, sepolgen.objectmodel.FLOW_WRITE)
33 self.assertEqual(pm.weight, 1)
34
35 self.assertRaises(KeyError, info.get, "filesystem", "foo")
36
37 pm = info.getdefault("filesystem", "foo")
38 self.assertEqual(pm.perm, "foo")
39 self.assertEqual(pm.dir, sepolgen.objectmodel.FLOW_BOTH)
40 self.assertEqual(pm.weight, 5)
41
42 pm = info.getdefault("foo", "bar")
43 self.assertEqual(pm.perm, "bar")
44 self.assertEqual(pm.dir, sepolgen.objectmodel.FLOW_BOTH)
45 self.assertEqual(pm.weight, 5)