File: test_categoryquery.py

package info (click to toggle)
setools 4.6.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,600 kB
  • sloc: python: 24,485; makefile: 14
file content (47 lines) | stat: -rw-r--r-- 1,815 bytes parent folder | download
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
# Copyright 2015, Tresys Technology, LLC
#
# SPDX-License-Identifier: GPL-2.0-only
#
import pytest
import setools


@pytest.mark.obj_args("tests/library/categoryquery.conf")
class TestCategoryQuery:

    def test_unset(self, compiled_policy: setools.SELinuxPolicy) -> None:
        """MLS category query with no criteria."""
        # query with no parameters gets all categories.
        allcats = sorted(str(c) for c in compiled_policy.categories())

        q = setools.CategoryQuery(compiled_policy)
        qcats = sorted(str(c) for c in q.results())
        assert allcats == qcats

    def test_name_exact(self, compiled_policy: setools.SELinuxPolicy) -> None:
        """MLS category query with exact name match."""
        q = setools.CategoryQuery(compiled_policy, name="test1")

        cats = sorted(str(c) for c in q.results())
        assert ["test1"] == cats

    def test_name_regex(self, compiled_policy: setools.SELinuxPolicy) -> None:
        """MLS category query with regex name match."""
        q = setools.CategoryQuery(compiled_policy, name="test2(a|b)", name_regex=True)

        cats = sorted(str(c) for c in q.results())
        assert ["test2a", "test2b"] == cats

    def test_alias_exact(self, compiled_policy: setools.SELinuxPolicy) -> None:
        """MLS category query with exact alias match."""
        q = setools.CategoryQuery(compiled_policy, alias="test10a")

        cats = sorted(str(t) for t in q.results())
        assert ["test10c1"] == cats

    def test_alias_regex(self, compiled_policy: setools.SELinuxPolicy) -> None:
        """MLS category query with regex alias match."""
        q = setools.CategoryQuery(compiled_policy, alias="test11(a|b)", alias_regex=True)

        cats = sorted(str(t) for t in q.results())
        assert ["test11c1", "test11c2"] == cats