2020-12-01 10:02:31 +00:00
|
|
|
from .conftest import (
|
|
|
|
tick_box,
|
|
|
|
cross_box,
|
|
|
|
mock_command,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-11-18 01:03:37 +00:00
|
|
|
def mock_selinux_config(state, host):
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2020-12-01 10:02:31 +00:00
|
|
|
Creates a mock SELinux config file with expected content
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2020-12-01 10:02:31 +00:00
|
|
|
# validate state string
|
2022-09-19 12:44:10 +00:00
|
|
|
valid_states = ["enforcing", "permissive", "disabled"]
|
2020-12-01 10:02:31 +00:00
|
|
|
assert state in valid_states
|
|
|
|
# getenforce returns the running state of SELinux
|
2022-09-19 12:44:10 +00:00
|
|
|
mock_command("getenforce", {"*": (state.capitalize(), "0")}, host)
|
2020-12-01 10:02:31 +00:00
|
|
|
# create mock configuration with desired content
|
2022-09-19 12:44:10 +00:00
|
|
|
host.run(
|
|
|
|
"""
|
2020-12-01 10:02:31 +00:00
|
|
|
mkdir /etc/selinux
|
|
|
|
echo "SELINUX={state}" > /etc/selinux/config
|
2022-09-19 12:44:10 +00:00
|
|
|
""".format(
|
|
|
|
state=state.lower()
|
|
|
|
)
|
|
|
|
)
|
2020-12-01 10:02:31 +00:00
|
|
|
|
|
|
|
|
2021-11-18 01:03:37 +00:00
|
|
|
def test_selinux_enforcing_exit(host):
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2020-12-01 10:02:31 +00:00
|
|
|
confirms installer prompts to exit when SELinux is Enforcing by default
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2021-11-18 01:03:37 +00:00
|
|
|
mock_selinux_config("enforcing", host)
|
2022-09-19 12:44:10 +00:00
|
|
|
check_selinux = host.run(
|
|
|
|
"""
|
2020-12-01 10:02:31 +00:00
|
|
|
source /opt/pihole/basic-install.sh
|
|
|
|
checkSelinux
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
expected_stdout = cross_box + " Current SELinux: enforcing"
|
2020-12-01 10:02:31 +00:00
|
|
|
assert expected_stdout in check_selinux.stdout
|
2022-09-19 12:44:10 +00:00
|
|
|
expected_stdout = "SELinux Enforcing detected, exiting installer"
|
2020-12-01 10:02:31 +00:00
|
|
|
assert expected_stdout in check_selinux.stdout
|
|
|
|
assert check_selinux.rc == 1
|
|
|
|
|
|
|
|
|
2021-11-18 01:03:37 +00:00
|
|
|
def test_selinux_permissive(host):
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2020-12-01 10:02:31 +00:00
|
|
|
confirms installer continues when SELinux is Permissive
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2021-11-18 01:03:37 +00:00
|
|
|
mock_selinux_config("permissive", host)
|
2022-09-19 12:44:10 +00:00
|
|
|
check_selinux = host.run(
|
|
|
|
"""
|
2020-12-01 10:02:31 +00:00
|
|
|
source /opt/pihole/basic-install.sh
|
|
|
|
checkSelinux
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
expected_stdout = tick_box + " Current SELinux: permissive"
|
2020-12-01 10:02:31 +00:00
|
|
|
assert expected_stdout in check_selinux.stdout
|
|
|
|
assert check_selinux.rc == 0
|
|
|
|
|
2020-12-01 10:13:36 +00:00
|
|
|
|
2021-11-18 01:03:37 +00:00
|
|
|
def test_selinux_disabled(host):
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2020-12-01 10:02:31 +00:00
|
|
|
confirms installer continues when SELinux is Disabled
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2021-11-18 01:03:37 +00:00
|
|
|
mock_selinux_config("disabled", host)
|
2022-09-19 12:44:10 +00:00
|
|
|
check_selinux = host.run(
|
|
|
|
"""
|
2020-12-01 10:02:31 +00:00
|
|
|
source /opt/pihole/basic-install.sh
|
|
|
|
checkSelinux
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
expected_stdout = tick_box + " Current SELinux: disabled"
|
2020-12-01 10:02:31 +00:00
|
|
|
assert expected_stdout in check_selinux.stdout
|
|
|
|
assert check_selinux.rc == 0
|