2014-07-08 18:28:55 +00:00
|
|
|
# Copyright 2014, 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/>.
|
|
|
|
#
|
|
|
|
import unittest
|
|
|
|
|
2014-10-25 01:23:13 +00:00
|
|
|
from setools import SELinuxPolicy
|
|
|
|
from setools.polcapquery import PolCapQuery
|
2014-07-08 18:28:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PolCapQueryTest(unittest.TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.p = SELinuxPolicy("tests/polcapquery.conf")
|
|
|
|
|
|
|
|
def test_000_unset(self):
|
|
|
|
"""Policy capability query with no criteria"""
|
|
|
|
# query with no parameters gets all capabilities.
|
2014-08-01 14:52:17 +00:00
|
|
|
allcaps = sorted(str(c) for c in self.p.polcaps())
|
2014-07-08 18:28:55 +00:00
|
|
|
|
|
|
|
q = PolCapQuery(self.p)
|
2014-08-01 14:52:17 +00:00
|
|
|
qcaps = sorted(str(c) for c in q.results())
|
2014-07-08 18:28:55 +00:00
|
|
|
|
2014-08-01 14:52:17 +00:00
|
|
|
self.assertListEqual(allcaps, qcaps)
|
2014-07-08 18:28:55 +00:00
|
|
|
|
|
|
|
def test_001_name_exact(self):
|
|
|
|
"""Policy capability query with exact match"""
|
|
|
|
q = PolCapQuery(self.p, name="open_perms", name_regex=False)
|
|
|
|
|
2014-08-01 14:52:17 +00:00
|
|
|
caps = sorted(str(c) for c in q.results())
|
|
|
|
self.assertListEqual(["open_perms"], caps)
|
2014-07-08 18:28:55 +00:00
|
|
|
|
|
|
|
def test_002_name_regex(self):
|
|
|
|
"""Policy capability query with regex match"""
|
|
|
|
q = PolCapQuery(self.p, name="pe?er", name_regex=True)
|
|
|
|
|
2014-08-01 14:52:17 +00:00
|
|
|
caps = sorted(str(c) for c in q.results())
|
|
|
|
self.assertListEqual(["network_peer_controls", "open_perms"], caps)
|