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
|
|
|
SETUPVARS,
|
|
|
|
tick_box,
|
|
|
|
info_box,
|
|
|
|
cross_box,
|
|
|
|
mock_command,
|
|
|
|
mock_command_2,
|
|
|
|
run_script
|
|
|
|
)
|
2017-06-21 11:49:05 +00:00
|
|
|
|
2018-07-02 20:54:19 +00:00
|
|
|
|
2021-10-04 10:40:53 +00:00
|
|
|
def test_supported_package_manager(Pihole):
|
2018-07-06 16:07:43 +00:00
|
|
|
'''
|
2021-10-04 10:40:53 +00:00
|
|
|
confirm installer exits when no supported package manager found
|
2018-07-06 16:07:43 +00:00
|
|
|
'''
|
2021-10-04 10:40:53 +00:00
|
|
|
# break supported package managers
|
2018-07-06 16:07:43 +00:00
|
|
|
Pihole.run('rm -rf /usr/bin/apt-get')
|
|
|
|
Pihole.run('rm -rf /usr/bin/rpm')
|
2021-08-03 20:48:26 +00:00
|
|
|
package_manager_detect = Pihole.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
|
2018-07-06 16:07:43 +00:00
|
|
|
''')
|
2021-10-04 10:40:53 +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
|
|
|
|
|
|
|
|
2016-10-11 04:14:39 +00:00
|
|
|
def test_setupVars_are_sourced_to_global_scope(Pihole):
|
2018-07-03 06:05:24 +00:00
|
|
|
'''
|
|
|
|
currently update_dialogs sources setupVars with a dot,
|
2016-11-03 04:25:13 +00:00
|
|
|
then various other functions use the variables.
|
2018-07-03 06:05:24 +00:00
|
|
|
This confirms the sourced variables are in scope between functions
|
|
|
|
'''
|
2016-10-11 04:14:39 +00:00
|
|
|
setup_var_file = 'cat <<EOF> /etc/pihole/setupVars.conf\n'
|
2020-03-03 07:30:44 +00:00
|
|
|
for k, v in SETUPVARS.items():
|
2016-10-11 04:14:39 +00:00
|
|
|
setup_var_file += "{}={}\n".format(k, v)
|
|
|
|
setup_var_file += "EOF\n"
|
|
|
|
Pihole.run(setup_var_file)
|
|
|
|
|
|
|
|
script = dedent('''\
|
2016-11-03 05:02:28 +00:00
|
|
|
set -e
|
2016-10-11 04:14:39 +00:00
|
|
|
printSetupVars() {
|
|
|
|
# Currently debug test function only
|
|
|
|
echo "Outputting sourced variables"
|
2016-11-03 05:02:28 +00:00
|
|
|
echo "PIHOLE_INTERFACE=${PIHOLE_INTERFACE}"
|
|
|
|
echo "PIHOLE_DNS_1=${PIHOLE_DNS_1}"
|
|
|
|
echo "PIHOLE_DNS_2=${PIHOLE_DNS_2}"
|
2016-10-11 04:14:39 +00:00
|
|
|
}
|
|
|
|
update_dialogs() {
|
|
|
|
. /etc/pihole/setupVars.conf
|
|
|
|
}
|
|
|
|
update_dialogs
|
|
|
|
printSetupVars
|
|
|
|
''')
|
|
|
|
|
|
|
|
output = run_script(Pihole, script).stdout
|
|
|
|
|
2020-03-03 07:30:44 +00:00
|
|
|
for k, v in SETUPVARS.items():
|
2016-10-11 04:14:39 +00:00
|
|
|
assert "{}={}".format(k, v) in output
|
|
|
|
|
2018-07-02 20:54:19 +00:00
|
|
|
|
2016-10-11 04:14:39 +00:00
|
|
|
def test_setupVars_saved_to_file(Pihole):
|
2018-07-03 06:05:24 +00:00
|
|
|
'''
|
|
|
|
confirm saved settings are written to a file for future updates to re-use
|
|
|
|
'''
|
|
|
|
# dedent works better with this and padding matching script below
|
|
|
|
set_setup_vars = '\n'
|
2020-03-03 07:30:44 +00:00
|
|
|
for k, v in SETUPVARS.items():
|
2016-10-11 04:14:39 +00:00
|
|
|
set_setup_vars += " {}={}\n".format(k, v)
|
|
|
|
Pihole.run(set_setup_vars).stdout
|
|
|
|
|
|
|
|
script = dedent('''\
|
2016-11-03 05:02:28 +00:00
|
|
|
set -e
|
2016-10-11 04:14:39 +00:00
|
|
|
echo start
|
|
|
|
TERM=xterm
|
|
|
|
source /opt/pihole/basic-install.sh
|
|
|
|
{}
|
2017-07-26 16:15:23 +00:00
|
|
|
mkdir -p /etc/dnsmasq.d
|
|
|
|
version_check_dnsmasq
|
2018-08-20 23:33:15 +00:00
|
|
|
echo "" > /etc/pihole/pihole-FTL.conf
|
2016-10-11 04:14:39 +00:00
|
|
|
finalExports
|
|
|
|
cat /etc/pihole/setupVars.conf
|
|
|
|
'''.format(set_setup_vars))
|
|
|
|
|
|
|
|
output = run_script(Pihole, script).stdout
|
|
|
|
|
2020-03-03 07:30:44 +00:00
|
|
|
for k, v in SETUPVARS.items():
|
2016-10-11 04:14:39 +00:00
|
|
|
assert "{}={}".format(k, v) in output
|
|
|
|
|
2018-07-02 20:54:19 +00:00
|
|
|
|
2019-10-14 18:26:39 +00:00
|
|
|
def test_selinux_not_detected(Pihole):
|
2018-07-03 06:05:24 +00:00
|
|
|
'''
|
2019-10-14 18:26:39 +00:00
|
|
|
confirms installer continues when SELinux configuration file does not exist
|
2018-07-03 06:05:24 +00:00
|
|
|
'''
|
2018-06-26 06:09:30 +00:00
|
|
|
check_selinux = Pihole.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
|
|
|
|
''')
|
2019-10-14 18:26:39 +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
|
|
|
|
2017-01-28 04:24:20 +00:00
|
|
|
def test_installPiholeWeb_fresh_install_no_errors(Pihole):
|
2018-07-03 06:05:24 +00:00
|
|
|
'''
|
|
|
|
confirms all web page assets from Core repo are installed on a fresh build
|
|
|
|
'''
|
2017-01-28 04:24:20 +00:00
|
|
|
installWeb = Pihole.run('''
|
|
|
|
source /opt/pihole/basic-install.sh
|
|
|
|
installPiholeWeb
|
|
|
|
''')
|
2018-07-03 06:05:24 +00:00
|
|
|
expected_stdout = info_box + ' Installing blocking page...'
|
|
|
|
assert expected_stdout in installWeb.stdout
|
|
|
|
expected_stdout = tick_box + (' Creating directory for blocking page, '
|
|
|
|
'and copying files')
|
|
|
|
assert expected_stdout in installWeb.stdout
|
2019-09-17 20:16:49 +00:00
|
|
|
expected_stdout = info_box + ' Backing up index.lighttpd.html'
|
2018-07-03 06:05:24 +00:00
|
|
|
assert expected_stdout in installWeb.stdout
|
|
|
|
expected_stdout = ('No default index.lighttpd.html file found... '
|
|
|
|
'not backing up')
|
|
|
|
assert expected_stdout in installWeb.stdout
|
|
|
|
expected_stdout = tick_box + ' Installing sudoer file'
|
|
|
|
assert expected_stdout in installWeb.stdout
|
2017-01-28 04:24:20 +00:00
|
|
|
web_directory = Pihole.run('ls -r /var/www/html/pihole').stdout
|
2017-01-28 04:28:03 +00:00
|
|
|
assert 'index.php' in web_directory
|
|
|
|
assert 'blockingpage.css' in web_directory
|
|
|
|
|
2018-07-02 20:54:19 +00:00
|
|
|
|
2017-01-28 23:44:31 +00:00
|
|
|
def test_update_package_cache_success_no_errors(Pihole):
|
2018-07-03 06:05:24 +00:00
|
|
|
'''
|
|
|
|
confirms package cache was updated without any errors
|
|
|
|
'''
|
2017-01-28 23:44:31 +00:00
|
|
|
updateCache = Pihole.run('''
|
|
|
|
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
|
|
|
|
''')
|
2018-07-03 06:05:24 +00:00
|
|
|
expected_stdout = tick_box + ' Update local cache of available packages'
|
|
|
|
assert expected_stdout in updateCache.stdout
|
2018-07-12 05:03: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
|
|
|
|
2017-01-28 23:49:28 +00:00
|
|
|
def test_update_package_cache_failure_no_errors(Pihole):
|
2018-07-03 06:05:24 +00:00
|
|
|
'''
|
|
|
|
confirms package cache was not updated
|
|
|
|
'''
|
2018-07-02 21:25:51 +00:00
|
|
|
mock_command('apt-get', {'update': ('', '1')}, Pihole)
|
2017-01-28 23:49:28 +00:00
|
|
|
updateCache = Pihole.run('''
|
|
|
|
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
|
|
|
|
''')
|
2018-07-03 06:05:24 +00:00
|
|
|
expected_stdout = cross_box + ' Update local cache of available packages'
|
|
|
|
assert expected_stdout in updateCache.stdout
|
2017-06-21 11:49:05 +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
|
|
|
|
2017-02-20 12:44:31 +00:00
|
|
|
def test_FTL_detect_aarch64_no_errors(Pihole):
|
2018-07-03 06:05:24 +00:00
|
|
|
'''
|
|
|
|
confirms only aarch64 package is downloaded for FTL engine
|
|
|
|
'''
|
2017-02-20 05:38:02 +00:00
|
|
|
# mock uname to return aarch64 platform
|
2018-07-02 21:25:51 +00:00
|
|
|
mock_command('uname', {'-m': ('aarch64', '0')}, Pihole)
|
2017-02-20 12:44:31 +00:00
|
|
|
# mock ldd to respond with aarch64 shared library
|
2018-07-03 06:05:24 +00:00
|
|
|
mock_command(
|
|
|
|
'ldd',
|
|
|
|
{
|
|
|
|
'/bin/ls': (
|
|
|
|
'/lib/ld-linux-aarch64.so.1',
|
|
|
|
'0'
|
|
|
|
)
|
|
|
|
},
|
|
|
|
Pihole
|
|
|
|
)
|
2017-02-20 05:38:02 +00:00
|
|
|
detectPlatform = Pihole.run('''
|
|
|
|
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}"
|
2017-02-20 05:38:02 +00:00
|
|
|
''')
|
2017-07-12 21:52:03 +00:00
|
|
|
expected_stdout = info_box + ' FTL Checks...'
|
2017-06-21 11:49:05 +00:00
|
|
|
assert expected_stdout in detectPlatform.stdout
|
2020-10-13 13:18:14 +00:00
|
|
|
expected_stdout = tick_box + ' Detected AArch64 (64 Bit ARM) processor'
|
|
|
|
assert expected_stdout in detectPlatform.stdout
|
|
|
|
expected_stdout = tick_box + ' Downloading and Installing FTL'
|
|
|
|
assert expected_stdout in detectPlatform.stdout
|
|
|
|
|
|
|
|
|
|
|
|
def test_FTL_detect_armv4t_no_errors(Pihole):
|
|
|
|
'''
|
|
|
|
confirms only armv4t package is downloaded for FTL engine
|
|
|
|
'''
|
|
|
|
# mock uname to return armv4t platform
|
|
|
|
mock_command('uname', {'-m': ('armv4t', '0')}, Pihole)
|
|
|
|
# mock ldd to respond with ld-linux shared library
|
|
|
|
mock_command('ldd', {'/bin/ls': ('/lib/ld-linux.so.3', '0')}, Pihole)
|
|
|
|
detectPlatform = Pihole.run('''
|
|
|
|
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}"
|
|
|
|
''')
|
|
|
|
expected_stdout = info_box + ' FTL Checks...'
|
|
|
|
assert expected_stdout in detectPlatform.stdout
|
|
|
|
expected_stdout = tick_box + (' Detected ARMv4 processor')
|
|
|
|
assert expected_stdout in detectPlatform.stdout
|
|
|
|
expected_stdout = tick_box + ' Downloading and Installing FTL'
|
|
|
|
assert expected_stdout in detectPlatform.stdout
|
|
|
|
|
|
|
|
|
|
|
|
def test_FTL_detect_armv5te_no_errors(Pihole):
|
|
|
|
'''
|
|
|
|
confirms only armv5te package is downloaded for FTL engine
|
|
|
|
'''
|
|
|
|
# mock uname to return armv5te platform
|
|
|
|
mock_command('uname', {'-m': ('armv5te', '0')}, Pihole)
|
|
|
|
# mock ldd to respond with ld-linux shared library
|
|
|
|
mock_command('ldd', {'/bin/ls': ('/lib/ld-linux.so.3', '0')}, Pihole)
|
|
|
|
detectPlatform = Pihole.run('''
|
|
|
|
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}"
|
|
|
|
''')
|
|
|
|
expected_stdout = info_box + ' FTL Checks...'
|
|
|
|
assert expected_stdout in detectPlatform.stdout
|
|
|
|
expected_stdout = tick_box + (' Detected ARMv5 (or newer) processor')
|
2017-06-21 11:49:05 +00:00
|
|
|
assert expected_stdout in detectPlatform.stdout
|
2017-07-12 21:52:03 +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
|
|
|
|
2017-02-20 12:44:31 +00:00
|
|
|
def test_FTL_detect_armv6l_no_errors(Pihole):
|
2018-07-03 06:05:24 +00:00
|
|
|
'''
|
|
|
|
confirms only armv6l package is downloaded for FTL engine
|
|
|
|
'''
|
2017-02-20 12:44:31 +00:00
|
|
|
# mock uname to return armv6l platform
|
2018-07-02 21:25:51 +00:00
|
|
|
mock_command('uname', {'-m': ('armv6l', '0')}, Pihole)
|
2020-10-13 13:18:14 +00:00
|
|
|
# mock ldd to respond with ld-linux-armhf shared library
|
2018-07-02 21:25:51 +00:00
|
|
|
mock_command('ldd', {'/bin/ls': ('/lib/ld-linux-armhf.so.3', '0')}, Pihole)
|
2017-02-20 12:44:31 +00:00
|
|
|
detectPlatform = Pihole.run('''
|
|
|
|
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}"
|
2017-02-20 12:44:31 +00:00
|
|
|
''')
|
2017-07-12 21:52:03 +00:00
|
|
|
expected_stdout = info_box + ' FTL Checks...'
|
2017-06-21 11:49:05 +00:00
|
|
|
assert expected_stdout in detectPlatform.stdout
|
2020-10-13 13:18:14 +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
|
2017-07-12 21:52:03 +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
|
|
|
|
2017-02-20 12:44:31 +00:00
|
|
|
def test_FTL_detect_armv7l_no_errors(Pihole):
|
2018-07-03 06:05:24 +00:00
|
|
|
'''
|
|
|
|
confirms only armv7l package is downloaded for FTL engine
|
|
|
|
'''
|
2017-02-20 12:44:31 +00:00
|
|
|
# mock uname to return armv7l platform
|
2018-07-02 21:25:51 +00:00
|
|
|
mock_command('uname', {'-m': ('armv7l', '0')}, Pihole)
|
2020-10-13 13:18:14 +00:00
|
|
|
# mock ldd to respond with ld-linux-armhf shared library
|
|
|
|
mock_command('ldd', {'/bin/ls': ('/lib/ld-linux-armhf.so.3', '0')}, Pihole)
|
|
|
|
detectPlatform = Pihole.run('''
|
|
|
|
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}"
|
|
|
|
''')
|
|
|
|
expected_stdout = info_box + ' FTL Checks...'
|
|
|
|
assert expected_stdout in detectPlatform.stdout
|
|
|
|
expected_stdout = tick_box + (' Detected ARMv7 processor '
|
|
|
|
'(with hard-float support)')
|
|
|
|
assert expected_stdout in detectPlatform.stdout
|
|
|
|
expected_stdout = tick_box + ' Downloading and Installing FTL'
|
|
|
|
assert expected_stdout in detectPlatform.stdout
|
|
|
|
|
|
|
|
|
|
|
|
def test_FTL_detect_armv8a_no_errors(Pihole):
|
|
|
|
'''
|
|
|
|
confirms only armv8a package is downloaded for FTL engine
|
|
|
|
'''
|
|
|
|
# mock uname to return armv8a platform
|
|
|
|
mock_command('uname', {'-m': ('armv8a', '0')}, Pihole)
|
|
|
|
# mock ldd to respond with ld-linux-armhf shared library
|
2018-07-02 21:25:51 +00:00
|
|
|
mock_command('ldd', {'/bin/ls': ('/lib/ld-linux-armhf.so.3', '0')}, Pihole)
|
2017-02-20 12:44:31 +00:00
|
|
|
detectPlatform = Pihole.run('''
|
|
|
|
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}"
|
2017-02-20 12:44:31 +00:00
|
|
|
''')
|
2017-07-12 21:52:03 +00:00
|
|
|
expected_stdout = info_box + ' FTL Checks...'
|
2017-06-21 11:49:05 +00:00
|
|
|
assert expected_stdout in detectPlatform.stdout
|
2020-10-13 13:18:14 +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
|
2017-07-12 21:52:03 +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
|
|
|
|
2017-02-20 12:44:31 +00:00
|
|
|
def test_FTL_detect_x86_64_no_errors(Pihole):
|
2018-07-03 06:05:24 +00:00
|
|
|
'''
|
|
|
|
confirms only x86_64 package is downloaded for FTL engine
|
|
|
|
'''
|
2017-02-20 12:44:31 +00:00
|
|
|
detectPlatform = Pihole.run('''
|
|
|
|
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}"
|
2017-02-20 12:44:31 +00:00
|
|
|
''')
|
2017-07-12 21:52:03 +00:00
|
|
|
expected_stdout = info_box + ' FTL Checks...'
|
2017-06-21 11:49:05 +00:00
|
|
|
assert expected_stdout in detectPlatform.stdout
|
2020-10-13 13:18:14 +00:00
|
|
|
expected_stdout = tick_box + ' Detected x86_64 processor'
|
2017-06-21 11:49:05 +00:00
|
|
|
assert expected_stdout in detectPlatform.stdout
|
2017-07-12 21:52:03 +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
|
|
|
|
2017-02-20 12:44:31 +00:00
|
|
|
def test_FTL_detect_unknown_no_errors(Pihole):
|
|
|
|
''' confirms only generic package is downloaded for FTL engine '''
|
|
|
|
# mock uname to return generic platform
|
2018-07-02 21:25:51 +00:00
|
|
|
mock_command('uname', {'-m': ('mips', '0')}, Pihole)
|
2017-02-20 05:38:02 +00:00
|
|
|
detectPlatform = Pihole.run('''
|
|
|
|
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}"
|
2017-02-20 05:38:02 +00:00
|
|
|
''')
|
2020-10-13 13:18:14 +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
|
|
|
|
2017-02-20 17:36:24 +00:00
|
|
|
def test_FTL_download_aarch64_no_errors(Pihole):
|
2018-07-03 06:05:24 +00:00
|
|
|
'''
|
|
|
|
confirms only aarch64 package is downloaded for FTL engine
|
|
|
|
'''
|
2019-07-06 17:06:08 +00:00
|
|
|
# mock whiptail answers and ensure installer dependencies
|
|
|
|
mock_command('whiptail', {'*': ('', '0')}, Pihole)
|
|
|
|
Pihole.run('''
|
|
|
|
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[@]}
|
|
|
|
''')
|
2017-02-20 17:36:24 +00:00
|
|
|
download_binary = Pihole.run('''
|
|
|
|
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"
|
2017-02-20 17:36:24 +00:00
|
|
|
''')
|
2017-07-12 21:52:03 +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
|
2018-07-12 05:03: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
|
|
|
|
2017-02-21 01:15:04 +00:00
|
|
|
def test_FTL_binary_installed_and_responsive_no_errors(Pihole):
|
2018-07-03 06:05:24 +00:00
|
|
|
'''
|
|
|
|
confirms FTL binary is copied and functional in installed location
|
|
|
|
'''
|
2017-02-21 01:15:04 +00:00
|
|
|
installed_binary = Pihole.run('''
|
|
|
|
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}"
|
2017-02-21 01:15:04 +00:00
|
|
|
pihole-FTL version
|
|
|
|
''')
|
|
|
|
expected_stdout = 'v'
|
|
|
|
assert expected_stdout in installed_binary.stdout
|
|
|
|
|
2018-07-02 20:54:19 +00:00
|
|
|
|
2017-02-21 10:25:18 +00:00
|
|
|
# def test_FTL_support_files_installed(Pihole):
|
2018-07-03 06:05:24 +00:00
|
|
|
# '''
|
|
|
|
# confirms FTL support files are installed
|
|
|
|
# '''
|
2017-02-21 10:25:18 +00:00
|
|
|
# support_files = Pihole.run('''
|
|
|
|
# source /opt/pihole/basic-install.sh
|
|
|
|
# FTLdetect
|
|
|
|
# stat -c '%a %n' /var/log/pihole-FTL.log
|
|
|
|
# stat -c '%a %n' /run/pihole-FTL.port
|
|
|
|
# stat -c '%a %n' /run/pihole-FTL.pid
|
|
|
|
# ls -lac /run
|
|
|
|
# ''')
|
|
|
|
# assert '644 /run/pihole-FTL.port' in support_files.stdout
|
|
|
|
# assert '644 /run/pihole-FTL.pid' in support_files.stdout
|
|
|
|
# assert '644 /var/log/pihole-FTL.log' in support_files.stdout
|
2017-02-21 01:28:38 +00:00
|
|
|
|
2018-07-02 20:54:19 +00:00
|
|
|
|
2017-06-02 21:01:48 +00:00
|
|
|
def test_IPv6_only_link_local(Pihole):
|
2018-07-03 06:05:24 +00:00
|
|
|
'''
|
|
|
|
confirms IPv6 blocking is disabled for Link-local address
|
|
|
|
'''
|
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(
|
|
|
|
'ip',
|
|
|
|
{
|
|
|
|
'-6 address': (
|
|
|
|
'inet6 fe80::d210:52fa:fe00:7ad7/64 scope link',
|
|
|
|
'0'
|
|
|
|
)
|
|
|
|
},
|
|
|
|
Pihole
|
|
|
|
)
|
2017-06-02 21:01:48 +00:00
|
|
|
detectPlatform = Pihole.run('''
|
|
|
|
source /opt/pihole/basic-install.sh
|
2021-10-02 21:43:08 +00:00
|
|
|
find_IPv6_information
|
2017-06-02 21:01:48 +00:00
|
|
|
''')
|
2021-10-02 21:43:08 +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
|
|
|
|
2017-06-02 21:01:48 +00:00
|
|
|
def test_IPv6_only_ULA(Pihole):
|
2018-07-03 06:05:24 +00:00
|
|
|
'''
|
|
|
|
confirms IPv6 blocking is enabled for ULA addresses
|
|
|
|
'''
|
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(
|
|
|
|
'ip',
|
|
|
|
{
|
|
|
|
'-6 address': (
|
|
|
|
'inet6 fda2:2001:5555:0:d210:52fa:fe00:7ad7/64 scope global',
|
|
|
|
'0'
|
|
|
|
)
|
|
|
|
},
|
|
|
|
Pihole
|
|
|
|
)
|
2017-06-02 21:01:48 +00:00
|
|
|
detectPlatform = Pihole.run('''
|
|
|
|
source /opt/pihole/basic-install.sh
|
2021-10-02 21:47:13 +00:00
|
|
|
find_IPv6_information
|
2017-06-02 21:01:48 +00:00
|
|
|
''')
|
2021-10-02 21:47:13 +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
|
|
|
|
2017-06-02 21:01:48 +00:00
|
|
|
def test_IPv6_only_GUA(Pihole):
|
2018-07-03 06:05:24 +00:00
|
|
|
'''
|
|
|
|
confirms IPv6 blocking is enabled for GUA addresses
|
|
|
|
'''
|
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(
|
|
|
|
'ip',
|
|
|
|
{
|
|
|
|
'-6 address': (
|
|
|
|
'inet6 2003:12:1e43:301:d210:52fa:fe00:7ad7/64 scope global',
|
|
|
|
'0'
|
|
|
|
)
|
|
|
|
},
|
|
|
|
Pihole
|
|
|
|
)
|
2017-06-02 21:01:48 +00:00
|
|
|
detectPlatform = Pihole.run('''
|
|
|
|
source /opt/pihole/basic-install.sh
|
2021-10-02 21:43:08 +00:00
|
|
|
find_IPv6_information
|
2017-06-02 21:01:48 +00:00
|
|
|
''')
|
2021-10-02 21:43:08 +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
|
|
|
|
2017-06-02 21:01:48 +00:00
|
|
|
def test_IPv6_GUA_ULA_test(Pihole):
|
2018-07-03 06:05:24 +00:00
|
|
|
'''
|
|
|
|
confirms IPv6 blocking is enabled for GUA and ULA addresses
|
|
|
|
'''
|
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(
|
|
|
|
'ip',
|
|
|
|
{
|
|
|
|
'-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'
|
|
|
|
)
|
|
|
|
},
|
|
|
|
Pihole
|
|
|
|
)
|
2017-06-02 21:01:48 +00:00
|
|
|
detectPlatform = Pihole.run('''
|
|
|
|
source /opt/pihole/basic-install.sh
|
2021-10-02 21:47:13 +00:00
|
|
|
find_IPv6_information
|
2017-06-02 21:01:48 +00:00
|
|
|
''')
|
2021-10-02 21:47:13 +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
|
|
|
|
2017-06-02 21:01:48 +00:00
|
|
|
def test_IPv6_ULA_GUA_test(Pihole):
|
2018-07-03 06:05:24 +00:00
|
|
|
'''
|
|
|
|
confirms IPv6 blocking is enabled for GUA and ULA addresses
|
|
|
|
'''
|
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(
|
|
|
|
'ip',
|
|
|
|
{
|
|
|
|
'-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'
|
|
|
|
)
|
|
|
|
},
|
|
|
|
Pihole
|
|
|
|
)
|
2017-06-02 21:01:48 +00:00
|
|
|
detectPlatform = Pihole.run('''
|
|
|
|
source /opt/pihole/basic-install.sh
|
2021-10-02 21:47:13 +00:00
|
|
|
find_IPv6_information
|
2017-06-02 21:01:48 +00:00
|
|
|
''')
|
2021-10-02 21:47:13 +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-03-17 10:09:13 +00:00
|
|
|
def test_validate_ip(Pihole):
|
|
|
|
'''
|
|
|
|
Tests valid_ip for various IP addresses
|
|
|
|
'''
|
|
|
|
|
|
|
|
def test_address(addr, success=True):
|
|
|
|
output = Pihole.run('''
|
|
|
|
source /opt/pihole/basic-install.sh
|
|
|
|
valid_ip "{addr}"
|
|
|
|
'''.format(addr=addr))
|
|
|
|
|
|
|
|
assert output.rc == 0 if success else 1
|
|
|
|
|
|
|
|
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)
|
2021-04-14 20:50:04 +00:00
|
|
|
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)
|
2021-03-18 01:09:03 +00:00
|
|
|
test_address('00.0.0.0', False)
|
|
|
|
test_address('010.0.0.0', False)
|
|
|
|
test_address('001.0.0.0', False)
|
2021-04-14 20:50:04 +00:00
|
|
|
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
|
|
|
|
2020-10-23 22:05:41 +00:00
|
|
|
def test_os_check_fails(Pihole):
|
|
|
|
''' Confirms install fails on unsupported OS '''
|
|
|
|
Pihole.run('''
|
|
|
|
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
|
|
|
|
ID=UnsupportedOS
|
|
|
|
VERSION_ID="2"
|
|
|
|
EOT
|
|
|
|
''')
|
|
|
|
detectOS = Pihole.run('''t
|
|
|
|
source /opt/pihole/basic-install.sh
|
|
|
|
os_check
|
|
|
|
''')
|
|
|
|
expected_stdout = 'Unsupported OS detected: UnsupportedOS'
|
|
|
|
assert expected_stdout in detectOS.stdout
|
|
|
|
|
2020-10-23 22:09:07 +00:00
|
|
|
|
2020-07-29 16:52:53 +00:00
|
|
|
def test_os_check_passes(Pihole):
|
2020-07-28 18:07:17 +00:00
|
|
|
''' Confirms OS meets the requirements '''
|
|
|
|
Pihole.run('''
|
|
|
|
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[@]}
|
|
|
|
''')
|
|
|
|
detectOS = Pihole.run('''
|
|
|
|
source /opt/pihole/basic-install.sh
|
|
|
|
os_check
|
|
|
|
''')
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
def test_package_manager_has_installer_deps(Pihole):
|
|
|
|
''' Confirms OS is able to install the required packages for the installer'''
|
|
|
|
mock_command('whiptail', {'*': ('', '0')}, Pihole)
|
|
|
|
output = Pihole.run('''
|
|
|
|
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[@]}
|
|
|
|
''')
|
|
|
|
|
2021-07-02 23:07:37 +00:00
|
|
|
assert 'No package' not in output.stdout # centos7 still exits 0...
|
2021-07-02 23:00:54 +00:00
|
|
|
assert output.rc == 0
|
|
|
|
|
|
|
|
|
|
|
|
def test_package_manager_has_pihole_deps(Pihole):
|
|
|
|
''' Confirms OS is able to install the required packages for Pi-hole '''
|
|
|
|
mock_command('whiptail', {'*': ('', '0')}, Pihole)
|
|
|
|
output = Pihole.run('''
|
|
|
|
source /opt/pihole/basic-install.sh
|
2021-08-03 20:48:26 +00:00
|
|
|
package_manager_detect
|
2021-09-12 20:40:37 +00:00
|
|
|
select_rpm_php
|
2021-07-02 23:00:54 +00:00
|
|
|
install_dependent_packages ${PIHOLE_DEPS[@]}
|
|
|
|
''')
|
|
|
|
|
2021-07-02 23:07:37 +00:00
|
|
|
assert 'No package' not in output.stdout # centos7 still exits 0...
|
2021-07-02 23:00:54 +00:00
|
|
|
assert output.rc == 0
|
|
|
|
|
|
|
|
|
|
|
|
def test_package_manager_has_web_deps(Pihole):
|
|
|
|
''' Confirms OS is able to install the required packages for web '''
|
|
|
|
mock_command('whiptail', {'*': ('', '0')}, Pihole)
|
|
|
|
output = Pihole.run('''
|
|
|
|
source /opt/pihole/basic-install.sh
|
2021-08-03 20:48:26 +00:00
|
|
|
package_manager_detect
|
2021-09-12 20:40:37 +00:00
|
|
|
select_rpm_php
|
2021-07-02 23:00:54 +00:00
|
|
|
install_dependent_packages ${PIHOLE_WEB_DEPS[@]}
|
|
|
|
''')
|
|
|
|
|
2021-07-02 23:07:37 +00:00
|
|
|
assert 'No package' not in output.stdout # centos7 still exits 0...
|
2021-07-02 23:00:54 +00:00
|
|
|
assert output.rc == 0
|