File: test_role.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 (45 lines) | stat: -rw-r--r-- 1,862 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
# Copyright 2015, Tresys Technology, LLC
#
# SPDX-License-Identifier: GPL-2.0-only
#
import pytest
import setools


@pytest.mark.obj_args("tests/library/policyrep/role.conf")
class TestRole:

    def test_string(self, compiled_policy: setools.SELinuxPolicy) -> None:
        """Role basic string rendering."""
        role = compiled_policy.lookup_role("role20_r")
        assert "role20_r" == str(role), f"{role}"

    def test_statement_type(self, compiled_policy: setools.SELinuxPolicy) -> None:
        """Role statement, one type."""
        role = compiled_policy.lookup_role("role20_r")
        assert "role role20_r types system;" == role.statement(), role.statement()

    def test_statement_two_types(self, compiled_policy: setools.SELinuxPolicy) -> None:
        """Role statement, two types."""
        role = compiled_policy.lookup_role("rolename21")
        assert "role rolename21 types { type31a type31b };" == role.statement(), role.statement()

    def test_statement_decl(self, compiled_policy: setools.SELinuxPolicy) -> None:
        """Role statement, no types."""
        # This is an unlikely corner case, where a role
        # has been declared but has no types.
        role = compiled_policy.lookup_role("rolename22")
        assert "role rolename22;" == role.statement(), role.statement()

    def test_types(self, compiled_policy: setools.SELinuxPolicy) -> None:
        """Role types generator."""
        role = compiled_policy.lookup_role("rolename23")
        types = sorted(role.types())
        assert ["type31b", "type31c"] == types, types

    def test_expand(self, compiled_policy: setools.SELinuxPolicy) -> None:
        """Role expansion"""
        role = compiled_policy.lookup_role("system")
        expanded = list(role.expand())
        assert 1 == len(expanded), expanded
        assert role == expanded[0], expanded