diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..8e19e550 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,25 @@ +name: Test Supported Distributions + +on: + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + +jobs: + distro-test: + if: github.event.pull_request.draft == false + runs-on: ubuntu-latest + strategy: + matrix: + distro: [debian_9, debian_10, ubuntu_16, ubuntu_18, ubuntu_20, centos_7, centos_8, fedora_31, fedora_32] + env: + DISTRO: ${{matrix.distro}} + steps: + - uses: actions/checkout@v1 + - name: Set up Python 3.7 + uses: actions/setup-python@v2 + with: + python-version: 3.7 + - name: Install dependencies + run: pip install -r test/requirements.txt + - name: Test with tox + run: tox -c test/tox.${DISTRO}.ini diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 3d80ab6e..00000000 --- a/.travis.yml +++ /dev/null @@ -1,5 +0,0 @@ -import: - - source: pi-hole/.github:/build-configs/core.yml@main - if: branch = master - - source: pi-hole/.github:/build-configs/core.yml@latest - if: branch != master diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 5c2b5f1c..bc83d70a 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -560,7 +560,7 @@ processor_check() { else # Check if the architecture is currently supported for FTL case "${PROCESSOR}" in - "amd64") log_write "${TICK} ${COL_GREEN}${PROCESSOR}${COL_NC}" + "amd64" | "x86_64") log_write "${TICK} ${COL_GREEN}${PROCESSOR}${COL_NC}" ;; "armv6l") log_write "${TICK} ${COL_GREEN}${PROCESSOR}${COL_NC}" ;; @@ -977,7 +977,7 @@ make_array_from_file() { # Otherwise, read the file line by line while IFS= read -r line;do # Othwerise, strip out comments and blank lines - new_line=$(echo "${line}" | sed -e 's/#.*$//' -e '/^$/d') + new_line=$(echo "${line}" | sed -e 's/^\s*#.*$//' -e '/^$/d') # If the line still has content (a non-zero value) if [[ -n "${new_line}" ]]; then # Put it into the array diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index bab6471e..45e96354 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -528,8 +528,10 @@ make_repo() { printf " %b %s..." "${INFO}" "${str}" # If the directory exists, if [[ -d "${directory}" ]]; then - # delete everything in it so git can clone into it - rm -rf "${directory}" + # Return with a 1 to exit the installer. We don't want to overwrite what could already be here in case it is not ours + str="Unable to clone ${remoteRepo} into ${directory} : Directory already exists" + printf "%b %b%s\\n" "${OVER}" "${CROSS}" "${str}" + return 1 fi # Clone the repo and return the return code from this command git clone -q --depth 20 "${remoteRepo}" "${directory}" &> /dev/null || return $? diff --git a/autotest b/autotest deleted file mode 100755 index 3747cc0b..00000000 --- a/autotest +++ /dev/null @@ -1 +0,0 @@ -py.test -v -f test/ diff --git a/test/centos_7.Dockerfile b/test/_centos_7.Dockerfile similarity index 100% rename from test/centos_7.Dockerfile rename to test/_centos_7.Dockerfile diff --git a/test/centos_8.Dockerfile b/test/_centos_8.Dockerfile similarity index 100% rename from test/centos_8.Dockerfile rename to test/_centos_8.Dockerfile diff --git a/test/debian_10.Dockerfile b/test/_debian_10.Dockerfile similarity index 100% rename from test/debian_10.Dockerfile rename to test/_debian_10.Dockerfile diff --git a/test/debian_9.Dockerfile b/test/_debian_9.Dockerfile similarity index 100% rename from test/debian_9.Dockerfile rename to test/_debian_9.Dockerfile diff --git a/test/fedora_31.Dockerfile b/test/_fedora_31.Dockerfile similarity index 100% rename from test/fedora_31.Dockerfile rename to test/_fedora_31.Dockerfile diff --git a/test/fedora_32.Dockerfile b/test/_fedora_32.Dockerfile similarity index 100% rename from test/fedora_32.Dockerfile rename to test/_fedora_32.Dockerfile diff --git a/test/ubuntu_16.Dockerfile b/test/_ubuntu_16.Dockerfile similarity index 92% rename from test/ubuntu_16.Dockerfile rename to test/_ubuntu_16.Dockerfile index d1107082..a92bc6f6 100644 --- a/test/ubuntu_16.Dockerfile +++ b/test/_ubuntu_16.Dockerfile @@ -13,4 +13,4 @@ RUN true && \ ENV PH_TEST true -#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \ +#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \ \ No newline at end of file diff --git a/test/ubuntu_18.Dockerfile b/test/_ubuntu_18.Dockerfile similarity index 100% rename from test/ubuntu_18.Dockerfile rename to test/_ubuntu_18.Dockerfile diff --git a/test/ubuntu_20.Dockerfile b/test/_ubuntu_20.Dockerfile similarity index 100% rename from test/ubuntu_20.Dockerfile rename to test/_ubuntu_20.Dockerfile diff --git a/test/conftest.py b/test/conftest.py index cda861c1..07166ec5 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -70,15 +70,7 @@ def args(request): @pytest.fixture(params=[ - 'debian_9', - 'debian_10', - 'centos_7', - 'centos_8', - 'fedora_31', - 'fedora_32', - 'ubuntu_16', - 'ubuntu_18', - 'ubuntu_20' + 'test_container' ]) def tag(request): ''' diff --git a/requirements.txt b/test/requirements.txt similarity index 100% rename from requirements.txt rename to test/requirements.txt diff --git a/setup.py b/test/setup.py similarity index 100% rename from setup.py rename to test/setup.py diff --git a/test/test_000_build_containers.py b/test/test_000_build_containers.py deleted file mode 100644 index 3033249f..00000000 --- a/test/test_000_build_containers.py +++ /dev/null @@ -1,29 +0,0 @@ -''' This file starts with 000 to make it run first ''' -import pytest -import testinfra - -run_local = testinfra.get_backend( - "local://" -).get_module("Command").run - - -@pytest.mark.parametrize("image,tag", [ - ('test/debian_9.Dockerfile', 'pytest_pihole:debian_9'), - ('test/debian_10.Dockerfile', 'pytest_pihole:debian_10'), - ('test/centos_7.Dockerfile', 'pytest_pihole:centos_7'), - ('test/centos_8.Dockerfile', 'pytest_pihole:centos_8'), - ('test/fedora_31.Dockerfile', 'pytest_pihole:fedora_31'), - ('test/fedora_32.Dockerfile', 'pytest_pihole:fedora_32'), - ('test/ubuntu_16.Dockerfile', 'pytest_pihole:ubuntu_16'), - ('test/ubuntu_18.Dockerfile', 'pytest_pihole:ubuntu_18'), - ('test/ubuntu_20.Dockerfile', 'pytest_pihole:ubuntu_20'), -]) -# mark as 'build_stage' so we can ensure images are built first when tests -# are executed in parallel. (not required when tests are executed serially) -@pytest.mark.build_stage -def test_build_pihole_image(image, tag): - build_cmd = run_local('docker build -f {} -t {} .'.format(image, tag)) - if build_cmd.rc != 0: - print(build_cmd.stdout) - print(build_cmd.stderr) - assert build_cmd.rc == 0 diff --git a/test/test_centos_7_support.py b/test/test_centos_7_support.py new file mode 100644 index 00000000..2f744ab4 --- /dev/null +++ b/test/test_centos_7_support.py @@ -0,0 +1,60 @@ +from .conftest import ( + tick_box, + info_box, + mock_command, +) + + +def test_php_upgrade_default_optout_centos_eq_7(Pihole): + ''' + confirms the default behavior to opt-out of installing PHP7 from REMI + ''' + distro_check = Pihole.run(''' + source /opt/pihole/basic-install.sh + distro_check + ''') + expected_stdout = info_box + (' User opt-out of PHP 7 upgrade on CentOS. ' + 'Deprecated PHP may be in use.') + assert expected_stdout in distro_check.stdout + remi_package = Pihole.package('remi-release') + assert not remi_package.is_installed + + +def test_php_upgrade_user_optout_centos_eq_7(Pihole): + ''' + confirms installer behavior when user opt-out of installing PHP7 from REMI + (php not currently installed) + ''' + # Whiptail dialog returns Cancel for user prompt + mock_command('whiptail', {'*': ('', '1')}, Pihole) + distro_check = Pihole.run(''' + source /opt/pihole/basic-install.sh + distro_check + ''') + expected_stdout = info_box + (' User opt-out of PHP 7 upgrade on CentOS. ' + 'Deprecated PHP may be in use.') + assert expected_stdout in distro_check.stdout + remi_package = Pihole.package('remi-release') + assert not remi_package.is_installed + + +def test_php_upgrade_user_optin_centos_eq_7(Pihole): + ''' + confirms installer behavior when user opt-in to installing PHP7 from REMI + (php not currently installed) + ''' + # Whiptail dialog returns Continue for user prompt + mock_command('whiptail', {'*': ('', '0')}, Pihole) + distro_check = Pihole.run(''' + source /opt/pihole/basic-install.sh + distro_check + ''') + assert 'opt-out' not in distro_check.stdout + expected_stdout = info_box + (' Enabling Remi\'s RPM repository ' + '(https://rpms.remirepo.net)') + assert expected_stdout in distro_check.stdout + expected_stdout = tick_box + (' Remi\'s RPM repository has ' + 'been enabled for PHP7') + assert expected_stdout in distro_check.stdout + remi_package = Pihole.package('remi-release') + assert remi_package.is_installed diff --git a/test/test_centos_8_support.py b/test/test_centos_8_support.py new file mode 100644 index 00000000..d3e83658 --- /dev/null +++ b/test/test_centos_8_support.py @@ -0,0 +1,65 @@ +from .conftest import ( + tick_box, + info_box, + mock_command, +) + + +def test_php_upgrade_default_continue_centos_gte_8(Pihole): + ''' + confirms the latest version of CentOS continues / does not optout + (should trigger on CentOS7 only) + ''' + distro_check = Pihole.run(''' + source /opt/pihole/basic-install.sh + distro_check + ''') + unexpected_stdout = info_box + (' User opt-out of PHP 7 upgrade on CentOS.' + ' Deprecated PHP may be in use.') + assert unexpected_stdout not in distro_check.stdout + # ensure remi was not installed on latest CentOS + remi_package = Pihole.package('remi-release') + assert not remi_package.is_installed + + +def test_php_upgrade_user_optout_skipped_centos_gte_8(Pihole): + ''' + confirms installer skips user opt-out of installing PHP7 from REMI on + latest CentOS (should trigger on CentOS7 only) + (php not currently installed) + ''' + # Whiptail dialog returns Cancel for user prompt + mock_command('whiptail', {'*': ('', '1')}, Pihole) + distro_check = Pihole.run(''' + source /opt/pihole/basic-install.sh + distro_check + ''') + unexpected_stdout = info_box + (' User opt-out of PHP 7 upgrade on CentOS.' + ' Deprecated PHP may be in use.') + assert unexpected_stdout not in distro_check.stdout + # ensure remi was not installed on latest CentOS + remi_package = Pihole.package('remi-release') + assert not remi_package.is_installed + + +def test_php_upgrade_user_optin_skipped_centos_gte_8(Pihole): + ''' + confirms installer skips user opt-in to installing PHP7 from REMI on + latest CentOS (should trigger on CentOS7 only) + (php not currently installed) + ''' + # Whiptail dialog returns Continue for user prompt + mock_command('whiptail', {'*': ('', '0')}, Pihole) + distro_check = Pihole.run(''' + source /opt/pihole/basic-install.sh + distro_check + ''') + assert 'opt-out' not in distro_check.stdout + unexpected_stdout = info_box + (' Enabling Remi\'s RPM repository ' + '(https://rpms.remirepo.net)') + assert unexpected_stdout not in distro_check.stdout + unexpected_stdout = tick_box + (' Remi\'s RPM repository has ' + 'been enabled for PHP7') + assert unexpected_stdout not in distro_check.stdout + remi_package = Pihole.package('remi-release') + assert not remi_package.is_installed diff --git a/test/test_centos_common_support.py b/test/test_centos_common_support.py new file mode 100644 index 00000000..fdf43cba --- /dev/null +++ b/test/test_centos_common_support.py @@ -0,0 +1,120 @@ +import pytest +from .conftest import ( + tick_box, + info_box, + cross_box, + mock_command, +) + + +def test_release_supported_version_check_centos(Pihole): + ''' + confirms installer exits on unsupported releases of CentOS + ''' + # modify /etc/redhat-release to mock an unsupported CentOS release + Pihole.run('echo "CentOS Linux release 6.9" > /etc/redhat-release') + distro_check = Pihole.run(''' + source /opt/pihole/basic-install.sh + distro_check + ''') + expected_stdout = cross_box + (' CentOS 6 is not supported.') + assert expected_stdout in distro_check.stdout + expected_stdout = 'Please update to CentOS release 7 or later' + assert expected_stdout in distro_check.stdout + + +def test_enable_epel_repository_centos(Pihole): + ''' + confirms the EPEL package repository is enabled when installed on CentOS + ''' + distro_check = Pihole.run(''' + source /opt/pihole/basic-install.sh + distro_check + ''') + expected_stdout = info_box + (' Enabling EPEL package repository ' + '(https://fedoraproject.org/wiki/EPEL)') + assert expected_stdout in distro_check.stdout + expected_stdout = tick_box + ' Installed epel-release' + assert expected_stdout in distro_check.stdout + epel_package = Pihole.package('epel-release') + assert epel_package.is_installed + + +def test_php_version_lt_7_detected_upgrade_default_optout_centos(Pihole): + ''' + confirms the default behavior to opt-out of upgrading to PHP7 from REMI + ''' + # first we will install the default php version to test installer behavior + php_install = Pihole.run('yum install -y php') + assert php_install.rc == 0 + php_package = Pihole.package('php') + default_centos_php_version = php_package.version.split('.')[0] + if int(default_centos_php_version) >= 7: # PHP7 is supported/recommended + pytest.skip("Test deprecated . Detected default PHP version >= 7") + distro_check = Pihole.run(''' + source /opt/pihole/basic-install.sh + distro_check + ''') + expected_stdout = info_box + (' User opt-out of PHP 7 upgrade on CentOS. ' + 'Deprecated PHP may be in use.') + assert expected_stdout in distro_check.stdout + remi_package = Pihole.package('remi-release') + assert not remi_package.is_installed + + +def test_php_version_lt_7_detected_upgrade_user_optout_centos(Pihole): + ''' + confirms installer behavior when user opt-out to upgrade to PHP7 via REMI + ''' + # first we will install the default php version to test installer behavior + php_install = Pihole.run('yum install -y php') + assert php_install.rc == 0 + php_package = Pihole.package('php') + default_centos_php_version = php_package.version.split('.')[0] + if int(default_centos_php_version) >= 7: # PHP7 is supported/recommended + pytest.skip("Test deprecated . Detected default PHP version >= 7") + # Whiptail dialog returns Cancel for user prompt + mock_command('whiptail', {'*': ('', '1')}, Pihole) + distro_check = Pihole.run(''' + source /opt/pihole/basic-install.sh + distro_check + ''') + expected_stdout = info_box + (' User opt-out of PHP 7 upgrade on CentOS. ' + 'Deprecated PHP may be in use.') + assert expected_stdout in distro_check.stdout + remi_package = Pihole.package('remi-release') + assert not remi_package.is_installed + + +def test_php_version_lt_7_detected_upgrade_user_optin_centos(Pihole): + ''' + confirms installer behavior when user opt-in to upgrade to PHP7 via REMI + ''' + # first we will install the default php version to test installer behavior + php_install = Pihole.run('yum install -y php') + assert php_install.rc == 0 + php_package = Pihole.package('php') + default_centos_php_version = php_package.version.split('.')[0] + if int(default_centos_php_version) >= 7: # PHP7 is supported/recommended + pytest.skip("Test deprecated . Detected default PHP version >= 7") + # Whiptail dialog returns Continue for user prompt + mock_command('whiptail', {'*': ('', '0')}, Pihole) + distro_check = Pihole.run(''' + source /opt/pihole/basic-install.sh + distro_check + install_dependent_packages PIHOLE_WEB_DEPS[@] + ''') + expected_stdout = info_box + (' User opt-out of PHP 7 upgrade on CentOS. ' + 'Deprecated PHP may be in use.') + assert expected_stdout not in distro_check.stdout + expected_stdout = info_box + (' Enabling Remi\'s RPM repository ' + '(https://rpms.remirepo.net)') + assert expected_stdout in distro_check.stdout + expected_stdout = tick_box + (' Remi\'s RPM repository has ' + 'been enabled for PHP7') + assert expected_stdout in distro_check.stdout + remi_package = Pihole.package('remi-release') + assert remi_package.is_installed + updated_php_package = Pihole.package('php') + updated_php_version = updated_php_package.version.split('.')[0] + assert int(updated_php_version) == 7 diff --git a/test/test_centos_fedora_common_support.py b/test/test_centos_fedora_common_support.py new file mode 100644 index 00000000..21ae6d1d --- /dev/null +++ b/test/test_centos_fedora_common_support.py @@ -0,0 +1,65 @@ +from .conftest import ( + tick_box, + cross_box, + mock_command, +) + + +def mock_selinux_config(state, Pihole): + ''' + Creates a mock SELinux config file with expected content + ''' + # validate state string + valid_states = ['enforcing', 'permissive', 'disabled'] + assert state in valid_states + # getenforce returns the running state of SELinux + mock_command('getenforce', {'*': (state.capitalize(), '0')}, Pihole) + # create mock configuration with desired content + Pihole.run(''' + mkdir /etc/selinux + echo "SELINUX={state}" > /etc/selinux/config + '''.format(state=state.lower())) + + +def test_selinux_enforcing_exit(Pihole): + ''' + confirms installer prompts to exit when SELinux is Enforcing by default + ''' + mock_selinux_config("enforcing", Pihole) + check_selinux = Pihole.run(''' + source /opt/pihole/basic-install.sh + checkSelinux + ''') + expected_stdout = cross_box + ' Current SELinux: Enforcing' + assert expected_stdout in check_selinux.stdout + expected_stdout = 'SELinux Enforcing detected, exiting installer' + assert expected_stdout in check_selinux.stdout + assert check_selinux.rc == 1 + + +def test_selinux_permissive(Pihole): + ''' + confirms installer continues when SELinux is Permissive + ''' + mock_selinux_config("permissive", Pihole) + check_selinux = Pihole.run(''' + source /opt/pihole/basic-install.sh + checkSelinux + ''') + expected_stdout = tick_box + ' Current SELinux: Permissive' + assert expected_stdout in check_selinux.stdout + assert check_selinux.rc == 0 + + +def test_selinux_disabled(Pihole): + ''' + confirms installer continues when SELinux is Disabled + ''' + mock_selinux_config("disabled", Pihole) + check_selinux = Pihole.run(''' + source /opt/pihole/basic-install.sh + checkSelinux + ''') + expected_stdout = tick_box + ' Current SELinux: Disabled' + assert expected_stdout in check_selinux.stdout + assert check_selinux.rc == 0 diff --git a/test/test_centos_fedora_support.py b/test/test_centos_fedora_support.py deleted file mode 100644 index 8dd0ee5f..00000000 --- a/test/test_centos_fedora_support.py +++ /dev/null @@ -1,327 +0,0 @@ -import pytest -from .conftest import ( - tick_box, - info_box, - cross_box, - mock_command, -) - - -def mock_selinux_config(state, Pihole): - ''' - Creates a mock SELinux config file with expected content - ''' - # validate state string - valid_states = ['enforcing', 'permissive', 'disabled'] - assert state in valid_states - # getenforce returns the running state of SELinux - mock_command('getenforce', {'*': (state.capitalize(), '0')}, Pihole) - # create mock configuration with desired content - Pihole.run(''' - mkdir /etc/selinux - echo "SELINUX={state}" > /etc/selinux/config - '''.format(state=state.lower())) - - -@pytest.mark.parametrize("tag", [('centos_7'), ('centos_8'), ('fedora_31'), ('fedora_32'), ]) -def test_selinux_enforcing_exit(Pihole): - ''' - confirms installer prompts to exit when SELinux is Enforcing by default - ''' - mock_selinux_config("enforcing", Pihole) - check_selinux = Pihole.run(''' - source /opt/pihole/basic-install.sh - checkSelinux - ''') - expected_stdout = cross_box + ' Current SELinux: Enforcing' - assert expected_stdout in check_selinux.stdout - expected_stdout = 'SELinux Enforcing detected, exiting installer' - assert expected_stdout in check_selinux.stdout - assert check_selinux.rc == 1 - - -@pytest.mark.parametrize("tag", [('centos_7'), ('centos_8'), ('fedora_31'), ('fedora_32'), ]) -def test_selinux_permissive(Pihole): - ''' - confirms installer continues when SELinux is Permissive - ''' - mock_selinux_config("permissive", Pihole) - check_selinux = Pihole.run(''' - source /opt/pihole/basic-install.sh - checkSelinux - ''') - expected_stdout = tick_box + ' Current SELinux: Permissive' - assert expected_stdout in check_selinux.stdout - assert check_selinux.rc == 0 - - -@pytest.mark.parametrize("tag", [('centos_7'), ('centos_8'), ('fedora_31'), ('fedora_32'), ]) -def test_selinux_disabled(Pihole): - ''' - confirms installer continues when SELinux is Disabled - ''' - mock_selinux_config("disabled", Pihole) - check_selinux = Pihole.run(''' - source /opt/pihole/basic-install.sh - checkSelinux - ''') - expected_stdout = tick_box + ' Current SELinux: Disabled' - assert expected_stdout in check_selinux.stdout - assert check_selinux.rc == 0 - - -@pytest.mark.parametrize("tag", [('fedora_31'), ('fedora_32'), ]) -def test_epel_and_remi_not_installed_fedora(Pihole): - ''' - confirms installer does not attempt to install EPEL/REMI repositories - on Fedora - ''' - distro_check = Pihole.run(''' - source /opt/pihole/basic-install.sh - distro_check - ''') - assert distro_check.stdout == '' - - epel_package = Pihole.package('epel-release') - assert not epel_package.is_installed - remi_package = Pihole.package('remi-release') - assert not remi_package.is_installed - - -@pytest.mark.parametrize("tag", [('centos_7'), ('centos_8'), ]) -def test_release_supported_version_check_centos(Pihole): - ''' - confirms installer exits on unsupported releases of CentOS - ''' - # modify /etc/redhat-release to mock an unsupported CentOS release - Pihole.run('echo "CentOS Linux release 6.9" > /etc/redhat-release') - distro_check = Pihole.run(''' - source /opt/pihole/basic-install.sh - distro_check - ''') - expected_stdout = cross_box + (' CentOS 6 is not supported.') - assert expected_stdout in distro_check.stdout - expected_stdout = 'Please update to CentOS release 7 or later' - assert expected_stdout in distro_check.stdout - - -@pytest.mark.parametrize("tag", [('centos_7'), ('centos_8'), ]) -def test_enable_epel_repository_centos(Pihole): - ''' - confirms the EPEL package repository is enabled when installed on CentOS - ''' - distro_check = Pihole.run(''' - source /opt/pihole/basic-install.sh - distro_check - ''') - expected_stdout = info_box + (' Enabling EPEL package repository ' - '(https://fedoraproject.org/wiki/EPEL)') - assert expected_stdout in distro_check.stdout - expected_stdout = tick_box + ' Installed epel-release' - assert expected_stdout in distro_check.stdout - epel_package = Pihole.package('epel-release') - assert epel_package.is_installed - - -@pytest.mark.parametrize("tag", [('centos_7'), ]) -def test_php_upgrade_default_optout_centos_eq_7(Pihole): - ''' - confirms the default behavior to opt-out of installing PHP7 from REMI - ''' - distro_check = Pihole.run(''' - source /opt/pihole/basic-install.sh - distro_check - ''') - expected_stdout = info_box + (' User opt-out of PHP 7 upgrade on CentOS. ' - 'Deprecated PHP may be in use.') - assert expected_stdout in distro_check.stdout - remi_package = Pihole.package('remi-release') - assert not remi_package.is_installed - - -@pytest.mark.parametrize("tag", [('centos_8'), ]) -def test_php_upgrade_default_continue_centos_gte_8(Pihole): - ''' - confirms the latest version of CentOS continues / does not optout - (should trigger on CentOS7 only) - ''' - distro_check = Pihole.run(''' - source /opt/pihole/basic-install.sh - distro_check - ''') - unexpected_stdout = info_box + (' User opt-out of PHP 7 upgrade on CentOS.' - ' Deprecated PHP may be in use.') - assert unexpected_stdout not in distro_check.stdout - # ensure remi was not installed on latest CentOS - remi_package = Pihole.package('remi-release') - assert not remi_package.is_installed - - -@pytest.mark.parametrize("tag", [('centos_7'), ]) -def test_php_upgrade_user_optout_centos_eq_7(Pihole): - ''' - confirms installer behavior when user opt-out of installing PHP7 from REMI - (php not currently installed) - ''' - # Whiptail dialog returns Cancel for user prompt - mock_command('whiptail', {'*': ('', '1')}, Pihole) - distro_check = Pihole.run(''' - source /opt/pihole/basic-install.sh - distro_check - ''') - expected_stdout = info_box + (' User opt-out of PHP 7 upgrade on CentOS. ' - 'Deprecated PHP may be in use.') - assert expected_stdout in distro_check.stdout - remi_package = Pihole.package('remi-release') - assert not remi_package.is_installed - - -@pytest.mark.parametrize("tag", [('centos_8'), ]) -def test_php_upgrade_user_optout_skipped_centos_gte_8(Pihole): - ''' - confirms installer skips user opt-out of installing PHP7 from REMI on - latest CentOS (should trigger on CentOS7 only) - (php not currently installed) - ''' - # Whiptail dialog returns Cancel for user prompt - mock_command('whiptail', {'*': ('', '1')}, Pihole) - distro_check = Pihole.run(''' - source /opt/pihole/basic-install.sh - distro_check - ''') - unexpected_stdout = info_box + (' User opt-out of PHP 7 upgrade on CentOS.' - ' Deprecated PHP may be in use.') - assert unexpected_stdout not in distro_check.stdout - # ensure remi was not installed on latest CentOS - remi_package = Pihole.package('remi-release') - assert not remi_package.is_installed - - -@pytest.mark.parametrize("tag", [('centos_7'), ]) -def test_php_upgrade_user_optin_centos_eq_7(Pihole): - ''' - confirms installer behavior when user opt-in to installing PHP7 from REMI - (php not currently installed) - ''' - # Whiptail dialog returns Continue for user prompt - mock_command('whiptail', {'*': ('', '0')}, Pihole) - distro_check = Pihole.run(''' - source /opt/pihole/basic-install.sh - distro_check - ''') - assert 'opt-out' not in distro_check.stdout - expected_stdout = info_box + (' Enabling Remi\'s RPM repository ' - '(https://rpms.remirepo.net)') - assert expected_stdout in distro_check.stdout - expected_stdout = tick_box + (' Remi\'s RPM repository has ' - 'been enabled for PHP7') - assert expected_stdout in distro_check.stdout - remi_package = Pihole.package('remi-release') - assert remi_package.is_installed - - -@pytest.mark.parametrize("tag", [('centos_8'), ]) -def test_php_upgrade_user_optin_skipped_centos_gte_8(Pihole): - ''' - confirms installer skips user opt-in to installing PHP7 from REMI on - latest CentOS (should trigger on CentOS7 only) - (php not currently installed) - ''' - # Whiptail dialog returns Continue for user prompt - mock_command('whiptail', {'*': ('', '0')}, Pihole) - distro_check = Pihole.run(''' - source /opt/pihole/basic-install.sh - distro_check - ''') - assert 'opt-out' not in distro_check.stdout - unexpected_stdout = info_box + (' Enabling Remi\'s RPM repository ' - '(https://rpms.remirepo.net)') - assert unexpected_stdout not in distro_check.stdout - unexpected_stdout = tick_box + (' Remi\'s RPM repository has ' - 'been enabled for PHP7') - assert unexpected_stdout not in distro_check.stdout - remi_package = Pihole.package('remi-release') - assert not remi_package.is_installed - - -@pytest.mark.parametrize("tag", [('centos_7'), ('centos_8'), ]) -def test_php_version_lt_7_detected_upgrade_default_optout_centos(Pihole): - ''' - confirms the default behavior to opt-out of upgrading to PHP7 from REMI - ''' - # first we will install the default php version to test installer behavior - php_install = Pihole.run('yum install -y php') - assert php_install.rc == 0 - php_package = Pihole.package('php') - default_centos_php_version = php_package.version.split('.')[0] - if int(default_centos_php_version) >= 7: # PHP7 is supported/recommended - pytest.skip("Test deprecated . Detected default PHP version >= 7") - distro_check = Pihole.run(''' - source /opt/pihole/basic-install.sh - distro_check - ''') - expected_stdout = info_box + (' User opt-out of PHP 7 upgrade on CentOS. ' - 'Deprecated PHP may be in use.') - assert expected_stdout in distro_check.stdout - remi_package = Pihole.package('remi-release') - assert not remi_package.is_installed - - -@pytest.mark.parametrize("tag", [('centos_7'), ('centos_8'), ]) -def test_php_version_lt_7_detected_upgrade_user_optout_centos(Pihole): - ''' - confirms installer behavior when user opt-out to upgrade to PHP7 via REMI - ''' - # first we will install the default php version to test installer behavior - php_install = Pihole.run('yum install -y php') - assert php_install.rc == 0 - php_package = Pihole.package('php') - default_centos_php_version = php_package.version.split('.')[0] - if int(default_centos_php_version) >= 7: # PHP7 is supported/recommended - pytest.skip("Test deprecated . Detected default PHP version >= 7") - # Whiptail dialog returns Cancel for user prompt - mock_command('whiptail', {'*': ('', '1')}, Pihole) - distro_check = Pihole.run(''' - source /opt/pihole/basic-install.sh - distro_check - ''') - expected_stdout = info_box + (' User opt-out of PHP 7 upgrade on CentOS. ' - 'Deprecated PHP may be in use.') - assert expected_stdout in distro_check.stdout - remi_package = Pihole.package('remi-release') - assert not remi_package.is_installed - - -@pytest.mark.parametrize("tag", [('centos_7'), ('centos_8'), ]) -def test_php_version_lt_7_detected_upgrade_user_optin_centos(Pihole): - ''' - confirms installer behavior when user opt-in to upgrade to PHP7 via REMI - ''' - # first we will install the default php version to test installer behavior - php_install = Pihole.run('yum install -y php') - assert php_install.rc == 0 - php_package = Pihole.package('php') - default_centos_php_version = php_package.version.split('.')[0] - if int(default_centos_php_version) >= 7: # PHP7 is supported/recommended - pytest.skip("Test deprecated . Detected default PHP version >= 7") - # Whiptail dialog returns Continue for user prompt - mock_command('whiptail', {'*': ('', '0')}, Pihole) - distro_check = Pihole.run(''' - source /opt/pihole/basic-install.sh - distro_check - install_dependent_packages PIHOLE_WEB_DEPS[@] - ''') - expected_stdout = info_box + (' User opt-out of PHP 7 upgrade on CentOS. ' - 'Deprecated PHP may be in use.') - assert expected_stdout not in distro_check.stdout - expected_stdout = info_box + (' Enabling Remi\'s RPM repository ' - '(https://rpms.remirepo.net)') - assert expected_stdout in distro_check.stdout - expected_stdout = tick_box + (' Remi\'s RPM repository has ' - 'been enabled for PHP7') - assert expected_stdout in distro_check.stdout - remi_package = Pihole.package('remi-release') - assert remi_package.is_installed - updated_php_package = Pihole.package('php') - updated_php_version = updated_php_package.version.split('.')[0] - assert int(updated_php_version) == 7 diff --git a/test/test_fedora_support.py b/test/test_fedora_support.py new file mode 100644 index 00000000..473b2e96 --- /dev/null +++ b/test/test_fedora_support.py @@ -0,0 +1,15 @@ +def test_epel_and_remi_not_installed_fedora(Pihole): + ''' + confirms installer does not attempt to install EPEL/REMI repositories + on Fedora + ''' + distro_check = Pihole.run(''' + source /opt/pihole/basic-install.sh + distro_check + ''') + assert distro_check.stdout == '' + + epel_package = Pihole.package('epel-release') + assert not epel_package.is_installed + remi_package = Pihole.package('remi-release') + assert not remi_package.is_installed diff --git a/test/test_shellcheck.py b/test/test_shellcheck.py deleted file mode 100644 index 919ad2b9..00000000 --- a/test/test_shellcheck.py +++ /dev/null @@ -1,18 +0,0 @@ -import testinfra - -run_local = testinfra.get_backend( - "local://" -).get_module("Command").run - - -def test_scripts_pass_shellcheck(): - ''' - 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;") - results = run_local(shellcheck) - print(results.stdout) - assert '' == results.stdout diff --git a/test/tox.centos_7.ini b/test/tox.centos_7.ini new file mode 100644 index 00000000..c2752698 --- /dev/null +++ b/test/tox.centos_7.ini @@ -0,0 +1,8 @@ +[tox] +envlist = py37 + +[testenv] +whitelist_externals = docker +deps = -rrequirements.txt +commands = docker build -f _centos_7.Dockerfile -t pytest_pihole:test_container ../ + pytest {posargs:-vv -n auto} ./test_automated_install.py ./test_centos_fedora_common_support.py ./test_centos_common_support.py ./test_centos_7_support.py diff --git a/test/tox.centos_8.ini b/test/tox.centos_8.ini new file mode 100644 index 00000000..c8852bae --- /dev/null +++ b/test/tox.centos_8.ini @@ -0,0 +1,8 @@ +[tox] +envlist = py37 + +[testenv] +whitelist_externals = docker +deps = -rrequirements.txt +commands = docker build -f _centos_8.Dockerfile -t pytest_pihole:test_container ../ + pytest {posargs:-vv -n auto} ./test_automated_install.py ./test_centos_fedora_common_support.py ./test_centos_common_support.py ./test_centos_8_support.py diff --git a/test/tox.debian_10.ini b/test/tox.debian_10.ini new file mode 100644 index 00000000..e8c5d746 --- /dev/null +++ b/test/tox.debian_10.ini @@ -0,0 +1,8 @@ +[tox] +envlist = py37 + +[testenv] +whitelist_externals = docker +deps = -rrequirements.txt +commands = docker build -f _debian_10.Dockerfile -t pytest_pihole:test_container ../ + pytest {posargs:-vv -n auto} ./test_automated_install.py diff --git a/test/tox.debian_9.ini b/test/tox.debian_9.ini new file mode 100644 index 00000000..b33e9927 --- /dev/null +++ b/test/tox.debian_9.ini @@ -0,0 +1,8 @@ +[tox] +envlist = py37 + +[testenv] +whitelist_externals = docker +deps = -rrequirements.txt +commands = docker build -f _debian_9.Dockerfile -t pytest_pihole:test_container ../ + pytest {posargs:-vv -n auto} ./test_automated_install.py diff --git a/test/tox.fedora_31.ini b/test/tox.fedora_31.ini new file mode 100644 index 00000000..36ab10ad --- /dev/null +++ b/test/tox.fedora_31.ini @@ -0,0 +1,8 @@ +[tox] +envlist = py37 + +[testenv] +whitelist_externals = docker +deps = -rrequirements.txt +commands = docker build -f _fedora_31.Dockerfile -t pytest_pihole:test_container ../ + pytest {posargs:-vv -n auto} ./test_automated_install.py ./test_centos_fedora_common_support.py ./test_fedora_support.py diff --git a/test/tox.fedora_32.ini b/test/tox.fedora_32.ini new file mode 100644 index 00000000..c68e0757 --- /dev/null +++ b/test/tox.fedora_32.ini @@ -0,0 +1,8 @@ +[tox] +envlist = py37 + +[testenv] +whitelist_externals = docker +deps = -rrequirements.txt +commands = docker build -f _fedora_32.Dockerfile -t pytest_pihole:test_container ../ + pytest {posargs:-vv -n auto} ./test_automated_install.py ./test_centos_fedora_common_support.py ./test_fedora_support.py diff --git a/test/tox.ubuntu_16.ini b/test/tox.ubuntu_16.ini new file mode 100644 index 00000000..6f484b6b --- /dev/null +++ b/test/tox.ubuntu_16.ini @@ -0,0 +1,8 @@ +[tox] +envlist = py37 + +[testenv] +whitelist_externals = docker +deps = -rrequirements.txt +commands = docker build -f _ubuntu_16.Dockerfile -t pytest_pihole:test_container ../ + pytest {posargs:-vv -n auto} ./test_automated_install.py diff --git a/test/tox.ubuntu_18.ini b/test/tox.ubuntu_18.ini new file mode 100644 index 00000000..10d4ac09 --- /dev/null +++ b/test/tox.ubuntu_18.ini @@ -0,0 +1,8 @@ +[tox] +envlist = py37 + +[testenv] +whitelist_externals = docker +deps = -rrequirements.txt +commands = docker build -f _ubuntu_18.Dockerfile -t pytest_pihole:test_container ../ + pytest {posargs:-vv -n auto} ./test_automated_install.py diff --git a/test/tox.ubuntu_20.ini b/test/tox.ubuntu_20.ini new file mode 100644 index 00000000..8b405b28 --- /dev/null +++ b/test/tox.ubuntu_20.ini @@ -0,0 +1,8 @@ +[tox] +envlist = py37 + +[testenv] +whitelist_externals = docker +deps = -rrequirements.txt +commands = docker build -f _ubuntu_20.Dockerfile -t pytest_pihole:test_container ../ + pytest {posargs:-vv -n auto} ./test_automated_install.py diff --git a/tox.ini b/tox.ini deleted file mode 100644 index 1142aea8..00000000 --- a/tox.ini +++ /dev/null @@ -1,16 +0,0 @@ -[tox] -envlist = py37 - -[testenv] -whitelist_externals = docker -deps = -rrequirements.txt -commands = docker build -f test/debian_9.Dockerfile -t pytest_pihole:debian_9 . - docker build -f test/debian_10.Dockerfile -t pytest_pihole:debian_10 . - docker build -f test/centos_7.Dockerfile -t pytest_pihole:centos_7 . - docker build -f test/centos_8.Dockerfile -t pytest_pihole:centos_8 . - docker build -f test/fedora_31.Dockerfile -t pytest_pihole:fedora_31 . - docker build -f test/fedora_32.Dockerfile -t pytest_pihole:fedora_32 . - docker build -f test/ubuntu_16.Dockerfile -t pytest_pihole:ubuntu_16 . - docker build -f test/ubuntu_18.Dockerfile -t pytest_pihole:ubuntu_18 . - docker build -f test/ubuntu_20.Dockerfile -t pytest_pihole:ubuntu_20 . - pytest {posargs:-vv -n auto} -m "not build_stage" ./test/