refactor(hardening): the SELinux part as three small questions (NetOrk/netork#2706)
driver / lint (pull_request) Successful in 17s
driver / standard (pull_request) Successful in 19s
driver / types (pull_request) Successful in 1m1s
driver / test (3.13) (pull_request) Successful in 1m12s
driver / test (3.12) (pull_request) Successful in 1m19s
driver / lowest (pull_request) Successful in 39s
driver / build (pull_request) Successful in 29s
driver / security (pull_request) Successful in 1m0s
CI / driver (pull_request) Successful in 2m31s
driver / publish (pull_request) Skipped

_selinux_configured, _selinux_running and _selinux_seen, each on its own, so
_selinux stays within napalm-standard's complexity limit. The parse is
unchanged.
This commit is contained in:
christianmanivong committed 2026-11-27 01:45:12 +01:00
1 parent e440bee9e1
commit 594cc5e486
2 files changed
+69 -10

No files matched your search

+44
View File
@@ -227,6 +227,50 @@ class TestSelinux:
assert reading["selinux"] == {"mode": None, "configured": "enforcing"}
class TestSelinuxParts:
"""The three questions the SELinux part answers, each on its own (napalm-standard's
complexity limit): the mode it boots in, the mode it runs in, and whether the
host has SELinux at all."""
def test_the_configured_mode_is_the_last_selinux_line(self):
from napalm_device_types.hardening import _selinux_configured
lines = ["SELINUXTYPE=targeted", 'SELINUX="Permissive"']
assert _selinux_configured({"selinux_config": lines}) == "permissive"
assert _selinux_configured({"selinux_config": ["SELINUX="]}) is None
assert _selinux_configured({}) is None
@pytest.mark.parametrize(
"sections, mode",
[
({"selinux": ["Enforcing"]}, "enforcing"),
({"selinux": ["something else"], "selinux_enforce": ["0"]}, "permissive"),
({"selinux_enforce": ["1"]}, "enforcing"),
({"selinux_enforce": ["2"]}, None),
({}, None),
],
)
def test_the_running_mode_getenforce_first(self, sections, mode):
from napalm_device_types.hardening import _selinux_running
assert _selinux_running(sections) == mode
@pytest.mark.parametrize(
"sections, lsm, seen",
[
({}, ["capability", "selinux"], True),
({"selinux_config": []}, None, True),
({}, ["capability", "apparmor"], False),
({}, None, False),
],
)
def test_whether_the_host_has_it(self, sections, lsm, seen):
from napalm_device_types.hardening import _selinux_seen
assert _selinux_seen(sections, lsm, None) is seen
assert _selinux_seen(sections, lsm, "enforcing") is True
class TestAppArmor:
def test_in_the_list_of_modules_without_the_parameter_file(self):
reading = parse_hardening(_wire([("lsm", "capability,apparmor")]))