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
|
# Copyright 2014, Tresys Technology, LLC
#
# SPDX-License-Identifier: GPL-2.0-only
#
import pytest
import setools
@pytest.mark.obj_args("tests/library/commonquery.conf")
class TestCommonQuery:
def test_unset(self, compiled_policy: setools.SELinuxPolicy) -> None:
"""Common query with no criteria."""
# query with no parameters gets all types.
commons = sorted(compiled_policy.commons())
q = setools.CommonQuery(compiled_policy)
q_commons = sorted(q.results())
assert commons == q_commons
def test_name_exact(self, compiled_policy: setools.SELinuxPolicy) -> None:
"""Common query with exact name match."""
q = setools.CommonQuery(compiled_policy, name="test1")
commons = sorted(str(c) for c in q.results())
assert ["test1"] == commons
def test_name_regex(self, compiled_policy: setools.SELinuxPolicy) -> None:
"""Common query with regex name match."""
q = setools.CommonQuery(compiled_policy, name="test2(a|b)", name_regex=True)
commons = sorted(str(c) for c in q.results())
assert ["test2a", "test2b"] == commons
def test_perm_indirect_intersect(self, compiled_policy: setools.SELinuxPolicy) -> None:
"""Common query with intersect permission name patch."""
q = setools.CommonQuery(compiled_policy, perms=set(["null"]), perms_equal=False)
commons = sorted(str(c) for c in q.results())
assert ["test10a", "test10b"] == commons
def test_perm_indirect_equal(self, compiled_policy: setools.SELinuxPolicy) -> None:
"""Common query with equal permission name patch."""
q = setools.CommonQuery(compiled_policy, perms=set(["read", "write"]), perms_equal=True)
commons = sorted(str(c) for c in q.results())
assert ["test11a"] == commons
def test_perm_indirect_regex(self, compiled_policy: setools.SELinuxPolicy) -> None:
"""Common query with regex permission name patch."""
q = setools.CommonQuery(compiled_policy, perms="sig.+", perms_regex=True)
commons = sorted(str(c) for c in q.results())
assert ["test12a", "test12b"] == commons
|