From a8e97257d7c473b393dbd6ed02a120e478a27133 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sun, 29 Nov 2020 15:08:46 +0000 Subject: [PATCH 01/18] Ensure entries of `PIHOLE_DNS_10` and above are not deleted when removing PIHOLE_DNS_1 and PIHOLE_DNS_2 Signed-off-by: Adam Warner --- automated install/basic-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 21e699c7..af6c3ade 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1913,7 +1913,7 @@ finalExports() { # If the setup variable file exists, if [[ -e "${setupVars}" ]]; then # update the variables in the file - sed -i.update.bak '/PIHOLE_INTERFACE/d;/IPV4_ADDRESS/d;/IPV6_ADDRESS/d;/PIHOLE_DNS_1/d;/PIHOLE_DNS_2/d;/QUERY_LOGGING/d;/INSTALL_WEB_SERVER/d;/INSTALL_WEB_INTERFACE/d;/LIGHTTPD_ENABLED/d;/CACHE_SIZE/d;' "${setupVars}" + sed -i.update.bak '/PIHOLE_INTERFACE/d;/IPV4_ADDRESS/d;/IPV6_ADDRESS/d;/PIHOLE_DNS_1\b/d;/PIHOLE_DNS_2\b/d;/QUERY_LOGGING/d;/INSTALL_WEB_SERVER/d;/INSTALL_WEB_INTERFACE/d;/LIGHTTPD_ENABLED/d;/CACHE_SIZE/d;' "${setupVars}" fi # echo the information to the user { From 0ecb8bf5e9fb555df7a4622c52bf54535bd96de1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 29 Nov 2020 21:05:40 +0100 Subject: [PATCH 02/18] Add lsof to dependencies for non Debian OS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- automated install/basic-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index af6c3ade..bab6471e 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -393,7 +393,7 @@ elif is_command rpm ; then PKG_INSTALL=("${PKG_MANAGER}" install -y) PKG_COUNT="${PKG_MANAGER} check-update | egrep '(.i686|.x86|.noarch|.arm|.src)' | wc -l" INSTALLER_DEPS=(git iproute newt procps-ng which chkconfig bind-utils) - PIHOLE_DEPS=(cronie curl findutils nmap-ncat sudo unzip libidn2 psmisc sqlite libcap) + PIHOLE_DEPS=(cronie curl findutils nmap-ncat sudo unzip libidn2 psmisc sqlite libcap lsof) PIHOLE_WEB_DEPS=(lighttpd lighttpd-fastcgi php-common php-cli php-pdo php-xml php-json php-intl) LIGHTTPD_USER="lighttpd" LIGHTTPD_GROUP="lighttpd" From e004d27b28bf3da43101948903c56a7cf66be4eb Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Mon, 30 Nov 2020 18:58:23 +0000 Subject: [PATCH 03/18] Fix processing of CONDITIONAL_FORWARDING_REVERSE Signed-off-by: Adam Warner --- advanced/Scripts/webpage.sh | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 15471ad4..7cf0ae75 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -217,6 +217,11 @@ trust-anchor=.,20326,8,2,E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC68345710423 if [[ "${CONDITIONAL_FORWARDING}" == true ]]; then # Convert legacy "conditional forwarding" to rev-server configuration + delete_setting "REV_SERVER" + delete_setting "REV_SERVER_DOMAIN" + delete_setting "REV_SERVER_TARGET" + delete_setting "REV_SERVER_CIDR" + REV_SERVER=true add_setting "REV_SERVER" "true" @@ -226,7 +231,17 @@ trust-anchor=.,20326,8,2,E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC68345710423 REV_SERVER_TARGET="${CONDITIONAL_FORWARDING_IP}" add_setting "REV_SERVER_TARGET" "${REV_SERVER_TARGET}" - REV_SERVER_CIDR="${CONDITIONAL_FORWARDING_REVERSE}" + search="in-addr.arpa" + if [[ "$CONDITIONAL_FORWARDING_REVERSE" == *"$search" ]];then + arrRev=(${CONDITIONAL_FORWARDING_REVERSE//./ }) + case ${#arrRev[@]} in + 6 ) REV_SERVER_CIDR="${arrRev[3]}.${arrRev[2]}.${arrRev[1]}.${arrRev[0]}/32";; + 5 ) REV_SERVER_CIDR="${arrRev[2]}.${arrRev[1]}.${arrRev[0]}.0/24";; + 4 ) REV_SERVER_CIDR="${arrRev[1]}.${arrRev[0]}.0.0/16";; + 3 ) REV_SERVER_CIDR="${arrRev[0]}.0.0.0/8";; + esac + fi + if [ -z "${REV_SERVER_CIDR}" ]; then # Convert existing input to /24 subnet (preserves legacy behavior) # This sed converts "192.168.1.2" to "192.168.1.0/24" From 6cb8f3f403928620e23e35158ae4f89a34487df7 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Mon, 30 Nov 2020 21:18:25 +0000 Subject: [PATCH 04/18] Add some comments Signed-off-by: Adam Warner --- advanced/Scripts/webpage.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 7cf0ae75..ebeb64fa 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -217,6 +217,7 @@ trust-anchor=.,20326,8,2,E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC68345710423 if [[ "${CONDITIONAL_FORWARDING}" == true ]]; then # Convert legacy "conditional forwarding" to rev-server configuration + # Remove any existing REV_SERVER settings delete_setting "REV_SERVER" delete_setting "REV_SERVER_DOMAIN" delete_setting "REV_SERVER_TARGET" @@ -231,6 +232,11 @@ trust-anchor=.,20326,8,2,E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC68345710423 REV_SERVER_TARGET="${CONDITIONAL_FORWARDING_IP}" add_setting "REV_SERVER_TARGET" "${REV_SERVER_TARGET}" + #Convert CONDITIONAL_FORWARDING_REVERSE if neccasery e.g: + # 1.1.168.192.in-addr.arpa to 192.168.1.1/32 + # 1.168.192.in-addr.arpa to 192.168.1.0/24 + # 168.192.in-addr.arpa to 192.168.0.0/16 + # 192.in-addr.arpa to 192.0.0.0/8 search="in-addr.arpa" if [[ "$CONDITIONAL_FORWARDING_REVERSE" == *"$search" ]];then arrRev=(${CONDITIONAL_FORWARDING_REVERSE//./ }) @@ -241,7 +247,8 @@ trust-anchor=.,20326,8,2,E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC68345710423 3 ) REV_SERVER_CIDR="${arrRev[0]}.0.0.0/8";; esac fi - + + # If REV_SERVER_CIDR is not converted by the above, then use the REV_SERVER_TARGET variable to derive it if [ -z "${REV_SERVER_CIDR}" ]; then # Convert existing input to /24 subnet (preserves legacy behavior) # This sed converts "192.168.1.2" to "192.168.1.0/24" From 06c5fe2a89304ce73105964b867e20ee079ce2c9 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Mon, 30 Nov 2020 21:29:54 +0000 Subject: [PATCH 05/18] Set REV_SERVER_CIDR in the else condition if it is not in-addr.arpa Signed-off-by: Adam Warner --- advanced/Scripts/webpage.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index ebeb64fa..e9794cbf 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -246,6 +246,9 @@ trust-anchor=.,20326,8,2,E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC68345710423 4 ) REV_SERVER_CIDR="${arrRev[1]}.${arrRev[0]}.0.0/16";; 3 ) REV_SERVER_CIDR="${arrRev[0]}.0.0.0/8";; esac + else + # Set REV_SERVER_CIDR to whatever value it was set to + REV_SERVER_CIDR="$CONDITIONAL_FORWARDING_REVERSE" fi # If REV_SERVER_CIDR is not converted by the above, then use the REV_SERVER_TARGET variable to derive it From 4093959d3ede4151d5cb4e994f1b2e6ef744b007 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Mon, 30 Nov 2020 21:55:07 +0000 Subject: [PATCH 06/18] Appease stickler Signed-off-by: Adam Warner --- advanced/Scripts/webpage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index e9794cbf..090d2a3a 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -239,7 +239,7 @@ trust-anchor=.,20326,8,2,E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC68345710423 # 192.in-addr.arpa to 192.0.0.0/8 search="in-addr.arpa" if [[ "$CONDITIONAL_FORWARDING_REVERSE" == *"$search" ]];then - arrRev=(${CONDITIONAL_FORWARDING_REVERSE//./ }) + arrRev=("${CONDITIONAL_FORWARDING_REVERSE//./ }") case ${#arrRev[@]} in 6 ) REV_SERVER_CIDR="${arrRev[3]}.${arrRev[2]}.${arrRev[1]}.${arrRev[0]}/32";; 5 ) REV_SERVER_CIDR="${arrRev[2]}.${arrRev[1]}.${arrRev[0]}.0/24";; From 58bc98ca44a457486862f738373e0d4114c878af Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Mon, 30 Nov 2020 22:30:59 +0000 Subject: [PATCH 07/18] Update advanced/Scripts/webpage.sh Signed-off-by: Adam Warner --- advanced/Scripts/webpage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 090d2a3a..f7598000 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -232,7 +232,7 @@ trust-anchor=.,20326,8,2,E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC68345710423 REV_SERVER_TARGET="${CONDITIONAL_FORWARDING_IP}" add_setting "REV_SERVER_TARGET" "${REV_SERVER_TARGET}" - #Convert CONDITIONAL_FORWARDING_REVERSE if neccasery e.g: + #Convert CONDITIONAL_FORWARDING_REVERSE if necessary e.g: # 1.1.168.192.in-addr.arpa to 192.168.1.1/32 # 1.168.192.in-addr.arpa to 192.168.1.0/24 # 168.192.in-addr.arpa to 192.168.0.0/16 From 49810262dbfcaf361d49c63730dc3fb626174c16 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 1 Dec 2020 09:16:50 +0100 Subject: [PATCH 08/18] When there is a Pi-hole domain set and "Never forward non-FQDNs" is ticked, we add to tell FTL that this domain is purely local and FTL may answer queries from /etc/hosts or DHCP but should never forward queries on that domain to any upstream servers Signed-off-by: DL6ER --- advanced/Scripts/webpage.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 15471ad4..21328dc1 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -253,6 +253,13 @@ trust-anchor=.,20326,8,2,E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC68345710423 # This follows https://support.mozilla.org/en-US/kb/configuring-networks-disable-dns-over-https # (sourced 7th September 2019) add_dnsmasq_setting "server=/use-application-dns.net/" + + # We need to process DHCP settings here as well to account for possible + # changes in the non-FQDN forwarding. This cannot be done in 01-pihole.conf + # as we don't want to delete all local=/.../ lines so it's much safer to + # simply rewrite the entire corresponding config file (which is what the + # DHCP settings subroutie is doing) + ProcessDHCPSettings } SetDNSServers() { @@ -375,6 +382,11 @@ dhcp-leasefile=/etc/pihole/dhcp.leases if [[ "${PIHOLE_DOMAIN}" != "none" ]]; then echo "domain=${PIHOLE_DOMAIN}" >> "${dhcpconfig}" + + # When there is a Pi-hole domain set and "Never forward non-FQDNs" is + # ticked, we add `local=/domain/` to tell FTL that this domain is purely + # local and FTL may answer queries from /etc/hosts or DHCP but should + # never forward queries on that domain to any upstream servers if [[ "${DNS_FQDN_REQUIRED}" == true ]]; then echo "local=/${PIHOLE_DOMAIN}/" >> "${dhcpconfig}" fi From 3e73782f0e5b5463b5756f1e607e6b0cfee4411a Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 1 Dec 2020 10:02:31 +0000 Subject: [PATCH 09/18] Remove Travis CI config Create Github Actions config Split tox ini into one per supported distro so they can be run seperately Signed-off-by: Adam Warner --- .github/workflows/test.yml | 25 ++ .travis.yml | 5 - autotest | 1 - ...ntos_7.Dockerfile => _centos_7.Dockerfile} | 0 ...ntos_8.Dockerfile => _centos_8.Dockerfile} | 0 ...an_10.Dockerfile => _debian_10.Dockerfile} | 0 ...bian_9.Dockerfile => _debian_9.Dockerfile} | 0 ...ra_31.Dockerfile => _fedora_31.Dockerfile} | 0 ...ra_32.Dockerfile => _fedora_32.Dockerfile} | 0 ...tu_16.Dockerfile => _ubuntu_16.Dockerfile} | 2 +- ...tu_18.Dockerfile => _ubuntu_18.Dockerfile} | 0 ...tu_20.Dockerfile => _ubuntu_20.Dockerfile} | 0 test/conftest.py | 12 +- requirements.txt => test/requirements.txt | 0 setup.py => test/setup.py | 0 test/test_000_build_containers.py | 29 -- test/test_centos_7_support.py | 62 ++++ test/test_centos_8_support.py | 67 ++++ test/test_centos_common_support.py | 120 +++++++ test/test_centos_fedora_common_support.py | 66 ++++ test/test_centos_fedora_support.py | 327 ------------------ test/test_fedora_support.py | 24 ++ test/test_shellcheck.py | 18 - test/tox.centos_7.ini | 8 + test/tox.centos_8.ini | 8 + test/tox.debian_10.ini | 8 + test/tox.debian_9.ini | 8 + test/tox.fedora_31.ini | 8 + test/tox.fedora_32.ini | 8 + test/tox.ubuntu_16.ini | 8 + test/tox.ubuntu_18.ini | 8 + test/tox.ubuntu_20.ini | 8 + tox.ini | 16 - 33 files changed, 439 insertions(+), 407 deletions(-) create mode 100644 .github/workflows/test.yml delete mode 100644 .travis.yml delete mode 100755 autotest rename test/{centos_7.Dockerfile => _centos_7.Dockerfile} (100%) rename test/{centos_8.Dockerfile => _centos_8.Dockerfile} (100%) rename test/{debian_10.Dockerfile => _debian_10.Dockerfile} (100%) rename test/{debian_9.Dockerfile => _debian_9.Dockerfile} (100%) rename test/{fedora_31.Dockerfile => _fedora_31.Dockerfile} (100%) rename test/{fedora_32.Dockerfile => _fedora_32.Dockerfile} (100%) rename test/{ubuntu_16.Dockerfile => _ubuntu_16.Dockerfile} (92%) rename test/{ubuntu_18.Dockerfile => _ubuntu_18.Dockerfile} (100%) rename test/{ubuntu_20.Dockerfile => _ubuntu_20.Dockerfile} (100%) rename requirements.txt => test/requirements.txt (100%) rename setup.py => test/setup.py (100%) delete mode 100644 test/test_000_build_containers.py create mode 100644 test/test_centos_7_support.py create mode 100644 test/test_centos_8_support.py create mode 100644 test/test_centos_common_support.py create mode 100644 test/test_centos_fedora_common_support.py delete mode 100644 test/test_centos_fedora_support.py create mode 100644 test/test_fedora_support.py delete mode 100644 test/test_shellcheck.py create mode 100644 test/tox.centos_7.ini create mode 100644 test/tox.centos_8.ini create mode 100644 test/tox.debian_10.ini create mode 100644 test/tox.debian_9.ini create mode 100644 test/tox.fedora_31.ini create mode 100644 test/tox.fedora_32.ini create mode 100644 test/tox.ubuntu_16.ini create mode 100644 test/tox.ubuntu_18.ini create mode 100644 test/tox.ubuntu_20.ini delete mode 100644 tox.ini diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..9145e8a5 --- /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/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..aebf5173 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): ''' @@ -161,4 +153,4 @@ def mock_command_2(script, args, container): def run_script(Pihole, script): result = Pihole.run(script) assert result.rc == 0 - return result + return result \ No newline at end of file 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..78cc6070 --- /dev/null +++ b/test/test_centos_7_support.py @@ -0,0 +1,62 @@ +import pytest +from .conftest import ( + tick_box, + info_box, + cross_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..899cff2f --- /dev/null +++ b/test/test_centos_8_support.py @@ -0,0 +1,67 @@ +import pytest +from .conftest import ( + tick_box, + info_box, + cross_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..4490f220 --- /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 \ No newline at end of file diff --git a/test/test_centos_fedora_common_support.py b/test/test_centos_fedora_common_support.py new file mode 100644 index 00000000..7338f0fc --- /dev/null +++ b/test/test_centos_fedora_common_support.py @@ -0,0 +1,66 @@ +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())) + + +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..a5823883 --- /dev/null +++ b/test/test_fedora_support.py @@ -0,0 +1,24 @@ +import pytest +from .conftest import ( + tick_box, + info_box, + cross_box, + mock_command, +) + + +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/ From 44d020a54c9a722619b7a56d089028b2cb0275f3 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 1 Dec 2020 10:09:16 +0000 Subject: [PATCH 10/18] Appease codefactor.io Signed-off-by: Adam Warner --- .github/workflows/test.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9145e8a5..8e19e550 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,10 +10,10 @@ jobs: 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] + distro: [debian_9, debian_10, ubuntu_16, ubuntu_18, ubuntu_20, centos_7, centos_8, fedora_31, fedora_32] env: - DISTRO: ${{matrix.distro}} - steps: + DISTRO: ${{matrix.distro}} + steps: - uses: actions/checkout@v1 - name: Set up Python 3.7 uses: actions/setup-python@v2 From d1539335bca135470d3b5fd8039c6e7600c802c3 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 1 Dec 2020 10:13:36 +0000 Subject: [PATCH 11/18] appease stickler-ci Signed-off-by: Adam Warner --- test/conftest.py | 2 +- test/test_centos_7_support.py | 2 -- test/test_centos_8_support.py | 2 -- test/test_centos_common_support.py | 2 +- test/test_centos_fedora_common_support.py | 3 +-- test/test_fedora_support.py | 9 --------- 6 files changed, 3 insertions(+), 17 deletions(-) diff --git a/test/conftest.py b/test/conftest.py index aebf5173..07166ec5 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -153,4 +153,4 @@ def mock_command_2(script, args, container): def run_script(Pihole, script): result = Pihole.run(script) assert result.rc == 0 - return result \ No newline at end of file + return result diff --git a/test/test_centos_7_support.py b/test/test_centos_7_support.py index 78cc6070..2f744ab4 100644 --- a/test/test_centos_7_support.py +++ b/test/test_centos_7_support.py @@ -1,8 +1,6 @@ -import pytest from .conftest import ( tick_box, info_box, - cross_box, mock_command, ) diff --git a/test/test_centos_8_support.py b/test/test_centos_8_support.py index 899cff2f..d3e83658 100644 --- a/test/test_centos_8_support.py +++ b/test/test_centos_8_support.py @@ -1,8 +1,6 @@ -import pytest from .conftest import ( tick_box, info_box, - cross_box, mock_command, ) diff --git a/test/test_centos_common_support.py b/test/test_centos_common_support.py index 4490f220..fdf43cba 100644 --- a/test/test_centos_common_support.py +++ b/test/test_centos_common_support.py @@ -117,4 +117,4 @@ def test_php_version_lt_7_detected_upgrade_user_optin_centos(Pihole): 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 \ No newline at end of file + assert int(updated_php_version) == 7 diff --git a/test/test_centos_fedora_common_support.py b/test/test_centos_fedora_common_support.py index 7338f0fc..21ae6d1d 100644 --- a/test/test_centos_fedora_common_support.py +++ b/test/test_centos_fedora_common_support.py @@ -1,7 +1,5 @@ -import pytest from .conftest import ( tick_box, - info_box, cross_box, mock_command, ) @@ -52,6 +50,7 @@ def test_selinux_permissive(Pihole): assert expected_stdout in check_selinux.stdout assert check_selinux.rc == 0 + def test_selinux_disabled(Pihole): ''' confirms installer continues when SELinux is Disabled diff --git a/test/test_fedora_support.py b/test/test_fedora_support.py index a5823883..473b2e96 100644 --- a/test/test_fedora_support.py +++ b/test/test_fedora_support.py @@ -1,12 +1,3 @@ -import pytest -from .conftest import ( - tick_box, - info_box, - cross_box, - mock_command, -) - - def test_epel_and_remi_not_installed_fedora(Pihole): ''' confirms installer does not attempt to install EPEL/REMI repositories From f44b2f6aa3d1481de70efc674b6ca2dec44173aa Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 1 Dec 2020 17:27:21 +0000 Subject: [PATCH 12/18] Update advanced/Scripts/webpage.sh Signed-off-by: Adam Warner Co-authored-by: DL6ER --- advanced/Scripts/webpage.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index f7598000..e173759b 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -237,8 +237,7 @@ trust-anchor=.,20326,8,2,E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC68345710423 # 1.168.192.in-addr.arpa to 192.168.1.0/24 # 168.192.in-addr.arpa to 192.168.0.0/16 # 192.in-addr.arpa to 192.0.0.0/8 - search="in-addr.arpa" - if [[ "$CONDITIONAL_FORWARDING_REVERSE" == *"$search" ]];then + if [[ "${CONDITIONAL_FORWARDING_REVERSE}" == *"in-addr.arpa" ]];then arrRev=("${CONDITIONAL_FORWARDING_REVERSE//./ }") case ${#arrRev[@]} in 6 ) REV_SERVER_CIDR="${arrRev[3]}.${arrRev[2]}.${arrRev[1]}.${arrRev[0]}/32";; From 454c9a411c34e699484c335ffcc8e4a3b18c034c Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 1 Dec 2020 17:27:36 +0000 Subject: [PATCH 13/18] Update advanced/Scripts/webpage.sh Signed-off-by: Adam Warner Co-authored-by: DL6ER --- advanced/Scripts/webpage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index e173759b..ef1d3ac9 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -247,7 +247,7 @@ trust-anchor=.,20326,8,2,E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC68345710423 esac else # Set REV_SERVER_CIDR to whatever value it was set to - REV_SERVER_CIDR="$CONDITIONAL_FORWARDING_REVERSE" + REV_SERVER_CIDR="${CONDITIONAL_FORWARDING_REVERSE}" fi # If REV_SERVER_CIDR is not converted by the above, then use the REV_SERVER_TARGET variable to derive it From d0af1a950bd45ed4eeb3ed3b82d2624a4f7efc63 Mon Sep 17 00:00:00 2001 From: Reto Gantenbein Date: Tue, 1 Dec 2020 23:43:55 +0100 Subject: [PATCH 14/18] Ensure x86_64 processor architecture is listed as supported Signed-off-by: Reto Gantenbein --- advanced/Scripts/piholeDebug.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 5c2b5f1c..e300c14a 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}" ;; From 36937b19132df631220e4a5912f889e58a357cbc Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 2 Dec 2020 20:52:39 +0100 Subject: [PATCH 15/18] Strip such lines starting with a #. Do not silently truncate lines if they have a # somewhere in between (like server=127.0.0.1#5353) Signed-off-by: DL6ER --- advanced/Scripts/piholeDebug.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 5c2b5f1c..30ca6031 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -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 From 61f13a334d2fb7ca81a3a47c7d9fc599a72d9164 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Wed, 2 Dec 2020 20:19:59 +0000 Subject: [PATCH 16/18] Don't delete an existing directory and clone our repo in its place. TODO: Something more robust Signed-off-by: Adam Warner --- automated install/basic-install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index bab6471e..5470a9fb 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -528,8 +528,8 @@ 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 + return 1 fi # Clone the repo and return the return code from this command git clone -q --depth 20 "${remoteRepo}" "${directory}" &> /dev/null || return $? From 641951b3a041a0a99c295fc977a1edef9fb87262 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Wed, 2 Dec 2020 20:35:40 +0000 Subject: [PATCH 17/18] add some meaningful outputSigned-off-by: Adam Warner --- automated install/basic-install.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 5470a9fb..9d5b4465 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -529,6 +529,8 @@ make_repo() { # If the directory exists, if [[ -d "${directory}" ]]; then # 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}" + printf "%b %b%s\\n" "${OVER}" "${CROSS}" "${str}" return 1 fi # Clone the repo and return the return code from this command From e47eb30a6e269895346dd4299591c930e631388f Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Wed, 2 Dec 2020 20:49:07 +0000 Subject: [PATCH 18/18] Update automated install/basic-install.sh Signed-off-by: Adam Warner --- automated install/basic-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 9d5b4465..45e96354 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -529,7 +529,7 @@ make_repo() { # If the directory exists, if [[ -d "${directory}" ]]; then # 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}" + str="Unable to clone ${remoteRepo} into ${directory} : Directory already exists" printf "%b %b%s\\n" "${OVER}" "${CROSS}" "${str}" return 1 fi