1# Authors: Karl MacMillan <kmacmillan@mentalrootkit.com>
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
20import unittest
21import sepolgen.objectmodel
22
23class 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
29        pm = info.get("filesystem", "mount")
30        self.assertEquals(pm.perm, "mount")
31        self.assertEquals(pm.dir, sepolgen.objectmodel.FLOW_WRITE)
32        self.assertEquals(pm.weight, 1)
33
34        self.assertRaises(KeyError, info.get, "filesystem", "foo")
35
36        pm = info.getdefault("filesystem", "foo")
37        self.assertEquals(pm.perm, "foo")
38        self.assertEquals(pm.dir, sepolgen.objectmodel.FLOW_BOTH)
39        self.assertEquals(pm.weight, 5)
40
41        pm = info.getdefault("foo", "bar")
42        self.assertEquals(pm.perm, "bar")
43        self.assertEquals(pm.dir, sepolgen.objectmodel.FLOW_BOTH)
44        self.assertEquals(pm.weight, 5)
45