2021-11-11 16:44:57 +00:00
|
|
|
import pytest
|
2016-10-11 04:14:39 +00:00
|
|
|
from textwrap import dedent
|
2018-07-12 05:03:10 +00:00
|
|
|
import re
|
2020-03-03 07:30:44 +00:00
|
|
|
from .conftest import (
|
2018-07-06 00:10:43 +00:00
|
|
|
tick_box,
|
|
|
|
info_box,
|
|
|
|
cross_box,
|
|
|
|
mock_command,
|
2021-11-11 16:44:57 +00:00
|
|
|
mock_command_run,
|
2018-07-06 00:10:43 +00:00
|
|
|
mock_command_2,
|
2021-11-11 16:44:57 +00:00
|
|
|
mock_command_passthrough,
|
2022-09-19 12:44:10 +00:00
|
|
|
run_script,
|
2018-07-06 00:10:43 +00:00
|
|
|
)
|
2017-06-21 11:49:05 +00:00
|
|
|
|
2018-07-02 20:54:19 +00:00
|
|
|
|
2021-11-18 01:03:37 +00:00
|
|
|
def test_supported_package_manager(host):
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2021-10-04 10:40:53 +00:00
|
|
|
confirm installer exits when no supported package manager found
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2021-10-04 10:40:53 +00:00
|
|
|
# break supported package managers
|
2022-09-19 12:44:10 +00:00
|
|
|
host.run("rm -rf /usr/bin/apt-get")
|
|
|
|
host.run("rm -rf /usr/bin/rpm")
|
|
|
|
package_manager_detect = host.run(
|
|
|
|
"""
|
2018-07-06 16:07:43 +00:00
|
|
|
source /opt/pihole/basic-install.sh
|
2021-08-03 20:48:26 +00:00
|
|
|
package_manager_detect
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
expected_stdout = cross_box + " No supported package manager found"
|
2021-08-03 20:48:26 +00:00
|
|
|
assert expected_stdout in package_manager_detect.stdout
|
|
|
|
# assert package_manager_detect.rc == 1
|
2018-07-06 16:07:43 +00:00
|
|
|
|
|
|
|
|
2021-11-18 01:03:37 +00:00
|
|
|
def test_selinux_not_detected(host):
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2019-10-14 18:26:39 +00:00
|
|
|
confirms installer continues when SELinux configuration file does not exist
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
check_selinux = host.run(
|
|
|
|
"""
|
2019-10-14 18:26:39 +00:00
|
|
|
rm -f /etc/selinux/config
|
2018-06-26 06:09:30 +00:00
|
|
|
source /opt/pihole/basic-install.sh
|
|
|
|
checkSelinux
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
expected_stdout = info_box + " SELinux not detected"
|
2018-07-03 06:05:24 +00:00
|
|
|
assert expected_stdout in check_selinux.stdout
|
2018-06-26 06:09:30 +00:00
|
|
|
assert check_selinux.rc == 0
|
|
|
|
|
2018-07-02 20:54:19 +00:00
|
|
|
|
2021-11-18 01:03:37 +00:00
|
|
|
def get_directories_recursive(host, directory):
|
2021-11-11 16:44:57 +00:00
|
|
|
if directory is None:
|
|
|
|
return directory
|
2023-01-04 11:31:49 +00:00
|
|
|
# returns all non-hidden subdirs of 'directory'
|
|
|
|
dirs_raw = host.run("find {} -type d -not -path '*/.*'".format(directory))
|
|
|
|
dirs = list(filter(bool, dirs_raw.stdout.splitlines()))
|
2021-11-11 16:44:57 +00:00
|
|
|
return dirs
|
|
|
|
|
|
|
|
|
2021-11-18 01:03:37 +00:00
|
|
|
def test_installPihole_fresh_install_readableFiles(host):
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2022-07-02 13:00:17 +00:00
|
|
|
confirms all necessary files are readable by pihole user
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2022-07-02 19:51:03 +00:00
|
|
|
# dialog returns Cancel for user prompt
|
2022-09-19 12:44:10 +00:00
|
|
|
mock_command("dialog", {"*": ("", "0")}, host)
|
2021-11-11 16:44:57 +00:00
|
|
|
# mock git pull
|
2022-09-19 12:44:10 +00:00
|
|
|
mock_command_passthrough("git", {"pull": ("", "0")}, host)
|
2021-11-11 16:44:57 +00:00
|
|
|
# mock systemctl to not start lighttpd and FTL
|
|
|
|
mock_command_2(
|
2022-09-19 12:44:10 +00:00
|
|
|
"systemctl",
|
2021-11-11 16:44:57 +00:00
|
|
|
{
|
2022-09-19 12:44:10 +00:00
|
|
|
"enable pihole-FTL": ("", "0"),
|
|
|
|
"restart pihole-FTL": ("", "0"),
|
|
|
|
"start pihole-FTL": ("", "0"),
|
|
|
|
"*": ('echo "systemctl call with $@"', "0"),
|
2021-11-11 16:44:57 +00:00
|
|
|
},
|
2022-09-19 12:44:10 +00:00
|
|
|
host,
|
2021-11-11 16:44:57 +00:00
|
|
|
)
|
|
|
|
# try to install man
|
2022-09-19 12:44:10 +00:00
|
|
|
host.run("command -v apt-get > /dev/null && apt-get install -qq man")
|
|
|
|
host.run("command -v dnf > /dev/null && dnf install -y man")
|
|
|
|
host.run("command -v yum > /dev/null && yum install -y man")
|
|
|
|
install = host.run(
|
|
|
|
"""
|
2021-11-11 16:44:57 +00:00
|
|
|
export TERM=xterm
|
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
|
|
umask 0027
|
|
|
|
runUnattended=true
|
|
|
|
useUpdateVars=true
|
|
|
|
source /opt/pihole/basic-install.sh > /dev/null
|
|
|
|
runUnattended=true
|
|
|
|
useUpdateVars=true
|
|
|
|
main
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
)
|
2021-11-11 16:44:57 +00:00
|
|
|
assert 0 == install.rc
|
|
|
|
maninstalled = True
|
2022-09-19 12:44:10 +00:00
|
|
|
if (info_box + " man not installed") in install.stdout:
|
2021-11-11 16:44:57 +00:00
|
|
|
maninstalled = False
|
2022-11-24 19:39:02 +00:00
|
|
|
if (info_box + " man pages not installed") in install.stdout:
|
|
|
|
maninstalled = False
|
2022-09-19 12:44:10 +00:00
|
|
|
piholeuser = "pihole"
|
2021-11-11 16:44:57 +00:00
|
|
|
exit_status_success = 0
|
|
|
|
test_cmd = 'su --shell /bin/bash --command "test -{0} {1}" -p {2}'
|
|
|
|
# check files in /etc/pihole for read, write and execute permission
|
2022-09-19 12:44:10 +00:00
|
|
|
check_etc = test_cmd.format("r", "/etc/pihole", piholeuser)
|
2021-11-18 01:03:37 +00:00
|
|
|
actual_rc = host.run(check_etc).rc
|
2021-11-11 16:44:57 +00:00
|
|
|
assert exit_status_success == actual_rc
|
2022-09-19 12:44:10 +00:00
|
|
|
check_etc = test_cmd.format("x", "/etc/pihole", piholeuser)
|
2021-11-18 01:03:37 +00:00
|
|
|
actual_rc = host.run(check_etc).rc
|
2021-11-11 16:44:57 +00:00
|
|
|
assert exit_status_success == actual_rc
|
|
|
|
# readable and writable dhcp.leases
|
2022-09-19 12:44:10 +00:00
|
|
|
check_leases = test_cmd.format("r", "/etc/pihole/dhcp.leases", piholeuser)
|
2021-11-18 01:03:37 +00:00
|
|
|
actual_rc = host.run(check_leases).rc
|
2021-11-11 16:44:57 +00:00
|
|
|
assert exit_status_success == actual_rc
|
2022-09-19 12:44:10 +00:00
|
|
|
check_leases = test_cmd.format("w", "/etc/pihole/dhcp.leases", piholeuser)
|
2021-11-18 01:03:37 +00:00
|
|
|
actual_rc = host.run(check_leases).rc
|
2021-11-11 16:44:57 +00:00
|
|
|
# readable dns-servers.conf
|
|
|
|
assert exit_status_success == actual_rc
|
2022-09-19 12:44:10 +00:00
|
|
|
check_servers = test_cmd.format("r", "/etc/pihole/dns-servers.conf", piholeuser)
|
2021-11-18 01:03:37 +00:00
|
|
|
actual_rc = host.run(check_servers).rc
|
2021-11-11 16:44:57 +00:00
|
|
|
assert exit_status_success == actual_rc
|
|
|
|
# readable install.log
|
2022-09-19 12:44:10 +00:00
|
|
|
check_install = test_cmd.format("r", "/etc/pihole/install.log", piholeuser)
|
2021-11-18 01:03:37 +00:00
|
|
|
actual_rc = host.run(check_install).rc
|
2021-11-11 16:44:57 +00:00
|
|
|
assert exit_status_success == actual_rc
|
2022-08-22 17:53:46 +00:00
|
|
|
# readable versions
|
2022-09-19 12:44:10 +00:00
|
|
|
check_localversion = test_cmd.format("r", "/etc/pihole/versions", piholeuser)
|
2021-11-18 01:03:37 +00:00
|
|
|
actual_rc = host.run(check_localversion).rc
|
2021-11-11 16:44:57 +00:00
|
|
|
assert exit_status_success == actual_rc
|
|
|
|
# readable logrotate
|
2022-09-19 12:44:10 +00:00
|
|
|
check_logrotate = test_cmd.format("r", "/etc/pihole/logrotate", piholeuser)
|
2021-11-18 01:03:37 +00:00
|
|
|
actual_rc = host.run(check_logrotate).rc
|
2021-11-11 16:44:57 +00:00
|
|
|
assert exit_status_success == actual_rc
|
|
|
|
# readable macvendor.db
|
2022-09-19 12:44:10 +00:00
|
|
|
check_macvendor = test_cmd.format("r", "/etc/pihole/macvendor.db", piholeuser)
|
2021-11-18 01:03:37 +00:00
|
|
|
actual_rc = host.run(check_macvendor).rc
|
2021-11-11 16:44:57 +00:00
|
|
|
assert exit_status_success == actual_rc
|
|
|
|
# readable and writeable pihole-FTL.conf
|
2022-09-19 12:44:10 +00:00
|
|
|
check_FTLconf = test_cmd.format("r", "/etc/pihole/pihole-FTL.conf", piholeuser)
|
2021-11-18 01:03:37 +00:00
|
|
|
actual_rc = host.run(check_FTLconf).rc
|
2021-11-11 16:44:57 +00:00
|
|
|
assert exit_status_success == actual_rc
|
2022-09-19 12:44:10 +00:00
|
|
|
check_FTLconf = test_cmd.format("w", "/etc/pihole/pihole-FTL.conf", piholeuser)
|
2021-11-18 01:03:37 +00:00
|
|
|
actual_rc = host.run(check_FTLconf).rc
|
2021-11-11 16:44:57 +00:00
|
|
|
assert exit_status_success == actual_rc
|
|
|
|
# check readable and executable /etc/init.d/pihole-FTL
|
2022-09-19 12:44:10 +00:00
|
|
|
check_init = test_cmd.format("x", "/etc/init.d/pihole-FTL", piholeuser)
|
2021-11-18 01:03:37 +00:00
|
|
|
actual_rc = host.run(check_init).rc
|
2021-11-11 16:44:57 +00:00
|
|
|
assert exit_status_success == actual_rc
|
2022-09-19 12:44:10 +00:00
|
|
|
check_init = test_cmd.format("r", "/etc/init.d/pihole-FTL", piholeuser)
|
2021-11-18 01:03:37 +00:00
|
|
|
actual_rc = host.run(check_init).rc
|
2021-11-11 16:44:57 +00:00
|
|
|
assert exit_status_success == actual_rc
|
|
|
|
# check readable and executable manpages
|
|
|
|
if maninstalled is True:
|
2022-09-19 12:44:10 +00:00
|
|
|
check_man = test_cmd.format("x", "/usr/local/share/man", piholeuser)
|
2021-11-18 01:03:37 +00:00
|
|
|
actual_rc = host.run(check_man).rc
|
2021-11-11 16:44:57 +00:00
|
|
|
assert exit_status_success == actual_rc
|
2022-09-19 12:44:10 +00:00
|
|
|
check_man = test_cmd.format("r", "/usr/local/share/man", piholeuser)
|
2021-11-18 01:03:37 +00:00
|
|
|
actual_rc = host.run(check_man).rc
|
2021-11-11 16:44:57 +00:00
|
|
|
assert exit_status_success == actual_rc
|
2022-09-19 12:44:10 +00:00
|
|
|
check_man = test_cmd.format("x", "/usr/local/share/man/man8", piholeuser)
|
2021-11-18 01:03:37 +00:00
|
|
|
actual_rc = host.run(check_man).rc
|
2021-11-11 16:44:57 +00:00
|
|
|
assert exit_status_success == actual_rc
|
2022-09-19 12:44:10 +00:00
|
|
|
check_man = test_cmd.format("r", "/usr/local/share/man/man8", piholeuser)
|
2021-11-18 01:03:37 +00:00
|
|
|
actual_rc = host.run(check_man).rc
|
2021-11-11 16:44:57 +00:00
|
|
|
assert exit_status_success == actual_rc
|
2022-09-19 12:44:10 +00:00
|
|
|
check_man = test_cmd.format("x", "/usr/local/share/man/man5", piholeuser)
|
2021-11-18 01:03:37 +00:00
|
|
|
actual_rc = host.run(check_man).rc
|
2021-11-11 16:44:57 +00:00
|
|
|
assert exit_status_success == actual_rc
|
2022-09-19 12:44:10 +00:00
|
|
|
check_man = test_cmd.format("r", "/usr/local/share/man/man5", piholeuser)
|
2021-11-18 01:03:37 +00:00
|
|
|
actual_rc = host.run(check_man).rc
|
2021-11-11 16:44:57 +00:00
|
|
|
assert exit_status_success == actual_rc
|
|
|
|
check_man = test_cmd.format(
|
2022-09-19 12:44:10 +00:00
|
|
|
"r", "/usr/local/share/man/man8/pihole.8", piholeuser
|
|
|
|
)
|
2021-11-18 01:03:37 +00:00
|
|
|
actual_rc = host.run(check_man).rc
|
2021-11-11 16:44:57 +00:00
|
|
|
assert exit_status_success == actual_rc
|
|
|
|
check_man = test_cmd.format(
|
2022-09-19 12:44:10 +00:00
|
|
|
"r", "/usr/local/share/man/man8/pihole-FTL.8", piholeuser
|
|
|
|
)
|
2021-11-18 01:03:37 +00:00
|
|
|
actual_rc = host.run(check_man).rc
|
2021-11-11 16:44:57 +00:00
|
|
|
assert exit_status_success == actual_rc
|
|
|
|
# check not readable sudoers file
|
2022-09-19 12:44:10 +00:00
|
|
|
check_sudo = test_cmd.format("r", "/etc/sudoers.d/pihole", piholeuser)
|
2021-11-18 01:03:37 +00:00
|
|
|
actual_rc = host.run(check_sudo).rc
|
2021-11-11 16:44:57 +00:00
|
|
|
assert exit_status_success != actual_rc
|
|
|
|
# check not readable cron file
|
2022-09-19 12:44:10 +00:00
|
|
|
check_sudo = test_cmd.format("x", "/etc/cron.d/", piholeuser)
|
2021-11-18 01:03:37 +00:00
|
|
|
actual_rc = host.run(check_sudo).rc
|
2021-11-11 16:44:57 +00:00
|
|
|
assert exit_status_success == actual_rc
|
2022-09-19 12:44:10 +00:00
|
|
|
check_sudo = test_cmd.format("r", "/etc/cron.d/", piholeuser)
|
2021-11-18 01:03:37 +00:00
|
|
|
actual_rc = host.run(check_sudo).rc
|
2021-11-11 16:44:57 +00:00
|
|
|
assert exit_status_success == actual_rc
|
2022-09-19 12:44:10 +00:00
|
|
|
check_sudo = test_cmd.format("r", "/etc/cron.d/pihole", piholeuser)
|
2021-11-18 01:03:37 +00:00
|
|
|
actual_rc = host.run(check_sudo).rc
|
2021-11-11 16:44:57 +00:00
|
|
|
assert exit_status_success == actual_rc
|
2022-09-19 12:44:10 +00:00
|
|
|
directories = get_directories_recursive(host, "/etc/.pihole/")
|
2021-11-11 16:44:57 +00:00
|
|
|
for directory in directories:
|
2022-09-19 12:44:10 +00:00
|
|
|
check_pihole = test_cmd.format("r", directory, piholeuser)
|
2021-11-18 01:03:37 +00:00
|
|
|
actual_rc = host.run(check_pihole).rc
|
2022-09-19 12:44:10 +00:00
|
|
|
check_pihole = test_cmd.format("x", directory, piholeuser)
|
2021-11-18 01:03:37 +00:00
|
|
|
actual_rc = host.run(check_pihole).rc
|
2021-11-11 16:44:57 +00:00
|
|
|
findfiles = 'find "{}" -maxdepth 1 -type f -exec echo {{}} \\;;'
|
2021-11-18 01:03:37 +00:00
|
|
|
filelist = host.run(findfiles.format(directory))
|
2021-11-11 16:44:57 +00:00
|
|
|
files = list(filter(bool, filelist.stdout.splitlines()))
|
|
|
|
for file in files:
|
2022-09-19 12:44:10 +00:00
|
|
|
check_pihole = test_cmd.format("r", file, piholeuser)
|
2021-11-18 01:03:37 +00:00
|
|
|
actual_rc = host.run(check_pihole).rc
|
2021-11-11 16:44:57 +00:00
|
|
|
|
|
|
|
|
2021-11-18 01:03:37 +00:00
|
|
|
def test_update_package_cache_success_no_errors(host):
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2018-07-03 06:05:24 +00:00
|
|
|
confirms package cache was updated without any errors
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
updateCache = host.run(
|
|
|
|
"""
|
2017-01-28 23:44:31 +00:00
|
|
|
source /opt/pihole/basic-install.sh
|
2021-08-03 20:48:26 +00:00
|
|
|
package_manager_detect
|
2017-01-28 23:44:31 +00:00
|
|
|
update_package_cache
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
expected_stdout = tick_box + " Update local cache of available packages"
|
2018-07-03 06:05:24 +00:00
|
|
|
assert expected_stdout in updateCache.stdout
|
2022-09-19 12:44:10 +00:00
|
|
|
assert "error" not in updateCache.stdout.lower()
|
2017-01-28 23:44:31 +00:00
|
|
|
|
2018-07-02 20:54:19 +00:00
|
|
|
|
2021-11-18 01:03:37 +00:00
|
|
|
def test_update_package_cache_failure_no_errors(host):
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2018-07-03 06:05:24 +00:00
|
|
|
confirms package cache was not updated
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
mock_command("apt-get", {"update": ("", "1")}, host)
|
|
|
|
updateCache = host.run(
|
|
|
|
"""
|
2017-01-28 23:49:28 +00:00
|
|
|
source /opt/pihole/basic-install.sh
|
2021-08-03 20:48:26 +00:00
|
|
|
package_manager_detect
|
2017-01-28 23:49:28 +00:00
|
|
|
update_package_cache
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
expected_stdout = cross_box + " Update local cache of available packages"
|
2018-07-03 06:05:24 +00:00
|
|
|
assert expected_stdout in updateCache.stdout
|
2022-09-19 12:44:10 +00:00
|
|
|
assert "Error: Unable to update package cache." in updateCache.stdout
|
2017-01-28 23:49:28 +00:00
|
|
|
|
2018-07-02 20:54:19 +00:00
|
|
|
|
2021-11-18 01:03:37 +00:00
|
|
|
def test_FTL_detect_aarch64_no_errors(host):
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2018-07-03 06:05:24 +00:00
|
|
|
confirms only aarch64 package is downloaded for FTL engine
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2017-02-20 05:38:02 +00:00
|
|
|
# mock uname to return aarch64 platform
|
2022-09-19 12:44:10 +00:00
|
|
|
mock_command("uname", {"-m": ("aarch64", "0")}, host)
|
2017-02-20 12:44:31 +00:00
|
|
|
# mock ldd to respond with aarch64 shared library
|
2022-10-11 20:18:31 +00:00
|
|
|
mock_command(
|
|
|
|
"ldd",
|
|
|
|
{
|
|
|
|
"/bin/sh": ("/lib/ld-linux-aarch64.so.1", "0"),
|
|
|
|
"/usr/bin/sh": ("/lib/ld-linux-aarch64.so.1", "0"),
|
|
|
|
},
|
|
|
|
host,
|
|
|
|
)
|
2022-09-19 12:44:10 +00:00
|
|
|
detectPlatform = host.run(
|
|
|
|
"""
|
2017-02-20 05:38:02 +00:00
|
|
|
source /opt/pihole/basic-install.sh
|
2019-05-12 09:27:25 +00:00
|
|
|
create_pihole_user
|
2019-11-14 18:52:07 +00:00
|
|
|
funcOutput=$(get_binary_name)
|
|
|
|
binary="pihole-FTL${funcOutput##*pihole-FTL}"
|
|
|
|
theRest="${funcOutput%pihole-FTL*}"
|
|
|
|
FTLdetect "${binary}" "${theRest}"
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
expected_stdout = info_box + " FTL Checks..."
|
2017-06-21 11:49:05 +00:00
|
|
|
assert expected_stdout in detectPlatform.stdout
|
2022-09-19 12:44:10 +00:00
|
|
|
expected_stdout = tick_box + " Detected AArch64 (64 Bit ARM) processor"
|
2020-10-13 13:18:14 +00:00
|
|
|
assert expected_stdout in detectPlatform.stdout
|
2022-09-19 12:44:10 +00:00
|
|
|
expected_stdout = tick_box + " Downloading and Installing FTL"
|
2020-10-13 13:18:14 +00:00
|
|
|
assert expected_stdout in detectPlatform.stdout
|
|
|
|
|
|
|
|
|
2021-11-18 01:03:37 +00:00
|
|
|
def test_FTL_detect_armv4t_no_errors(host):
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2020-10-13 13:18:14 +00:00
|
|
|
confirms only armv4t package is downloaded for FTL engine
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2020-10-13 13:18:14 +00:00
|
|
|
# mock uname to return armv4t platform
|
2022-09-19 12:44:10 +00:00
|
|
|
mock_command("uname", {"-m": ("armv4t", "0")}, host)
|
2022-04-20 17:35:18 +00:00
|
|
|
# mock ldd to respond with armv4t shared library
|
2022-10-11 20:18:31 +00:00
|
|
|
mock_command(
|
|
|
|
"ldd",
|
|
|
|
{
|
|
|
|
"/bin/sh": ("/lib/ld-linux.so.3", "0"),
|
|
|
|
"/usr/bin/sh": ("/lib/ld-linux.so.3", "0"),
|
|
|
|
},
|
|
|
|
host,
|
|
|
|
)
|
2022-09-19 12:44:10 +00:00
|
|
|
detectPlatform = host.run(
|
|
|
|
"""
|
2020-10-13 13:18:14 +00:00
|
|
|
source /opt/pihole/basic-install.sh
|
|
|
|
create_pihole_user
|
|
|
|
funcOutput=$(get_binary_name)
|
|
|
|
binary="pihole-FTL${funcOutput##*pihole-FTL}"
|
|
|
|
theRest="${funcOutput%pihole-FTL*}"
|
|
|
|
FTLdetect "${binary}" "${theRest}"
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
expected_stdout = info_box + " FTL Checks..."
|
2020-10-13 13:18:14 +00:00
|
|
|
assert expected_stdout in detectPlatform.stdout
|
2022-09-19 12:44:10 +00:00
|
|
|
expected_stdout = tick_box + (" Detected ARMv4 processor")
|
2020-10-13 13:18:14 +00:00
|
|
|
assert expected_stdout in detectPlatform.stdout
|
2022-09-19 12:44:10 +00:00
|
|
|
expected_stdout = tick_box + " Downloading and Installing FTL"
|
2020-10-13 13:18:14 +00:00
|
|
|
assert expected_stdout in detectPlatform.stdout
|
|
|
|
|
|
|
|
|
2021-11-18 01:03:37 +00:00
|
|
|
def test_FTL_detect_armv5te_no_errors(host):
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2020-10-13 13:18:14 +00:00
|
|
|
confirms only armv5te package is downloaded for FTL engine
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2020-10-13 13:18:14 +00:00
|
|
|
# mock uname to return armv5te platform
|
2022-09-19 12:44:10 +00:00
|
|
|
mock_command("uname", {"-m": ("armv5te", "0")}, host)
|
2020-10-13 13:18:14 +00:00
|
|
|
# mock ldd to respond with ld-linux shared library
|
2022-10-11 20:18:31 +00:00
|
|
|
mock_command(
|
|
|
|
"ldd",
|
|
|
|
{
|
|
|
|
"/bin/sh": ("/lib/ld-linux.so.3", "0"),
|
|
|
|
"/usr/bin/sh": ("/lib/ld-linux.so.3", "0"),
|
|
|
|
},
|
|
|
|
host,
|
|
|
|
)
|
2022-09-19 12:44:10 +00:00
|
|
|
detectPlatform = host.run(
|
|
|
|
"""
|
2020-10-13 13:18:14 +00:00
|
|
|
source /opt/pihole/basic-install.sh
|
|
|
|
create_pihole_user
|
|
|
|
funcOutput=$(get_binary_name)
|
|
|
|
binary="pihole-FTL${funcOutput##*pihole-FTL}"
|
|
|
|
theRest="${funcOutput%pihole-FTL*}"
|
|
|
|
FTLdetect "${binary}" "${theRest}"
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
expected_stdout = info_box + " FTL Checks..."
|
2020-10-13 13:18:14 +00:00
|
|
|
assert expected_stdout in detectPlatform.stdout
|
2022-09-19 12:44:10 +00:00
|
|
|
expected_stdout = tick_box + (" Detected ARMv5 (or newer) processor")
|
2017-06-21 11:49:05 +00:00
|
|
|
assert expected_stdout in detectPlatform.stdout
|
2022-09-19 12:44:10 +00:00
|
|
|
expected_stdout = tick_box + " Downloading and Installing FTL"
|
2017-02-20 05:38:02 +00:00
|
|
|
assert expected_stdout in detectPlatform.stdout
|
|
|
|
|
2018-07-02 20:54:19 +00:00
|
|
|
|
2021-11-18 01:03:37 +00:00
|
|
|
def test_FTL_detect_armv6l_no_errors(host):
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2018-07-03 06:05:24 +00:00
|
|
|
confirms only armv6l package is downloaded for FTL engine
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2017-02-20 12:44:31 +00:00
|
|
|
# mock uname to return armv6l platform
|
2022-09-19 12:44:10 +00:00
|
|
|
mock_command("uname", {"-m": ("armv6l", "0")}, host)
|
2020-10-13 13:18:14 +00:00
|
|
|
# mock ldd to respond with ld-linux-armhf shared library
|
2022-10-11 20:18:31 +00:00
|
|
|
mock_command(
|
|
|
|
"ldd",
|
|
|
|
{
|
|
|
|
"/bin/sh": ("/lib/ld-linux-armhf.so.3", "0"),
|
|
|
|
"/usr/bin/sh": ("/lib/ld-linux-armhf.so.3", "0"),
|
|
|
|
},
|
|
|
|
host,
|
|
|
|
)
|
2022-09-19 12:44:10 +00:00
|
|
|
detectPlatform = host.run(
|
|
|
|
"""
|
2017-02-20 12:44:31 +00:00
|
|
|
source /opt/pihole/basic-install.sh
|
2019-05-12 09:27:25 +00:00
|
|
|
create_pihole_user
|
2019-11-14 18:52:07 +00:00
|
|
|
funcOutput=$(get_binary_name)
|
|
|
|
binary="pihole-FTL${funcOutput##*pihole-FTL}"
|
|
|
|
theRest="${funcOutput%pihole-FTL*}"
|
|
|
|
FTLdetect "${binary}" "${theRest}"
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
expected_stdout = info_box + " FTL Checks..."
|
2017-06-21 11:49:05 +00:00
|
|
|
assert expected_stdout in detectPlatform.stdout
|
2022-09-19 12:44:10 +00:00
|
|
|
expected_stdout = tick_box + (
|
|
|
|
" Detected ARMv6 processor " "(with hard-float support)"
|
|
|
|
)
|
2017-06-21 11:49:05 +00:00
|
|
|
assert expected_stdout in detectPlatform.stdout
|
2022-09-19 12:44:10 +00:00
|
|
|
expected_stdout = tick_box + " Downloading and Installing FTL"
|
2017-02-20 12:44:31 +00:00
|
|
|
assert expected_stdout in detectPlatform.stdout
|
|
|
|
|
2018-07-02 20:54:19 +00:00
|
|
|
|
2021-11-18 01:03:37 +00:00
|
|
|
def test_FTL_detect_armv7l_no_errors(host):
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2018-07-03 06:05:24 +00:00
|
|
|
confirms only armv7l package is downloaded for FTL engine
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2017-02-20 12:44:31 +00:00
|
|
|
# mock uname to return armv7l platform
|
2022-09-19 12:44:10 +00:00
|
|
|
mock_command("uname", {"-m": ("armv7l", "0")}, host)
|
2020-10-13 13:18:14 +00:00
|
|
|
# mock ldd to respond with ld-linux-armhf shared library
|
2022-10-11 20:18:31 +00:00
|
|
|
mock_command(
|
|
|
|
"ldd",
|
|
|
|
{
|
|
|
|
"/bin/sh": ("/lib/ld-linux-armhf.so.3", "0"),
|
|
|
|
"/usr/bin/sh": ("/lib/ld-linux-armhf.so.3", "0"),
|
|
|
|
},
|
|
|
|
host,
|
|
|
|
)
|
2022-09-19 12:44:10 +00:00
|
|
|
detectPlatform = host.run(
|
|
|
|
"""
|
2020-10-13 13:18:14 +00:00
|
|
|
source /opt/pihole/basic-install.sh
|
|
|
|
create_pihole_user
|
|
|
|
funcOutput=$(get_binary_name)
|
|
|
|
binary="pihole-FTL${funcOutput##*pihole-FTL}"
|
|
|
|
theRest="${funcOutput%pihole-FTL*}"
|
|
|
|
FTLdetect "${binary}" "${theRest}"
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
expected_stdout = info_box + " FTL Checks..."
|
2020-10-13 13:18:14 +00:00
|
|
|
assert expected_stdout in detectPlatform.stdout
|
2022-09-19 12:44:10 +00:00
|
|
|
expected_stdout = tick_box + (
|
|
|
|
" Detected ARMv7 processor " "(with hard-float support)"
|
|
|
|
)
|
2020-10-13 13:18:14 +00:00
|
|
|
assert expected_stdout in detectPlatform.stdout
|
2022-09-19 12:44:10 +00:00
|
|
|
expected_stdout = tick_box + " Downloading and Installing FTL"
|
2020-10-13 13:18:14 +00:00
|
|
|
assert expected_stdout in detectPlatform.stdout
|
|
|
|
|
|
|
|
|
2021-11-18 01:03:37 +00:00
|
|
|
def test_FTL_detect_armv8a_no_errors(host):
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2020-10-13 13:18:14 +00:00
|
|
|
confirms only armv8a package is downloaded for FTL engine
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2020-10-13 13:18:14 +00:00
|
|
|
# mock uname to return armv8a platform
|
2022-09-19 12:44:10 +00:00
|
|
|
mock_command("uname", {"-m": ("armv8a", "0")}, host)
|
2020-10-13 13:18:14 +00:00
|
|
|
# mock ldd to respond with ld-linux-armhf shared library
|
2022-10-11 20:18:31 +00:00
|
|
|
mock_command(
|
|
|
|
"ldd",
|
|
|
|
{
|
|
|
|
"/bin/sh": ("/lib/ld-linux-armhf.so.3", "0"),
|
|
|
|
"/usr/bin/sh": ("/lib/ld-linux-armhf.so.3", "0"),
|
|
|
|
},
|
|
|
|
host,
|
|
|
|
)
|
2022-09-19 12:44:10 +00:00
|
|
|
detectPlatform = host.run(
|
|
|
|
"""
|
2017-02-20 12:44:31 +00:00
|
|
|
source /opt/pihole/basic-install.sh
|
2019-05-12 09:27:25 +00:00
|
|
|
create_pihole_user
|
2019-11-14 18:52:07 +00:00
|
|
|
funcOutput=$(get_binary_name)
|
|
|
|
binary="pihole-FTL${funcOutput##*pihole-FTL}"
|
|
|
|
theRest="${funcOutput%pihole-FTL*}"
|
|
|
|
FTLdetect "${binary}" "${theRest}"
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
expected_stdout = info_box + " FTL Checks..."
|
2017-06-21 11:49:05 +00:00
|
|
|
assert expected_stdout in detectPlatform.stdout
|
2022-09-19 12:44:10 +00:00
|
|
|
expected_stdout = tick_box + " Detected ARMv8 (or newer) processor"
|
2017-06-21 11:49:05 +00:00
|
|
|
assert expected_stdout in detectPlatform.stdout
|
2022-09-19 12:44:10 +00:00
|
|
|
expected_stdout = tick_box + " Downloading and Installing FTL"
|
2017-02-20 12:44:31 +00:00
|
|
|
assert expected_stdout in detectPlatform.stdout
|
|
|
|
|
2018-07-02 20:54:19 +00:00
|
|
|
|
2021-11-18 01:03:37 +00:00
|
|
|
def test_FTL_detect_x86_64_no_errors(host):
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2018-07-03 06:05:24 +00:00
|
|
|
confirms only x86_64 package is downloaded for FTL engine
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
detectPlatform = host.run(
|
|
|
|
"""
|
2017-02-20 12:44:31 +00:00
|
|
|
source /opt/pihole/basic-install.sh
|
2019-05-12 09:27:25 +00:00
|
|
|
create_pihole_user
|
2019-11-14 18:52:07 +00:00
|
|
|
funcOutput=$(get_binary_name)
|
|
|
|
binary="pihole-FTL${funcOutput##*pihole-FTL}"
|
|
|
|
theRest="${funcOutput%pihole-FTL*}"
|
|
|
|
FTLdetect "${binary}" "${theRest}"
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
expected_stdout = info_box + " FTL Checks..."
|
2017-06-21 11:49:05 +00:00
|
|
|
assert expected_stdout in detectPlatform.stdout
|
2022-09-19 12:44:10 +00:00
|
|
|
expected_stdout = tick_box + " Detected x86_64 processor"
|
2017-06-21 11:49:05 +00:00
|
|
|
assert expected_stdout in detectPlatform.stdout
|
2022-09-19 12:44:10 +00:00
|
|
|
expected_stdout = tick_box + " Downloading and Installing FTL"
|
2017-02-20 12:44:31 +00:00
|
|
|
assert expected_stdout in detectPlatform.stdout
|
|
|
|
|
2018-07-02 20:54:19 +00:00
|
|
|
|
2021-11-18 01:03:37 +00:00
|
|
|
def test_FTL_detect_unknown_no_errors(host):
|
2022-09-19 12:44:10 +00:00
|
|
|
"""confirms only generic package is downloaded for FTL engine"""
|
2017-02-20 12:44:31 +00:00
|
|
|
# mock uname to return generic platform
|
2022-09-19 12:44:10 +00:00
|
|
|
mock_command("uname", {"-m": ("mips", "0")}, host)
|
|
|
|
detectPlatform = host.run(
|
|
|
|
"""
|
2017-02-20 05:38:02 +00:00
|
|
|
source /opt/pihole/basic-install.sh
|
2019-05-12 09:27:25 +00:00
|
|
|
create_pihole_user
|
2019-11-14 18:52:07 +00:00
|
|
|
funcOutput=$(get_binary_name)
|
|
|
|
binary="pihole-FTL${funcOutput##*pihole-FTL}"
|
|
|
|
theRest="${funcOutput%pihole-FTL*}"
|
|
|
|
FTLdetect "${binary}" "${theRest}"
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
expected_stdout = "Not able to detect processor (unknown: mips)"
|
2017-02-20 05:38:02 +00:00
|
|
|
assert expected_stdout in detectPlatform.stdout
|
2017-02-20 17:36:24 +00:00
|
|
|
|
2018-07-02 20:54:19 +00:00
|
|
|
|
2021-11-18 01:03:37 +00:00
|
|
|
def test_FTL_download_aarch64_no_errors(host):
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2018-07-03 06:05:24 +00:00
|
|
|
confirms only aarch64 package is downloaded for FTL engine
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2022-07-02 19:51:03 +00:00
|
|
|
# mock dialog answers and ensure installer dependencies
|
2022-09-19 12:44:10 +00:00
|
|
|
mock_command("dialog", {"*": ("", "0")}, host)
|
|
|
|
host.run(
|
|
|
|
"""
|
2019-07-06 17:06:08 +00:00
|
|
|
source /opt/pihole/basic-install.sh
|
2021-08-03 20:48:26 +00:00
|
|
|
package_manager_detect
|
2019-07-06 17:06:08 +00:00
|
|
|
install_dependent_packages ${INSTALLER_DEPS[@]}
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
download_binary = host.run(
|
|
|
|
"""
|
2017-02-20 17:36:24 +00:00
|
|
|
source /opt/pihole/basic-install.sh
|
2019-05-12 09:27:25 +00:00
|
|
|
create_pihole_user
|
2019-11-14 18:52:07 +00:00
|
|
|
FTLinstall "pihole-FTL-aarch64-linux-gnu"
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
expected_stdout = tick_box + " Downloading and Installing FTL"
|
2017-02-20 17:36:24 +00:00
|
|
|
assert expected_stdout in download_binary.stdout
|
2022-09-19 12:44:10 +00:00
|
|
|
assert "error" not in download_binary.stdout.lower()
|
2017-02-20 17:36:24 +00:00
|
|
|
|
2018-07-02 20:54:19 +00:00
|
|
|
|
2021-11-18 01:03:37 +00:00
|
|
|
def test_FTL_binary_installed_and_responsive_no_errors(host):
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2018-07-03 06:05:24 +00:00
|
|
|
confirms FTL binary is copied and functional in installed location
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2022-09-19 12:48:58 +00:00
|
|
|
host.run(
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2017-02-21 01:15:04 +00:00
|
|
|
source /opt/pihole/basic-install.sh
|
2019-05-12 09:27:25 +00:00
|
|
|
create_pihole_user
|
2019-11-14 18:52:07 +00:00
|
|
|
funcOutput=$(get_binary_name)
|
2022-09-03 11:09:37 +00:00
|
|
|
echo "development" > /etc/pihole/ftlbranch
|
2019-11-14 18:52:07 +00:00
|
|
|
binary="pihole-FTL${funcOutput##*pihole-FTL}"
|
|
|
|
theRest="${funcOutput%pihole-FTL*}"
|
|
|
|
FTLdetect "${binary}" "${theRest}"
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
version_check = host.run(
|
|
|
|
"""
|
2022-09-03 11:55:17 +00:00
|
|
|
VERSION=$(pihole-FTL version)
|
|
|
|
echo ${VERSION:0:1}
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
expected_stdout = "v"
|
2022-09-03 11:09:37 +00:00
|
|
|
assert expected_stdout in version_check.stdout
|
2017-02-21 01:15:04 +00:00
|
|
|
|
2018-07-02 20:54:19 +00:00
|
|
|
|
2021-11-18 01:03:37 +00:00
|
|
|
def test_IPv6_only_link_local(host):
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2018-07-03 06:05:24 +00:00
|
|
|
confirms IPv6 blocking is disabled for Link-local address
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2017-06-02 21:01:48 +00:00
|
|
|
# mock ip -6 address to return Link-local address
|
2018-07-03 06:05:24 +00:00
|
|
|
mock_command_2(
|
2022-09-19 12:44:10 +00:00
|
|
|
"ip",
|
|
|
|
{"-6 address": ("inet6 fe80::d210:52fa:fe00:7ad7/64 scope link", "0")},
|
|
|
|
host,
|
2018-07-03 06:05:24 +00:00
|
|
|
)
|
2022-09-19 12:44:10 +00:00
|
|
|
detectPlatform = host.run(
|
|
|
|
"""
|
2017-06-02 21:01:48 +00:00
|
|
|
source /opt/pihole/basic-install.sh
|
2021-10-02 21:43:08 +00:00
|
|
|
find_IPv6_information
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
expected_stdout = "Unable to find IPv6 ULA/GUA address"
|
2017-06-02 21:01:48 +00:00
|
|
|
assert expected_stdout in detectPlatform.stdout
|
|
|
|
|
2018-07-02 20:54:19 +00:00
|
|
|
|
2021-11-18 01:03:37 +00:00
|
|
|
def test_IPv6_only_ULA(host):
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2018-07-03 06:05:24 +00:00
|
|
|
confirms IPv6 blocking is enabled for ULA addresses
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2017-06-02 21:01:48 +00:00
|
|
|
# mock ip -6 address to return ULA address
|
2018-07-03 06:05:24 +00:00
|
|
|
mock_command_2(
|
2022-09-19 12:44:10 +00:00
|
|
|
"ip",
|
2018-07-03 06:05:24 +00:00
|
|
|
{
|
2022-09-19 12:44:10 +00:00
|
|
|
"-6 address": (
|
|
|
|
"inet6 fda2:2001:5555:0:d210:52fa:fe00:7ad7/64 scope global",
|
|
|
|
"0",
|
2018-07-03 06:05:24 +00:00
|
|
|
)
|
|
|
|
},
|
2022-09-19 12:44:10 +00:00
|
|
|
host,
|
2018-07-03 06:05:24 +00:00
|
|
|
)
|
2022-09-19 12:44:10 +00:00
|
|
|
detectPlatform = host.run(
|
|
|
|
"""
|
2017-06-02 21:01:48 +00:00
|
|
|
source /opt/pihole/basic-install.sh
|
2021-10-02 21:47:13 +00:00
|
|
|
find_IPv6_information
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
expected_stdout = "Found IPv6 ULA address"
|
2017-06-02 21:01:48 +00:00
|
|
|
assert expected_stdout in detectPlatform.stdout
|
|
|
|
|
2018-07-02 20:54:19 +00:00
|
|
|
|
2021-11-18 01:03:37 +00:00
|
|
|
def test_IPv6_only_GUA(host):
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2018-07-03 06:05:24 +00:00
|
|
|
confirms IPv6 blocking is enabled for GUA addresses
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2017-06-02 21:01:48 +00:00
|
|
|
# mock ip -6 address to return GUA address
|
2018-07-03 06:05:24 +00:00
|
|
|
mock_command_2(
|
2022-09-19 12:44:10 +00:00
|
|
|
"ip",
|
2018-07-03 06:05:24 +00:00
|
|
|
{
|
2022-09-19 12:44:10 +00:00
|
|
|
"-6 address": (
|
|
|
|
"inet6 2003:12:1e43:301:d210:52fa:fe00:7ad7/64 scope global",
|
|
|
|
"0",
|
2018-07-03 06:05:24 +00:00
|
|
|
)
|
|
|
|
},
|
2022-09-19 12:44:10 +00:00
|
|
|
host,
|
2018-07-03 06:05:24 +00:00
|
|
|
)
|
2022-09-19 12:44:10 +00:00
|
|
|
detectPlatform = host.run(
|
|
|
|
"""
|
2017-06-02 21:01:48 +00:00
|
|
|
source /opt/pihole/basic-install.sh
|
2021-10-02 21:43:08 +00:00
|
|
|
find_IPv6_information
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
expected_stdout = "Found IPv6 GUA address"
|
2017-06-02 21:01:48 +00:00
|
|
|
assert expected_stdout in detectPlatform.stdout
|
|
|
|
|
2018-07-02 20:54:19 +00:00
|
|
|
|
2021-11-18 01:03:37 +00:00
|
|
|
def test_IPv6_GUA_ULA_test(host):
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2018-07-03 06:05:24 +00:00
|
|
|
confirms IPv6 blocking is enabled for GUA and ULA addresses
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2017-06-02 21:01:48 +00:00
|
|
|
# mock ip -6 address to return GUA and ULA addresses
|
2018-07-03 06:05:24 +00:00
|
|
|
mock_command_2(
|
2022-09-19 12:44:10 +00:00
|
|
|
"ip",
|
2018-07-03 06:05:24 +00:00
|
|
|
{
|
2022-09-19 12:44:10 +00:00
|
|
|
"-6 address": (
|
|
|
|
"inet6 2003:12:1e43:301:d210:52fa:fe00:7ad7/64 scope global\n"
|
|
|
|
"inet6 fda2:2001:5555:0:d210:52fa:fe00:7ad7/64 scope global",
|
|
|
|
"0",
|
2018-07-03 06:05:24 +00:00
|
|
|
)
|
|
|
|
},
|
2022-09-19 12:44:10 +00:00
|
|
|
host,
|
2018-07-03 06:05:24 +00:00
|
|
|
)
|
2022-09-19 12:44:10 +00:00
|
|
|
detectPlatform = host.run(
|
|
|
|
"""
|
2017-06-02 21:01:48 +00:00
|
|
|
source /opt/pihole/basic-install.sh
|
2021-10-02 21:47:13 +00:00
|
|
|
find_IPv6_information
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
expected_stdout = "Found IPv6 ULA address"
|
2017-06-02 21:01:48 +00:00
|
|
|
assert expected_stdout in detectPlatform.stdout
|
|
|
|
|
2018-07-02 20:54:19 +00:00
|
|
|
|
2021-11-18 01:03:37 +00:00
|
|
|
def test_IPv6_ULA_GUA_test(host):
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2018-07-03 06:05:24 +00:00
|
|
|
confirms IPv6 blocking is enabled for GUA and ULA addresses
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2017-06-02 21:01:48 +00:00
|
|
|
# mock ip -6 address to return ULA and GUA addresses
|
2018-07-03 06:05:24 +00:00
|
|
|
mock_command_2(
|
2022-09-19 12:44:10 +00:00
|
|
|
"ip",
|
2018-07-03 06:05:24 +00:00
|
|
|
{
|
2022-09-19 12:44:10 +00:00
|
|
|
"-6 address": (
|
|
|
|
"inet6 fda2:2001:5555:0:d210:52fa:fe00:7ad7/64 scope global\n"
|
|
|
|
"inet6 2003:12:1e43:301:d210:52fa:fe00:7ad7/64 scope global",
|
|
|
|
"0",
|
2018-07-03 06:05:24 +00:00
|
|
|
)
|
|
|
|
},
|
2022-09-19 12:44:10 +00:00
|
|
|
host,
|
2018-07-03 06:05:24 +00:00
|
|
|
)
|
2022-09-19 12:44:10 +00:00
|
|
|
detectPlatform = host.run(
|
|
|
|
"""
|
2017-06-02 21:01:48 +00:00
|
|
|
source /opt/pihole/basic-install.sh
|
2021-10-02 21:47:13 +00:00
|
|
|
find_IPv6_information
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
expected_stdout = "Found IPv6 ULA address"
|
2017-06-02 21:01:48 +00:00
|
|
|
assert expected_stdout in detectPlatform.stdout
|
2019-07-11 04:18:58 +00:00
|
|
|
|
|
|
|
|
2021-11-18 01:03:37 +00:00
|
|
|
def test_validate_ip(host):
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2021-03-17 10:09:13 +00:00
|
|
|
Tests valid_ip for various IP addresses
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
2021-03-17 10:09:13 +00:00
|
|
|
|
|
|
|
def test_address(addr, success=True):
|
2022-09-19 12:44:10 +00:00
|
|
|
output = host.run(
|
|
|
|
"""
|
2021-03-17 10:09:13 +00:00
|
|
|
source /opt/pihole/basic-install.sh
|
|
|
|
valid_ip "{addr}"
|
2022-09-19 12:44:10 +00:00
|
|
|
""".format(
|
|
|
|
addr=addr
|
|
|
|
)
|
|
|
|
)
|
2021-03-17 10:09:13 +00:00
|
|
|
|
|
|
|
assert output.rc == 0 if success else 1
|
|
|
|
|
2022-09-19 12:44:10 +00:00
|
|
|
test_address("192.168.1.1")
|
|
|
|
test_address("127.0.0.1")
|
|
|
|
test_address("255.255.255.255")
|
|
|
|
test_address("255.255.255.256", False)
|
|
|
|
test_address("255.255.256.255", False)
|
|
|
|
test_address("255.256.255.255", False)
|
|
|
|
test_address("256.255.255.255", False)
|
|
|
|
test_address("1092.168.1.1", False)
|
|
|
|
test_address("not an IP", False)
|
|
|
|
test_address("8.8.8.8#", False)
|
|
|
|
test_address("8.8.8.8#0")
|
|
|
|
test_address("8.8.8.8#1")
|
|
|
|
test_address("8.8.8.8#42")
|
|
|
|
test_address("8.8.8.8#888")
|
|
|
|
test_address("8.8.8.8#1337")
|
|
|
|
test_address("8.8.8.8#65535")
|
|
|
|
test_address("8.8.8.8#65536", False)
|
|
|
|
test_address("8.8.8.8#-1", False)
|
|
|
|
test_address("00.0.0.0", False)
|
|
|
|
test_address("010.0.0.0", False)
|
|
|
|
test_address("001.0.0.0", False)
|
|
|
|
test_address("0.0.0.0#00", False)
|
|
|
|
test_address("0.0.0.0#01", False)
|
|
|
|
test_address("0.0.0.0#001", False)
|
|
|
|
test_address("0.0.0.0#0001", False)
|
|
|
|
test_address("0.0.0.0#00001", False)
|
2020-07-28 18:07:17 +00:00
|
|
|
|
2020-08-09 19:02:48 +00:00
|
|
|
|
2021-11-18 01:03:37 +00:00
|
|
|
def test_os_check_fails(host):
|
2022-09-19 12:44:10 +00:00
|
|
|
"""Confirms install fails on unsupported OS"""
|
|
|
|
host.run(
|
|
|
|
"""
|
2020-10-23 22:05:41 +00:00
|
|
|
source /opt/pihole/basic-install.sh
|
2021-08-03 20:48:26 +00:00
|
|
|
package_manager_detect
|
2021-08-03 21:48:03 +00:00
|
|
|
install_dependent_packages ${OS_CHECK_DEPS[@]}
|
2020-10-23 22:05:41 +00:00
|
|
|
install_dependent_packages ${INSTALLER_DEPS[@]}
|
|
|
|
cat <<EOT > /etc/os-release
|
2021-11-30 01:57:44 +00:00
|
|
|
ID=UnsupportedOS
|
|
|
|
VERSION_ID="2"
|
|
|
|
EOT
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
detectOS = host.run(
|
|
|
|
"""t
|
2020-10-23 22:05:41 +00:00
|
|
|
source /opt/pihole/basic-install.sh
|
|
|
|
os_check
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
expected_stdout = "Unsupported OS detected: UnsupportedOS"
|
2020-10-23 22:05:41 +00:00
|
|
|
assert expected_stdout in detectOS.stdout
|
|
|
|
|
2020-10-23 22:09:07 +00:00
|
|
|
|
2021-11-18 01:03:37 +00:00
|
|
|
def test_os_check_passes(host):
|
2022-09-19 12:44:10 +00:00
|
|
|
"""Confirms OS meets the requirements"""
|
|
|
|
host.run(
|
|
|
|
"""
|
2020-07-28 18:07:17 +00:00
|
|
|
source /opt/pihole/basic-install.sh
|
2021-08-03 20:48:26 +00:00
|
|
|
package_manager_detect
|
2021-08-03 21:48:03 +00:00
|
|
|
install_dependent_packages ${OS_CHECK_DEPS[@]}
|
2020-07-28 18:07:17 +00:00
|
|
|
install_dependent_packages ${INSTALLER_DEPS[@]}
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
detectOS = host.run(
|
|
|
|
"""
|
2020-07-28 18:07:17 +00:00
|
|
|
source /opt/pihole/basic-install.sh
|
|
|
|
os_check
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
expected_stdout = "Supported OS detected"
|
2020-10-23 22:09:07 +00:00
|
|
|
assert expected_stdout in detectOS.stdout
|
2021-07-02 23:00:54 +00:00
|
|
|
|
|
|
|
|
2021-11-18 01:03:37 +00:00
|
|
|
def test_package_manager_has_installer_deps(host):
|
2022-09-19 12:44:10 +00:00
|
|
|
"""Confirms OS is able to install the required packages for the installer"""
|
|
|
|
mock_command("dialog", {"*": ("", "0")}, host)
|
|
|
|
output = host.run(
|
|
|
|
"""
|
2021-07-02 23:00:54 +00:00
|
|
|
source /opt/pihole/basic-install.sh
|
2021-08-03 20:48:26 +00:00
|
|
|
package_manager_detect
|
2021-07-02 23:00:54 +00:00
|
|
|
install_dependent_packages ${INSTALLER_DEPS[@]}
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
)
|
2021-07-02 23:00:54 +00:00
|
|
|
|
2022-09-19 12:44:10 +00:00
|
|
|
assert "No package" not in output.stdout
|
2021-07-02 23:00:54 +00:00
|
|
|
assert output.rc == 0
|
|
|
|
|
|
|
|
|
2021-11-18 01:03:37 +00:00
|
|
|
def test_package_manager_has_pihole_deps(host):
|
2022-09-19 12:44:10 +00:00
|
|
|
"""Confirms OS is able to install the required packages for Pi-hole"""
|
|
|
|
mock_command("dialog", {"*": ("", "0")}, host)
|
|
|
|
output = host.run(
|
|
|
|
"""
|
2021-07-02 23:00:54 +00:00
|
|
|
source /opt/pihole/basic-install.sh
|
2021-08-03 20:48:26 +00:00
|
|
|
package_manager_detect
|
2021-07-02 23:00:54 +00:00
|
|
|
install_dependent_packages ${PIHOLE_DEPS[@]}
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
)
|
2021-07-02 23:00:54 +00:00
|
|
|
|
2022-09-19 12:44:10 +00:00
|
|
|
assert "No package" not in output.stdout
|
2021-07-02 23:00:54 +00:00
|
|
|
assert output.rc == 0
|
|
|
|
|
|
|
|
|
2021-11-18 01:03:37 +00:00
|
|
|
def test_package_manager_has_web_deps(host):
|
2022-09-19 12:44:10 +00:00
|
|
|
"""Confirms OS is able to install the required packages for web"""
|
|
|
|
mock_command("dialog", {"*": ("", "0")}, host)
|
|
|
|
output = host.run(
|
|
|
|
"""
|
2021-07-02 23:00:54 +00:00
|
|
|
source /opt/pihole/basic-install.sh
|
2021-08-03 20:48:26 +00:00
|
|
|
package_manager_detect
|
2021-07-02 23:00:54 +00:00
|
|
|
install_dependent_packages ${PIHOLE_WEB_DEPS[@]}
|
2022-09-19 12:44:10 +00:00
|
|
|
"""
|
|
|
|
)
|
2021-07-02 23:00:54 +00:00
|
|
|
|
2022-09-19 12:44:10 +00:00
|
|
|
assert "No package" not in output.stdout
|
2021-07-02 23:00:54 +00:00
|
|
|
assert output.rc == 0
|