From 33e57350530dd5c4ee44051e8931604bebae1130 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 28 Jul 2020 19:06:54 +0100 Subject: [PATCH 01/11] Change base images for test containers to latest supported version Signed-off-by: Adam Warner --- test/debian.Dockerfile | 2 +- test/fedora.Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/debian.Dockerfile b/test/debian.Dockerfile index 66436f1a..9b72fc6a 100644 --- a/test/debian.Dockerfile +++ b/test/debian.Dockerfile @@ -1,4 +1,4 @@ -FROM buildpack-deps:jessie-scm +FROM buildpack-deps:buster-scm ENV GITDIR /etc/.pihole ENV SCRIPTDIR /opt/pihole diff --git a/test/fedora.Dockerfile b/test/fedora.Dockerfile index a06fc007..869efb2b 100644 --- a/test/fedora.Dockerfile +++ b/test/fedora.Dockerfile @@ -1,4 +1,4 @@ -FROM fedora:30 +FROM fedora:32 ENV GITDIR /etc/.pihole ENV SCRIPTDIR /opt/pihole From c9edcfa33563e849d98e47143dc4f4d3e7cd44af Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 28 Jul 2020 19:07:17 +0100 Subject: [PATCH 02/11] add test to check "os_check" works Signed-off-by: Adam Warner --- test/test_automated_install.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 342d8a3c..c0648b71 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -561,3 +561,17 @@ def test_validate_ip_invalid_letters(Pihole): ''') assert output.rc == 1 + +def test_os_check_pases(Pihole): + ''' Confirms OS meets the requirements ''' + Pihole.run(''' + source /opt/pihole/basic-install.sh + distro_check + install_dependent_packages ${INSTALLER_DEPS[@]} + ''') + detectOS = Pihole.run(''' + source /opt/pihole/basic-install.sh + os_check + ''') + expected_stdout = 'Supported OS detected' + assert expected_stdout in detectOS.stdout From 5648ad6b61406e560b3a3ce31032d64a3fbdc0d1 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 28 Jul 2020 19:07:50 +0100 Subject: [PATCH 03/11] [Experiment] up python to 3.7 Signed-off-by: Adam Warner --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 249575b6..346ca886 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py36 +envlist = py37 [testenv] whitelist_externals = docker From 5aab68ab41cf94a0b95faa9e4cd63b1f09e580f9 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Wed, 29 Jul 2020 17:52:53 +0100 Subject: [PATCH 04/11] Update test/test_automated_install.py Co-authored-by: pvogt09 <50047961+pvogt09@users.noreply.github.com> --- test/test_automated_install.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_automated_install.py b/test/test_automated_install.py index c0648b71..4f6e2020 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -562,7 +562,7 @@ def test_validate_ip_invalid_letters(Pihole): assert output.rc == 1 -def test_os_check_pases(Pihole): +def test_os_check_passes(Pihole): ''' Confirms OS meets the requirements ''' Pihole.run(''' source /opt/pihole/basic-install.sh From 2c461460dbdedbd34451e9ff9a3657e65fbbaa3f Mon Sep 17 00:00:00 2001 From: bcambl Date: Sat, 8 Aug 2020 11:15:49 -0600 Subject: [PATCH 05/11] test with both centos7 and centos8 images Signed-off-by: bcambl --- test/centos.Dockerfile | 2 +- test/centos7.Dockerfile | 16 ++++++++++++++++ test/conftest.py | 2 +- test/test_000_build_containers.py | 1 + test/test_centos_fedora_support.py | 8 ++++---- tox.ini | 1 + 6 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 test/centos7.Dockerfile diff --git a/test/centos.Dockerfile b/test/centos.Dockerfile index 00543b67..7444551b 100644 --- a/test/centos.Dockerfile +++ b/test/centos.Dockerfile @@ -1,4 +1,4 @@ -FROM centos:7 +FROM centos:8 ENV GITDIR /etc/.pihole ENV SCRIPTDIR /opt/pihole diff --git a/test/centos7.Dockerfile b/test/centos7.Dockerfile new file mode 100644 index 00000000..00543b67 --- /dev/null +++ b/test/centos7.Dockerfile @@ -0,0 +1,16 @@ +FROM centos:7 + +ENV GITDIR /etc/.pihole +ENV SCRIPTDIR /opt/pihole + +RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole +ADD . $GITDIR +RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $SCRIPTDIR/ +ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR + +RUN true && \ + chmod +x $SCRIPTDIR/* + +ENV PH_TEST true + +#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \ diff --git a/test/conftest.py b/test/conftest.py index 5b8be41e..69926eaf 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -69,7 +69,7 @@ def args(request): return '-t -d' -@pytest.fixture(params=['debian', 'centos', 'fedora']) +@pytest.fixture(params=['debian', 'centos7', 'centos', 'fedora']) def tag(request): ''' consumed by image to make the test matrix diff --git a/test/test_000_build_containers.py b/test/test_000_build_containers.py index 184052f3..0f3e2d1a 100644 --- a/test/test_000_build_containers.py +++ b/test/test_000_build_containers.py @@ -9,6 +9,7 @@ run_local = testinfra.get_backend( @pytest.mark.parametrize("image,tag", [ ('test/debian.Dockerfile', 'pytest_pihole:debian'), + ('test/centos7.Dockerfile', 'pytest_pihole:centos7'), ('test/centos.Dockerfile', 'pytest_pihole:centos'), ('test/fedora.Dockerfile', 'pytest_pihole:fedora'), ]) diff --git a/test/test_centos_fedora_support.py b/test/test_centos_fedora_support.py index 4b405920..e0d25634 100644 --- a/test/test_centos_fedora_support.py +++ b/test/test_centos_fedora_support.py @@ -123,7 +123,7 @@ def test_enable_epel_repository_centos(Pihole): assert epel_package.is_installed -@pytest.mark.parametrize("tag", [('centos'), ]) +@pytest.mark.parametrize("tag", [('centos7'), ('centos8'), ]) def test_php_upgrade_default_optout_centos(Pihole): ''' confirms the default behavior to opt-out of installing PHP7 from REMI @@ -139,7 +139,7 @@ def test_php_upgrade_default_optout_centos(Pihole): assert not remi_package.is_installed -@pytest.mark.parametrize("tag", [('centos'), ]) +@pytest.mark.parametrize("tag", [('centos7'), ('centos8'), ]) def test_php_upgrade_user_optout_centos(Pihole): ''' confirms installer behavior when user opt-out of installing PHP7 from REMI @@ -158,7 +158,7 @@ def test_php_upgrade_user_optout_centos(Pihole): assert not remi_package.is_installed -@pytest.mark.parametrize("tag", [('centos'), ]) +@pytest.mark.parametrize("tag", [('centos7'), ('centos8'), ]) def test_php_upgrade_user_optin_centos(Pihole): ''' confirms installer behavior when user opt-in to installing PHP7 from REMI @@ -181,7 +181,7 @@ def test_php_upgrade_user_optin_centos(Pihole): assert remi_package.is_installed -@pytest.mark.parametrize("tag", [('centos'), ]) +@pytest.mark.parametrize("tag", [('centos7'), ('centos8'), ]) 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 diff --git a/tox.ini b/tox.ini index 346ca886..49c99066 100644 --- a/tox.ini +++ b/tox.ini @@ -5,6 +5,7 @@ envlist = py37 whitelist_externals = docker deps = -rrequirements.txt commands = docker build -f test/debian.Dockerfile -t pytest_pihole:debian . + docker build -f test/centos7.Dockerfile -t pytest_pihole:centos7 . docker build -f test/centos.Dockerfile -t pytest_pihole:centos . docker build -f test/fedora.Dockerfile -t pytest_pihole:fedora . pytest {posargs:-vv -n auto} -m "not build_stage" ./test/ From 05b6717187cbc8d300401c7a2e5b862167690d02 Mon Sep 17 00:00:00 2001 From: bcambl Date: Sun, 9 Aug 2020 12:30:51 -0600 Subject: [PATCH 06/11] test PHP optin/optout separately for CentOS 7 & 8 Signed-off-by: bcambl --- test/test_centos_fedora_support.py | 85 ++++++++++++++++++++++++++---- 1 file changed, 74 insertions(+), 11 deletions(-) diff --git a/test/test_centos_fedora_support.py b/test/test_centos_fedora_support.py index e0d25634..9f772f4f 100644 --- a/test/test_centos_fedora_support.py +++ b/test/test_centos_fedora_support.py @@ -88,7 +88,7 @@ def test_epel_and_remi_not_installed_fedora(Pihole): assert not remi_package.is_installed -@pytest.mark.parametrize("tag", [('centos'), ]) +@pytest.mark.parametrize("tag", [('centos7'), ('centos'), ]) def test_release_supported_version_check_centos(Pihole): ''' confirms installer exits on unsupported releases of CentOS @@ -105,7 +105,7 @@ def test_release_supported_version_check_centos(Pihole): assert expected_stdout in distro_check.stdout -@pytest.mark.parametrize("tag", [('centos'), ]) +@pytest.mark.parametrize("tag", [('centos7'), ('centos'), ]) def test_enable_epel_repository_centos(Pihole): ''' confirms the EPEL package repository is enabled when installed on CentOS @@ -123,8 +123,8 @@ def test_enable_epel_repository_centos(Pihole): assert epel_package.is_installed -@pytest.mark.parametrize("tag", [('centos7'), ('centos8'), ]) -def test_php_upgrade_default_optout_centos(Pihole): +@pytest.mark.parametrize("tag", [('centos7'), ]) +def test_php_upgrade_default_optout_centos_eq_7(Pihole): ''' confirms the default behavior to opt-out of installing PHP7 from REMI ''' @@ -139,8 +139,26 @@ def test_php_upgrade_default_optout_centos(Pihole): assert not remi_package.is_installed -@pytest.mark.parametrize("tag", [('centos7'), ('centos8'), ]) -def test_php_upgrade_user_optout_centos(Pihole): +@pytest.mark.parametrize("tag", [('centos'), ]) +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", [('centos7'), ]) +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) @@ -158,8 +176,29 @@ def test_php_upgrade_user_optout_centos(Pihole): assert not remi_package.is_installed -@pytest.mark.parametrize("tag", [('centos7'), ('centos8'), ]) -def test_php_upgrade_user_optin_centos(Pihole): +@pytest.mark.parametrize("tag", [('centos'), ]) +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", [('centos7'), ]) +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) @@ -181,7 +220,31 @@ def test_php_upgrade_user_optin_centos(Pihole): assert remi_package.is_installed -@pytest.mark.parametrize("tag", [('centos7'), ('centos8'), ]) +@pytest.mark.parametrize("tag", [('centos'), ]) +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", [('centos7'), ('centos'), ]) 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 @@ -204,7 +267,7 @@ def test_php_version_lt_7_detected_upgrade_default_optout_centos(Pihole): assert not remi_package.is_installed -@pytest.mark.parametrize("tag", [('centos'), ]) +@pytest.mark.parametrize("tag", [('centos7'), ('centos'), ]) 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 @@ -229,7 +292,7 @@ def test_php_version_lt_7_detected_upgrade_user_optout_centos(Pihole): assert not remi_package.is_installed -@pytest.mark.parametrize("tag", [('centos'), ]) +@pytest.mark.parametrize("tag", [('centos7'), ('centos'), ]) 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 From a7c58e7112ed9463d91a210c993dfcfc622c0bc6 Mon Sep 17 00:00:00 2001 From: bcambl Date: Sun, 9 Aug 2020 13:02:48 -0600 Subject: [PATCH 07/11] E302 expected 2 blank lines, found 1 Signed-off-by: bcambl --- test/test_automated_install.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 4f6e2020..8d894b5a 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -562,6 +562,7 @@ def test_validate_ip_invalid_letters(Pihole): assert output.rc == 1 + def test_os_check_passes(Pihole): ''' Confirms OS meets the requirements ''' Pihole.run(''' From 660c17814d5698e2c1b4918b0ca3e131e2650154 Mon Sep 17 00:00:00 2001 From: bcambl Date: Sun, 9 Aug 2020 15:03:50 -0600 Subject: [PATCH 08/11] E128 continuation line under-indented for visual indent Signed-off-by: bcambl --- test/test_centos_fedora_support.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_centos_fedora_support.py b/test/test_centos_fedora_support.py index 9f772f4f..b4ae7c89 100644 --- a/test/test_centos_fedora_support.py +++ b/test/test_centos_fedora_support.py @@ -238,7 +238,7 @@ def test_php_upgrade_user_optin_skipped_centos_gte_8(Pihole): '(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') + 'been enabled for PHP7') assert unexpected_stdout not in distro_check.stdout remi_package = Pihole.package('remi-release') assert not remi_package.is_installed From ee556088b5dea283ec63d0c82b147d7f434242cd Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 23 Oct 2020 23:05:41 +0100 Subject: [PATCH 09/11] Fake OS details in /etc/os-release and confirm install fails Signed-off-by: Adam Warner --- test/test_automated_install.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 8d894b5a..300f622e 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -563,6 +563,24 @@ def test_validate_ip_invalid_letters(Pihole): assert output.rc == 1 +def test_os_check_fails(Pihole): + ''' Confirms install fails on unsupported OS ''' + Pihole.run(''' + source /opt/pihole/basic-install.sh + distro_check + install_dependent_packages ${INSTALLER_DEPS[@]} + cat < /etc/os-release + ID=UnsupportedOS + VERSION_ID="2" + EOT + ''') + detectOS = Pihole.run('''t + source /opt/pihole/basic-install.sh + os_check + ''') + expected_stdout = 'Unsupported OS detected: UnsupportedOS' + assert expected_stdout in detectOS.stdout + def test_os_check_passes(Pihole): ''' Confirms OS meets the requirements ''' Pihole.run(''' @@ -575,4 +593,4 @@ def test_os_check_passes(Pihole): os_check ''') expected_stdout = 'Supported OS detected' - assert expected_stdout in detectOS.stdout + assert expected_stdout in detectOS.stdout \ No newline at end of file From fb454ebe145dc922582bf9d0ee44f12aba977032 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 23 Oct 2020 23:09:07 +0100 Subject: [PATCH 10/11] fix stickler complaints Signed-off-by: Adam Warner --- test/test_automated_install.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 300f622e..f6b5a87e 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -581,6 +581,7 @@ def test_os_check_fails(Pihole): expected_stdout = 'Unsupported OS detected: UnsupportedOS' assert expected_stdout in detectOS.stdout + def test_os_check_passes(Pihole): ''' Confirms OS meets the requirements ''' Pihole.run(''' @@ -593,4 +594,4 @@ def test_os_check_passes(Pihole): os_check ''') expected_stdout = 'Supported OS detected' - assert expected_stdout in detectOS.stdout \ No newline at end of file + assert expected_stdout in detectOS.stdout From c80f0766c55de16c8ea4178f1ff4c73b06b20ee6 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Mon, 26 Oct 2020 17:56:17 +0000 Subject: [PATCH 11/11] drop debian/fedora container versions to lowest supported Signed-off-by: Adam Warner --- test/debian.Dockerfile | 2 +- test/fedora.Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/debian.Dockerfile b/test/debian.Dockerfile index 9b72fc6a..d6609ba3 100644 --- a/test/debian.Dockerfile +++ b/test/debian.Dockerfile @@ -1,4 +1,4 @@ -FROM buildpack-deps:buster-scm +FROM buildpack-deps:stretch-scm ENV GITDIR /etc/.pihole ENV SCRIPTDIR /opt/pihole diff --git a/test/fedora.Dockerfile b/test/fedora.Dockerfile index 869efb2b..02dcb733 100644 --- a/test/fedora.Dockerfile +++ b/test/fedora.Dockerfile @@ -1,4 +1,4 @@ -FROM fedora:32 +FROM fedora:31 ENV GITDIR /etc/.pihole ENV SCRIPTDIR /opt/pihole