mirror of
https://github.com/SELinuxProject/setools
synced 2025-02-23 23:56:59 +00:00
66 lines
2.3 KiB
Python
66 lines
2.3 KiB
Python
|
# 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/>.
|
||
|
#
|
||
|
import unittest
|
||
|
|
||
|
from setools import SELinuxPolicy
|
||
|
from setools.mlscategoryquery import MLSCategoryQuery
|
||
|
|
||
|
|
||
|
class MLSCategoryQueryTest(unittest.TestCase):
|
||
|
|
||
|
def setUp(self):
|
||
|
self.p = SELinuxPolicy("tests/mlscategoryquery.conf")
|
||
|
|
||
|
def test_000_unset(self):
|
||
|
"""MLS category query with no criteria."""
|
||
|
# query with no parameters gets all categories.
|
||
|
allcats = sorted(str(c) for c in self.p.mlscategories())
|
||
|
|
||
|
q = MLSCategoryQuery(self.p)
|
||
|
qcats = sorted(str(c) for c in q.results())
|
||
|
|
||
|
self.assertListEqual(allcats, qcats)
|
||
|
|
||
|
def test_001_name_exact(self):
|
||
|
"""MLS category query with exact name match."""
|
||
|
q = MLSCategoryQuery(self.p, name="test1")
|
||
|
|
||
|
cats = sorted(str(c) for c in q.results())
|
||
|
self.assertListEqual(["test1"], cats)
|
||
|
|
||
|
def test_002_name_regex(self):
|
||
|
"""MLS category query with regex name match."""
|
||
|
q = MLSCategoryQuery(self.p, name="test2(a|b)", name_regex=True)
|
||
|
|
||
|
cats = sorted(str(c) for c in q.results())
|
||
|
self.assertListEqual(["test2a", "test2b"], cats)
|
||
|
|
||
|
def test_010_alias_exact(self):
|
||
|
"""MLS category query with exact alias match."""
|
||
|
q = MLSCategoryQuery(self.p, alias="test10a")
|
||
|
|
||
|
cats = sorted(str(t) for t in q.results())
|
||
|
self.assertListEqual(["test10c1"], cats)
|
||
|
|
||
|
def test_011_alias_regex(self):
|
||
|
"""MLS category query with regex alias match."""
|
||
|
q = MLSCategoryQuery(self.p, alias="test11(a|b)", alias_regex=True)
|
||
|
|
||
|
cats = sorted(str(t) for t in q.results())
|
||
|
self.assertListEqual(["test11c1", "test11c2"], cats)
|