mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-15 02:42:58 +00:00
python linting: 2 lines prior to defs (E302)
Signed-off-by: bcambl <blayne@blaynecampbell.com>
This commit is contained in:
parent
9d3d33b6a2
commit
4468d81472
4 changed files with 41 additions and 0 deletions
|
@ -5,6 +5,7 @@ check_output = testinfra.get_backend(
|
||||||
"local://"
|
"local://"
|
||||||
).get_module("Command").check_output
|
).get_module("Command").check_output
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def Pihole(Docker):
|
def Pihole(Docker):
|
||||||
''' used to contain some script stubbing, now pretty much an alias.
|
''' used to contain some script stubbing, now pretty much an alias.
|
||||||
|
@ -25,6 +26,7 @@ def Pihole(Docker):
|
||||||
Docker.run = funcType(run_bash, Docker, testinfra.backend.docker.DockerBackend)
|
Docker.run = funcType(run_bash, Docker, testinfra.backend.docker.DockerBackend)
|
||||||
return Docker
|
return Docker
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def Docker(request, args, image, cmd):
|
def Docker(request, args, image, cmd):
|
||||||
''' combine our fixtures into a docker run command and setup finalizer to cleanup '''
|
''' combine our fixtures into a docker run command and setup finalizer to cleanup '''
|
||||||
|
@ -40,21 +42,25 @@ def Docker(request, args, image, cmd):
|
||||||
docker_container.id = docker_id
|
docker_container.id = docker_id
|
||||||
return docker_container
|
return docker_container
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def args(request):
|
def args(request):
|
||||||
''' -t became required when tput began being used '''
|
''' -t became required when tput began being used '''
|
||||||
return '-t -d'
|
return '-t -d'
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(params=['debian', 'centos'])
|
@pytest.fixture(params=['debian', 'centos'])
|
||||||
def tag(request):
|
def tag(request):
|
||||||
''' consumed by image to make the test matrix '''
|
''' consumed by image to make the test matrix '''
|
||||||
return request.param
|
return request.param
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def image(request, tag):
|
def image(request, tag):
|
||||||
''' built by test_000_build_containers.py '''
|
''' built by test_000_build_containers.py '''
|
||||||
return 'pytest_pihole:{}'.format(tag)
|
return 'pytest_pihole:{}'.format(tag)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def cmd(request):
|
def cmd(request):
|
||||||
''' default to doing nothing by tailing null, but don't exit '''
|
''' default to doing nothing by tailing null, but don't exit '''
|
||||||
|
|
|
@ -6,6 +6,7 @@ run_local = testinfra.get_backend(
|
||||||
"local://"
|
"local://"
|
||||||
).get_module("Command").run
|
).get_module("Command").run
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("image,tag", [
|
@pytest.mark.parametrize("image,tag", [
|
||||||
( 'test/debian.Dockerfile', 'pytest_pihole:debian' ),
|
( 'test/debian.Dockerfile', 'pytest_pihole:debian' ),
|
||||||
( 'test/centos.Dockerfile', 'pytest_pihole:centos' ),
|
( 'test/centos.Dockerfile', 'pytest_pihole:centos' ),
|
||||||
|
|
|
@ -13,6 +13,7 @@ tick_box="[\x1b[1;32m\xe2\x9c\x93\x1b[0m]".decode("utf-8")
|
||||||
cross_box="[\x1b[1;31m\xe2\x9c\x97\x1b[0m]".decode("utf-8")
|
cross_box="[\x1b[1;31m\xe2\x9c\x97\x1b[0m]".decode("utf-8")
|
||||||
info_box="[i]".decode("utf-8")
|
info_box="[i]".decode("utf-8")
|
||||||
|
|
||||||
|
|
||||||
def test_setupVars_are_sourced_to_global_scope(Pihole):
|
def test_setupVars_are_sourced_to_global_scope(Pihole):
|
||||||
''' currently update_dialogs sources setupVars with a dot,
|
''' currently update_dialogs sources setupVars with a dot,
|
||||||
then various other functions use the variables.
|
then various other functions use the variables.
|
||||||
|
@ -46,6 +47,7 @@ def test_setupVars_are_sourced_to_global_scope(Pihole):
|
||||||
for k,v in SETUPVARS.iteritems():
|
for k,v in SETUPVARS.iteritems():
|
||||||
assert "{}={}".format(k, v) in output
|
assert "{}={}".format(k, v) in output
|
||||||
|
|
||||||
|
|
||||||
def test_setupVars_saved_to_file(Pihole):
|
def test_setupVars_saved_to_file(Pihole):
|
||||||
''' confirm saved settings are written to a file for future updates to re-use '''
|
''' confirm saved settings are written to a file for future updates to re-use '''
|
||||||
set_setup_vars = '\n' # dedent works better with this and padding matching script below
|
set_setup_vars = '\n' # dedent works better with this and padding matching script below
|
||||||
|
@ -70,6 +72,7 @@ def test_setupVars_saved_to_file(Pihole):
|
||||||
for k,v in SETUPVARS.iteritems():
|
for k,v in SETUPVARS.iteritems():
|
||||||
assert "{}={}".format(k, v) in output
|
assert "{}={}".format(k, v) in output
|
||||||
|
|
||||||
|
|
||||||
def test_configureFirewall_firewalld_running_no_errors(Pihole):
|
def test_configureFirewall_firewalld_running_no_errors(Pihole):
|
||||||
''' confirms firewalld rules are applied when firewallD is running '''
|
''' confirms firewalld rules are applied when firewallD is running '''
|
||||||
# firewallD returns 'running' as status
|
# firewallD returns 'running' as status
|
||||||
|
@ -87,6 +90,7 @@ def test_configureFirewall_firewalld_running_no_errors(Pihole):
|
||||||
assert 'firewall-cmd --permanent --add-service=http --add-service=dns' in firewall_calls
|
assert 'firewall-cmd --permanent --add-service=http --add-service=dns' in firewall_calls
|
||||||
assert 'firewall-cmd --reload' in firewall_calls
|
assert 'firewall-cmd --reload' in firewall_calls
|
||||||
|
|
||||||
|
|
||||||
def test_configureFirewall_firewalld_disabled_no_errors(Pihole):
|
def test_configureFirewall_firewalld_disabled_no_errors(Pihole):
|
||||||
''' confirms firewalld rules are not applied when firewallD is not running '''
|
''' confirms firewalld rules are not applied when firewallD is not running '''
|
||||||
# firewallD returns non-running status
|
# firewallD returns non-running status
|
||||||
|
@ -98,6 +102,7 @@ def test_configureFirewall_firewalld_disabled_no_errors(Pihole):
|
||||||
expected_stdout = 'No active firewall detected.. skipping firewall configuration'
|
expected_stdout = 'No active firewall detected.. skipping firewall configuration'
|
||||||
assert expected_stdout in configureFirewall.stdout
|
assert expected_stdout in configureFirewall.stdout
|
||||||
|
|
||||||
|
|
||||||
def test_configureFirewall_firewalld_enabled_declined_no_errors(Pihole):
|
def test_configureFirewall_firewalld_enabled_declined_no_errors(Pihole):
|
||||||
''' confirms firewalld rules are not applied when firewallD is running, user declines ruleset '''
|
''' confirms firewalld rules are not applied when firewallD is running, user declines ruleset '''
|
||||||
# firewallD returns running status
|
# firewallD returns running status
|
||||||
|
@ -111,6 +116,7 @@ def test_configureFirewall_firewalld_enabled_declined_no_errors(Pihole):
|
||||||
expected_stdout = 'Not installing firewall rulesets.'
|
expected_stdout = 'Not installing firewall rulesets.'
|
||||||
assert expected_stdout in configureFirewall.stdout
|
assert expected_stdout in configureFirewall.stdout
|
||||||
|
|
||||||
|
|
||||||
def test_configureFirewall_no_firewall(Pihole):
|
def test_configureFirewall_no_firewall(Pihole):
|
||||||
''' confirms firewall skipped no daemon is running '''
|
''' confirms firewall skipped no daemon is running '''
|
||||||
configureFirewall = Pihole.run('''
|
configureFirewall = Pihole.run('''
|
||||||
|
@ -120,6 +126,7 @@ def test_configureFirewall_no_firewall(Pihole):
|
||||||
expected_stdout = 'No active firewall detected'
|
expected_stdout = 'No active firewall detected'
|
||||||
assert expected_stdout in configureFirewall.stdout
|
assert expected_stdout in configureFirewall.stdout
|
||||||
|
|
||||||
|
|
||||||
def test_configureFirewall_IPTables_enabled_declined_no_errors(Pihole):
|
def test_configureFirewall_IPTables_enabled_declined_no_errors(Pihole):
|
||||||
''' confirms IPTables rules are not applied when IPTables is running, user declines ruleset '''
|
''' confirms IPTables rules are not applied when IPTables is running, user declines ruleset '''
|
||||||
# iptables command exists
|
# iptables command exists
|
||||||
|
@ -135,6 +142,7 @@ def test_configureFirewall_IPTables_enabled_declined_no_errors(Pihole):
|
||||||
expected_stdout = 'Not installing firewall rulesets.'
|
expected_stdout = 'Not installing firewall rulesets.'
|
||||||
assert expected_stdout in configureFirewall.stdout
|
assert expected_stdout in configureFirewall.stdout
|
||||||
|
|
||||||
|
|
||||||
def test_configureFirewall_IPTables_enabled_rules_exist_no_errors(Pihole):
|
def test_configureFirewall_IPTables_enabled_rules_exist_no_errors(Pihole):
|
||||||
''' confirms IPTables rules are not applied when IPTables is running and rules exist '''
|
''' confirms IPTables rules are not applied when IPTables is running and rules exist '''
|
||||||
# iptables command exists and returns 0 on calls (should return 0 on iptables -C)
|
# iptables command exists and returns 0 on calls (should return 0 on iptables -C)
|
||||||
|
@ -154,6 +162,7 @@ def test_configureFirewall_IPTables_enabled_rules_exist_no_errors(Pihole):
|
||||||
assert 'iptables -I INPUT 1 -p tcp -m tcp --dport 53 -j ACCEPT' not in firewall_calls
|
assert 'iptables -I INPUT 1 -p tcp -m tcp --dport 53 -j ACCEPT' not in firewall_calls
|
||||||
assert 'iptables -I INPUT 1 -p udp -m udp --dport 53 -j ACCEPT' not in firewall_calls
|
assert 'iptables -I INPUT 1 -p udp -m udp --dport 53 -j ACCEPT' not in firewall_calls
|
||||||
|
|
||||||
|
|
||||||
def test_configureFirewall_IPTables_enabled_not_exist_no_errors(Pihole):
|
def test_configureFirewall_IPTables_enabled_not_exist_no_errors(Pihole):
|
||||||
''' confirms IPTables rules are applied when IPTables is running and rules do not exist '''
|
''' confirms IPTables rules are applied when IPTables is running and rules do not exist '''
|
||||||
# iptables command and returns 0 on calls (should return 1 on iptables -C)
|
# iptables command and returns 0 on calls (should return 1 on iptables -C)
|
||||||
|
@ -173,6 +182,7 @@ def test_configureFirewall_IPTables_enabled_not_exist_no_errors(Pihole):
|
||||||
assert 'iptables -I INPUT 1 -p tcp -m tcp --dport 53 -j ACCEPT' in firewall_calls
|
assert 'iptables -I INPUT 1 -p tcp -m tcp --dport 53 -j ACCEPT' in firewall_calls
|
||||||
assert 'iptables -I INPUT 1 -p udp -m udp --dport 53 -j ACCEPT' in firewall_calls
|
assert 'iptables -I INPUT 1 -p udp -m udp --dport 53 -j ACCEPT' in firewall_calls
|
||||||
|
|
||||||
|
|
||||||
def test_selinux_enforcing_default_exit(Pihole):
|
def test_selinux_enforcing_default_exit(Pihole):
|
||||||
''' confirms installer prompts to exit when SELinux is Enforcing by default '''
|
''' confirms installer prompts to exit when SELinux is Enforcing by default '''
|
||||||
# getenforce returns the running state of SELinux
|
# getenforce returns the running state of SELinux
|
||||||
|
@ -187,6 +197,7 @@ def test_selinux_enforcing_default_exit(Pihole):
|
||||||
assert 'SELinux Enforcing detected, exiting installer' in check_selinux.stdout
|
assert 'SELinux Enforcing detected, exiting installer' in check_selinux.stdout
|
||||||
assert check_selinux.rc == 1
|
assert check_selinux.rc == 1
|
||||||
|
|
||||||
|
|
||||||
def test_selinux_enforcing_continue(Pihole):
|
def test_selinux_enforcing_continue(Pihole):
|
||||||
''' confirms installer prompts to continue with custom policy warning '''
|
''' confirms installer prompts to continue with custom policy warning '''
|
||||||
# getenforce returns the running state of SELinux
|
# getenforce returns the running state of SELinux
|
||||||
|
@ -202,6 +213,7 @@ def test_selinux_enforcing_continue(Pihole):
|
||||||
assert info_box + ' Please refer to official SELinux documentation to create a custom policy' in check_selinux.stdout
|
assert info_box + ' Please refer to official SELinux documentation to create a custom policy' in check_selinux.stdout
|
||||||
assert check_selinux.rc == 0
|
assert check_selinux.rc == 0
|
||||||
|
|
||||||
|
|
||||||
def test_selinux_permissive(Pihole):
|
def test_selinux_permissive(Pihole):
|
||||||
''' confirms installer continues when SELinux is Permissive '''
|
''' confirms installer continues when SELinux is Permissive '''
|
||||||
# getenforce returns the running state of SELinux
|
# getenforce returns the running state of SELinux
|
||||||
|
@ -213,6 +225,7 @@ def test_selinux_permissive(Pihole):
|
||||||
assert info_box + ' SELinux mode detected: Permissive' in check_selinux.stdout
|
assert info_box + ' SELinux mode detected: Permissive' in check_selinux.stdout
|
||||||
assert check_selinux.rc == 0
|
assert check_selinux.rc == 0
|
||||||
|
|
||||||
|
|
||||||
def test_selinux_disabled(Pihole):
|
def test_selinux_disabled(Pihole):
|
||||||
''' confirms installer continues when SELinux is Disabled '''
|
''' confirms installer continues when SELinux is Disabled '''
|
||||||
mock_command('getenforce', {'*':('Disabled', '0')}, Pihole)
|
mock_command('getenforce', {'*':('Disabled', '0')}, Pihole)
|
||||||
|
@ -223,6 +236,7 @@ def test_selinux_disabled(Pihole):
|
||||||
assert info_box + ' SELinux mode detected: Disabled' in check_selinux.stdout
|
assert info_box + ' SELinux mode detected: Disabled' in check_selinux.stdout
|
||||||
assert check_selinux.rc == 0
|
assert check_selinux.rc == 0
|
||||||
|
|
||||||
|
|
||||||
def test_installPiholeWeb_fresh_install_no_errors(Pihole):
|
def test_installPiholeWeb_fresh_install_no_errors(Pihole):
|
||||||
''' confirms all web page assets from Core repo are installed on a fresh build '''
|
''' confirms all web page assets from Core repo are installed on a fresh build '''
|
||||||
installWeb = Pihole.run('''
|
installWeb = Pihole.run('''
|
||||||
|
@ -238,6 +252,7 @@ def test_installPiholeWeb_fresh_install_no_errors(Pihole):
|
||||||
assert 'index.php' in web_directory
|
assert 'index.php' in web_directory
|
||||||
assert 'blockingpage.css' in web_directory
|
assert 'blockingpage.css' in web_directory
|
||||||
|
|
||||||
|
|
||||||
def test_update_package_cache_success_no_errors(Pihole):
|
def test_update_package_cache_success_no_errors(Pihole):
|
||||||
''' confirms package cache was updated without any errors'''
|
''' confirms package cache was updated without any errors'''
|
||||||
updateCache = Pihole.run('''
|
updateCache = Pihole.run('''
|
||||||
|
@ -248,6 +263,7 @@ def test_update_package_cache_success_no_errors(Pihole):
|
||||||
assert tick_box + ' Update local cache of available packages' in updateCache.stdout
|
assert tick_box + ' Update local cache of available packages' in updateCache.stdout
|
||||||
assert 'Error: Unable to update package cache.' not in updateCache.stdout
|
assert 'Error: Unable to update package cache.' not in updateCache.stdout
|
||||||
|
|
||||||
|
|
||||||
def test_update_package_cache_failure_no_errors(Pihole):
|
def test_update_package_cache_failure_no_errors(Pihole):
|
||||||
''' confirms package cache was not updated'''
|
''' confirms package cache was not updated'''
|
||||||
mock_command('apt-get', {'update':('', '1')}, Pihole)
|
mock_command('apt-get', {'update':('', '1')}, Pihole)
|
||||||
|
@ -259,6 +275,7 @@ def test_update_package_cache_failure_no_errors(Pihole):
|
||||||
assert cross_box + ' Update local cache of available packages' in updateCache.stdout
|
assert cross_box + ' Update local cache of available packages' in updateCache.stdout
|
||||||
assert 'Error: Unable to update package cache.' in updateCache.stdout
|
assert 'Error: Unable to update package cache.' in updateCache.stdout
|
||||||
|
|
||||||
|
|
||||||
def test_FTL_detect_aarch64_no_errors(Pihole):
|
def test_FTL_detect_aarch64_no_errors(Pihole):
|
||||||
''' confirms only aarch64 package is downloaded for FTL engine '''
|
''' confirms only aarch64 package is downloaded for FTL engine '''
|
||||||
# mock uname to return aarch64 platform
|
# mock uname to return aarch64 platform
|
||||||
|
@ -276,6 +293,7 @@ def test_FTL_detect_aarch64_no_errors(Pihole):
|
||||||
expected_stdout = tick_box + ' Downloading and Installing FTL'
|
expected_stdout = tick_box + ' Downloading and Installing FTL'
|
||||||
assert expected_stdout in detectPlatform.stdout
|
assert expected_stdout in detectPlatform.stdout
|
||||||
|
|
||||||
|
|
||||||
def test_FTL_detect_armv6l_no_errors(Pihole):
|
def test_FTL_detect_armv6l_no_errors(Pihole):
|
||||||
''' confirms only armv6l package is downloaded for FTL engine '''
|
''' confirms only armv6l package is downloaded for FTL engine '''
|
||||||
# mock uname to return armv6l platform
|
# mock uname to return armv6l platform
|
||||||
|
@ -293,6 +311,7 @@ def test_FTL_detect_armv6l_no_errors(Pihole):
|
||||||
expected_stdout = tick_box + ' Downloading and Installing FTL'
|
expected_stdout = tick_box + ' Downloading and Installing FTL'
|
||||||
assert expected_stdout in detectPlatform.stdout
|
assert expected_stdout in detectPlatform.stdout
|
||||||
|
|
||||||
|
|
||||||
def test_FTL_detect_armv7l_no_errors(Pihole):
|
def test_FTL_detect_armv7l_no_errors(Pihole):
|
||||||
''' confirms only armv7l package is downloaded for FTL engine '''
|
''' confirms only armv7l package is downloaded for FTL engine '''
|
||||||
# mock uname to return armv7l platform
|
# mock uname to return armv7l platform
|
||||||
|
@ -310,6 +329,7 @@ def test_FTL_detect_armv7l_no_errors(Pihole):
|
||||||
expected_stdout = tick_box + ' Downloading and Installing FTL'
|
expected_stdout = tick_box + ' Downloading and Installing FTL'
|
||||||
assert expected_stdout in detectPlatform.stdout
|
assert expected_stdout in detectPlatform.stdout
|
||||||
|
|
||||||
|
|
||||||
def test_FTL_detect_x86_64_no_errors(Pihole):
|
def test_FTL_detect_x86_64_no_errors(Pihole):
|
||||||
''' confirms only x86_64 package is downloaded for FTL engine '''
|
''' confirms only x86_64 package is downloaded for FTL engine '''
|
||||||
detectPlatform = Pihole.run('''
|
detectPlatform = Pihole.run('''
|
||||||
|
@ -323,6 +343,7 @@ def test_FTL_detect_x86_64_no_errors(Pihole):
|
||||||
expected_stdout = tick_box + ' Downloading and Installing FTL'
|
expected_stdout = tick_box + ' Downloading and Installing FTL'
|
||||||
assert expected_stdout in detectPlatform.stdout
|
assert expected_stdout in detectPlatform.stdout
|
||||||
|
|
||||||
|
|
||||||
def test_FTL_detect_unknown_no_errors(Pihole):
|
def test_FTL_detect_unknown_no_errors(Pihole):
|
||||||
''' confirms only generic package is downloaded for FTL engine '''
|
''' confirms only generic package is downloaded for FTL engine '''
|
||||||
# mock uname to return generic platform
|
# mock uname to return generic platform
|
||||||
|
@ -334,6 +355,7 @@ def test_FTL_detect_unknown_no_errors(Pihole):
|
||||||
expected_stdout = 'Not able to detect architecture (unknown: mips)'
|
expected_stdout = 'Not able to detect architecture (unknown: mips)'
|
||||||
assert expected_stdout in detectPlatform.stdout
|
assert expected_stdout in detectPlatform.stdout
|
||||||
|
|
||||||
|
|
||||||
def test_FTL_download_aarch64_no_errors(Pihole):
|
def test_FTL_download_aarch64_no_errors(Pihole):
|
||||||
''' confirms only aarch64 package is downloaded for FTL engine '''
|
''' confirms only aarch64 package is downloaded for FTL engine '''
|
||||||
# mock uname to return generic platform
|
# mock uname to return generic platform
|
||||||
|
@ -348,6 +370,7 @@ def test_FTL_download_aarch64_no_errors(Pihole):
|
||||||
error = 'Error: URL not found'
|
error = 'Error: URL not found'
|
||||||
assert error not in download_binary.stdout
|
assert error not in download_binary.stdout
|
||||||
|
|
||||||
|
|
||||||
def test_FTL_download_unknown_fails_no_errors(Pihole):
|
def test_FTL_download_unknown_fails_no_errors(Pihole):
|
||||||
''' confirms unknown binary is not downloaded for FTL engine '''
|
''' confirms unknown binary is not downloaded for FTL engine '''
|
||||||
# mock uname to return generic platform
|
# mock uname to return generic platform
|
||||||
|
@ -360,6 +383,7 @@ def test_FTL_download_unknown_fails_no_errors(Pihole):
|
||||||
error = 'Error: URL not found'
|
error = 'Error: URL not found'
|
||||||
assert error in download_binary.stdout
|
assert error in download_binary.stdout
|
||||||
|
|
||||||
|
|
||||||
def test_FTL_binary_installed_and_responsive_no_errors(Pihole):
|
def test_FTL_binary_installed_and_responsive_no_errors(Pihole):
|
||||||
''' confirms FTL binary is copied and functional in installed location '''
|
''' confirms FTL binary is copied and functional in installed location '''
|
||||||
installed_binary = Pihole.run('''
|
installed_binary = Pihole.run('''
|
||||||
|
@ -370,6 +394,7 @@ def test_FTL_binary_installed_and_responsive_no_errors(Pihole):
|
||||||
expected_stdout = 'v'
|
expected_stdout = 'v'
|
||||||
assert expected_stdout in installed_binary.stdout
|
assert expected_stdout in installed_binary.stdout
|
||||||
|
|
||||||
|
|
||||||
# def test_FTL_support_files_installed(Pihole):
|
# def test_FTL_support_files_installed(Pihole):
|
||||||
# ''' confirms FTL support files are installed '''
|
# ''' confirms FTL support files are installed '''
|
||||||
# support_files = Pihole.run('''
|
# support_files = Pihole.run('''
|
||||||
|
@ -384,6 +409,7 @@ def test_FTL_binary_installed_and_responsive_no_errors(Pihole):
|
||||||
# assert '644 /run/pihole-FTL.pid' 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
|
# assert '644 /var/log/pihole-FTL.log' in support_files.stdout
|
||||||
|
|
||||||
|
|
||||||
def test_IPv6_only_link_local(Pihole):
|
def test_IPv6_only_link_local(Pihole):
|
||||||
''' confirms IPv6 blocking is disabled for Link-local address '''
|
''' confirms IPv6 blocking is disabled for Link-local address '''
|
||||||
# mock ip -6 address to return Link-local address
|
# mock ip -6 address to return Link-local address
|
||||||
|
@ -395,6 +421,7 @@ def test_IPv6_only_link_local(Pihole):
|
||||||
expected_stdout = 'Unable to find IPv6 ULA/GUA address, IPv6 adblocking will not be enabled'
|
expected_stdout = 'Unable to find IPv6 ULA/GUA address, IPv6 adblocking will not be enabled'
|
||||||
assert expected_stdout in detectPlatform.stdout
|
assert expected_stdout in detectPlatform.stdout
|
||||||
|
|
||||||
|
|
||||||
def test_IPv6_only_ULA(Pihole):
|
def test_IPv6_only_ULA(Pihole):
|
||||||
''' confirms IPv6 blocking is enabled for ULA addresses '''
|
''' confirms IPv6 blocking is enabled for ULA addresses '''
|
||||||
# mock ip -6 address to return ULA address
|
# mock ip -6 address to return ULA address
|
||||||
|
@ -406,6 +433,7 @@ def test_IPv6_only_ULA(Pihole):
|
||||||
expected_stdout = 'Found IPv6 ULA address, using it for blocking IPv6 ads'
|
expected_stdout = 'Found IPv6 ULA address, using it for blocking IPv6 ads'
|
||||||
assert expected_stdout in detectPlatform.stdout
|
assert expected_stdout in detectPlatform.stdout
|
||||||
|
|
||||||
|
|
||||||
def test_IPv6_only_GUA(Pihole):
|
def test_IPv6_only_GUA(Pihole):
|
||||||
''' confirms IPv6 blocking is enabled for GUA addresses '''
|
''' confirms IPv6 blocking is enabled for GUA addresses '''
|
||||||
# mock ip -6 address to return GUA address
|
# mock ip -6 address to return GUA address
|
||||||
|
@ -417,6 +445,7 @@ def test_IPv6_only_GUA(Pihole):
|
||||||
expected_stdout = 'Found IPv6 GUA address, using it for blocking IPv6 ads'
|
expected_stdout = 'Found IPv6 GUA address, using it for blocking IPv6 ads'
|
||||||
assert expected_stdout in detectPlatform.stdout
|
assert expected_stdout in detectPlatform.stdout
|
||||||
|
|
||||||
|
|
||||||
def test_IPv6_GUA_ULA_test(Pihole):
|
def test_IPv6_GUA_ULA_test(Pihole):
|
||||||
''' confirms IPv6 blocking is enabled for GUA and ULA addresses '''
|
''' confirms IPv6 blocking is enabled for GUA and ULA addresses '''
|
||||||
# mock ip -6 address to return GUA and ULA addresses
|
# mock ip -6 address to return GUA and ULA addresses
|
||||||
|
@ -428,6 +457,7 @@ def test_IPv6_GUA_ULA_test(Pihole):
|
||||||
expected_stdout = 'Found IPv6 ULA address, using it for blocking IPv6 ads'
|
expected_stdout = 'Found IPv6 ULA address, using it for blocking IPv6 ads'
|
||||||
assert expected_stdout in detectPlatform.stdout
|
assert expected_stdout in detectPlatform.stdout
|
||||||
|
|
||||||
|
|
||||||
def test_IPv6_ULA_GUA_test(Pihole):
|
def test_IPv6_ULA_GUA_test(Pihole):
|
||||||
''' confirms IPv6 blocking is enabled for GUA and ULA addresses '''
|
''' confirms IPv6 blocking is enabled for GUA and ULA addresses '''
|
||||||
# mock ip -6 address to return ULA and GUA addresses
|
# mock ip -6 address to return ULA and GUA addresses
|
||||||
|
@ -439,6 +469,7 @@ def test_IPv6_ULA_GUA_test(Pihole):
|
||||||
expected_stdout = 'Found IPv6 ULA address, using it for blocking IPv6 ads'
|
expected_stdout = 'Found IPv6 ULA address, using it for blocking IPv6 ads'
|
||||||
assert expected_stdout in detectPlatform.stdout
|
assert expected_stdout in detectPlatform.stdout
|
||||||
|
|
||||||
|
|
||||||
# Helper functions
|
# Helper functions
|
||||||
def mock_command(script, args, container):
|
def mock_command(script, args, container):
|
||||||
''' Allows for setup of commands we don't really want to have to run for real in unit tests '''
|
''' Allows for setup of commands we don't really want to have to run for real in unit tests '''
|
||||||
|
@ -461,6 +492,7 @@ def mock_command(script, args, container):
|
||||||
chmod +x {script}
|
chmod +x {script}
|
||||||
rm -f /var/log/{scriptlog}'''.format(script=full_script_path, content=mock_script, scriptlog=script))
|
rm -f /var/log/{scriptlog}'''.format(script=full_script_path, content=mock_script, scriptlog=script))
|
||||||
|
|
||||||
|
|
||||||
def mock_command_2(script, args, container):
|
def mock_command_2(script, args, container):
|
||||||
''' Allows for setup of commands we don't really want to have to run for real in unit tests '''
|
''' Allows for setup of commands we don't really want to have to run for real in unit tests '''
|
||||||
full_script_path = '/usr/local/bin/{}'.format(script)
|
full_script_path = '/usr/local/bin/{}'.format(script)
|
||||||
|
@ -482,6 +514,7 @@ def mock_command_2(script, args, container):
|
||||||
chmod +x {script}
|
chmod +x {script}
|
||||||
rm -f /var/log/{scriptlog}'''.format(script=full_script_path, content=mock_script, scriptlog=script))
|
rm -f /var/log/{scriptlog}'''.format(script=full_script_path, content=mock_script, scriptlog=script))
|
||||||
|
|
||||||
|
|
||||||
def run_script(Pihole, script):
|
def run_script(Pihole, script):
|
||||||
result = Pihole.run(script)
|
result = Pihole.run(script)
|
||||||
assert result.rc == 0
|
assert result.rc == 0
|
||||||
|
|
|
@ -5,6 +5,7 @@ run_local = testinfra.get_backend(
|
||||||
"local://"
|
"local://"
|
||||||
).get_module("Command").run
|
).get_module("Command").run
|
||||||
|
|
||||||
|
|
||||||
def test_scripts_pass_shellcheck():
|
def test_scripts_pass_shellcheck():
|
||||||
''' Make sure shellcheck does not find anything wrong with our shell scripts '''
|
''' Make sure shellcheck does not find anything wrong with our shell scripts '''
|
||||||
shellcheck = "find . -type f -name 'update.sh' | while read file; do shellcheck -x \"$file\" -e SC1090,SC1091; done;"
|
shellcheck = "find . -type f -name 'update.sh' | while read file; do shellcheck -x \"$file\" -e SC1090,SC1091; done;"
|
||||||
|
|
Loading…
Reference in a new issue