2014-07-17 13:39:06 +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.userquery import UserQuery
|
2014-07-17 13:39:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
class UserQueryTest(unittest.TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.p = SELinuxPolicy("tests/userquery.conf")
|
|
|
|
|
|
|
|
def test_000_unset(self):
|
|
|
|
"""User query with no criteria."""
|
|
|
|
# query with no parameters gets all types.
|
2014-08-01 14:52:17 +00:00
|
|
|
allusers = sorted(str(u) for u in self.p.users())
|
2014-07-17 13:39:06 +00:00
|
|
|
|
|
|
|
q = UserQuery(self.p)
|
2014-08-01 14:52:17 +00:00
|
|
|
qusers = sorted(str(u) for u in q.results())
|
2014-07-17 13:39:06 +00:00
|
|
|
|
2014-08-01 14:52:17 +00:00
|
|
|
self.assertListEqual(allusers, qusers)
|
2014-07-17 13:39:06 +00:00
|
|
|
|
|
|
|
def test_001_name_exact(self):
|
|
|
|
"""User query with exact name match."""
|
|
|
|
q = UserQuery(self.p, name="test1_u")
|
|
|
|
|
2014-08-01 14:52:17 +00:00
|
|
|
users = sorted(str(u) for u in q.results())
|
|
|
|
self.assertListEqual(["test1_u"], users)
|
2014-07-17 13:39:06 +00:00
|
|
|
|
|
|
|
def test_002_name_regex(self):
|
|
|
|
"""User query with regex name match."""
|
|
|
|
q = UserQuery(self.p, name="test2_u(1|2)", name_regex=True)
|
|
|
|
|
2014-08-01 14:52:17 +00:00
|
|
|
users = sorted(str(u) for u in q.results())
|
|
|
|
self.assertListEqual(["test2_u1", "test2_u2"], users)
|
2014-07-17 13:39:06 +00:00
|
|
|
|
|
|
|
def test_010_role_intersect(self):
|
|
|
|
"""User query with role set intersection."""
|
|
|
|
q = UserQuery(self.p, roles=["test10a_r", "test10b_r"])
|
|
|
|
|
2014-08-01 14:52:17 +00:00
|
|
|
users = sorted(str(u) for u in q.results())
|
|
|
|
self.assertListEqual(["test10_u1", "test10_u2", "test10_u3",
|
|
|
|
"test10_u4", "test10_u5", "test10_u6"], users)
|
2014-07-17 13:39:06 +00:00
|
|
|
|
|
|
|
def test_011_role_equality(self):
|
|
|
|
"""User query with role set equality."""
|
|
|
|
q = UserQuery(
|
|
|
|
self.p, roles=["test11a_r", "test11b_r"], roles_equal=True)
|
|
|
|
|
2014-08-01 14:52:17 +00:00
|
|
|
users = sorted(str(u) for u in q.results())
|
|
|
|
self.assertListEqual(["test11_u2"], users)
|
2014-07-17 13:39:06 +00:00
|
|
|
|
|
|
|
def test_012_role_regex(self):
|
|
|
|
"""User query with role regex match."""
|
|
|
|
q = UserQuery(self.p, roles="test12(a|b)_r", roles_regex=True)
|
|
|
|
|
2014-08-01 14:52:17 +00:00
|
|
|
users = sorted(str(u) for u in q.results())
|
|
|
|
self.assertListEqual(["test12_u1", "test12_u2", "test12_u3",
|
|
|
|
"test12_u4", "test12_u5", "test12_u6"], users)
|