[go: up one dir, main page]

File: polcap.py

package info (click to toggle)
setools 4.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,900 kB
  • sloc: python: 20,968; makefile: 14
file content (64 lines) | stat: -rw-r--r-- 2,143 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Copyright 2015, Tresys Technology, LLC
#
# This file is part of SETools.
#
# SETools is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# SETools is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with SETools.  If not, see <http://www.gnu.org/licenses/>.
#
# Until this is fixed for cython:
# pylint: disable=undefined-variable
import unittest
from unittest.mock import Mock


@unittest.skip("Needs to be reworked for cython")
class PolCapTest(unittest.TestCase):

    @staticmethod
    def mock_cap(name):
        cap = Mock(qpol.qpol_polcap_t)
        cap.name.return_value = name
        return cap

    def setUp(self):
        self.p = Mock(qpol.qpol_policy_t)

    def test_001_factory(self):
        """PolCap: factory on qpol object."""
        q = self.mock_cap("test1")
        cap = polcap_factory(self.p, q)
        self.assertEqual("test1", cap.qpol_symbol.name(self.p))

    def test_002_factory_object(self):
        """PolCap: factory on PolCap object."""
        q = self.mock_cap("test2")
        cap1 = polcap_factory(self.p, q)
        cap2 = polcap_factory(self.p, cap1)
        self.assertIs(cap2, cap1)

    def test_003_factory_lookup(self):
        """PolCap: factory lookup."""
        with self.assertRaises(TypeError):
            polcap_factory(self.p, "open_perms")

    def test_010_string(self):
        """PolCap: basic string rendering."""
        q = self.mock_cap("test10")
        cap = polcap_factory(self.p, q)
        self.assertEqual("test10", str(cap))

    def test_020_statement(self):
        """PolCap: statement."""
        q = self.mock_cap("test20")
        cap = polcap_factory(self.p, q)
        self.assertEqual("policycap test20;", cap.statement())