From 5b43f1393527b49a557c3f84a72b26155831091c Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 27 Jan 2017 20:24:20 -0800 Subject: [PATCH 1/6] Fresh install web page directory tests --- automated install/basic-install.sh | 2 +- test/test_automated_install.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index a98eb3aa..16b72230 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -809,7 +809,7 @@ installPiholeWeb() { if [ -f "/var/www/html/pihole/blockingpage.css" ]; then echo "::: Existing blockingpage.css detected, not overwriting" else - echo -n "::: index.css missing, replacing... " + echo -n "::: blockingpage.css missing, replacing... " cp /etc/.pihole/advanced/blockingpage.css /var/www/html/pihole echo " done!" fi diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 211364ed..29c62f45 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -167,6 +167,20 @@ def test_configureFirewall_IPTables_enabled_not_exist_no_errors(Pihole): assert 'iptables -I INPUT 1 -p tcp -m tcp --dport 53 -j ACCEPT' in firewall_calls assert 'iptables -I INPUT 1 -p udp -m udp --dport 53 -j ACCEPT' in firewall_calls +def test_installPiholeWeb_fresh_install_no_errors(Pihole): + ''' confirms all web page assets from Core repo are installed on a fresh build ''' + installWeb = Pihole.run(''' + source /opt/pihole/basic-install.sh + installPiholeWeb + ''') + assert 'Installing pihole custom index page...' in installWeb.stdout + assert 'No default index.lighttpd.html file found... not backing up' in installWeb.stdout + web_directory = Pihole.run('ls -r /var/www/html/pihole').stdout + assert 'index.php' in web_directory + assert 'index.js' in web_directory + assert 'blockingpage.css' in web_directory + + # Helper functions def mock_command(script, args, container): ''' Allows for setup of commands we don't really want to have to run for real in unit tests ''' From 91bcc18e6a50bb9b57543a82d15f813ea4beac3e Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 27 Jan 2017 20:28:03 -0800 Subject: [PATCH 2/6] Make full path to directory for pihole web page. --- automated install/basic-install.sh | 2 +- test/test_automated_install.py | 35 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 16b72230..ce5d044e 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -815,7 +815,7 @@ installPiholeWeb() { fi else - mkdir /var/www/html/pihole + mkdir -p /var/www/html/pihole if [ -f /var/www/html/index.lighttpd.html ]; then mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig else diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 29c62f45..2a39085d 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -180,6 +180,41 @@ def test_installPiholeWeb_fresh_install_no_errors(Pihole): assert 'index.js' in web_directory assert 'blockingpage.css' in web_directory +def test_installPiholeWeb_empty_directory_no_errors(Pihole): + ''' confirms all web page assets from Core repo are installed in an emtpy directory ''' + installWeb = Pihole.run(''' + source /opt/pihole/basic-install.sh + mkdir -p /var/www/html/pihole + installPiholeWeb + ''') + assert 'Installing pihole custom index page...' in installWeb.stdout + assert 'No default index.lighttpd.html file found... not backing up' not in installWeb.stdout + assert 'index.php missing, replacing...' in installWeb.stdout + assert 'index.js missing, replacing...' in installWeb.stdout + assert 'blockingpage.css missing, replacing...' in installWeb.stdout + web_directory = Pihole.run('ls -r /var/www/html/pihole').stdout + assert 'index.php' in web_directory + assert 'index.js' in web_directory + assert 'blockingpage.css' in web_directory + +def test_installPiholeWeb_index_php_no_errors(Pihole): + ''' confirms all web page assets from Core repo are installed in an emtpy directory ''' + installWeb = Pihole.run(''' + source /opt/pihole/basic-install.sh + mkdir -p /var/www/html/pihole + touch /var/www/html/index.php + installPiholeWeb + ''') + assert 'Installing pihole custom index page...' in installWeb.stdout + assert 'No default index.lighttpd.html file found... not backing up' not in installWeb.stdout + assert 'Existing index.php detected, not overwriting' in installWeb.stdout + assert 'index.js missing, replacing...' in installWeb.stdout + assert 'blockingpage.css missing, replacing...' in installWeb.stdout + web_directory = Pihole.run('ls -r /var/www/html/pihole').stdout + assert 'index.php' in web_directory + assert 'index.js' in web_directory + assert 'blockingpage.css' in web_directory + # Helper functions def mock_command(script, args, container): From 28eb3487070f54abc9ed53a4a9f2594d64d2a150 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 27 Jan 2017 21:23:49 -0800 Subject: [PATCH 3/6] Individual Page tests --- test/test_automated_install.py | 39 ++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 2a39085d..b7c82f88 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -198,11 +198,11 @@ def test_installPiholeWeb_empty_directory_no_errors(Pihole): assert 'blockingpage.css' in web_directory def test_installPiholeWeb_index_php_no_errors(Pihole): - ''' confirms all web page assets from Core repo are installed in an emtpy directory ''' + ''' confirms all web page assets from Core repo are installed when necessary ''' installWeb = Pihole.run(''' source /opt/pihole/basic-install.sh mkdir -p /var/www/html/pihole - touch /var/www/html/index.php + touch /var/www/html/pihole/index.php installPiholeWeb ''') assert 'Installing pihole custom index page...' in installWeb.stdout @@ -215,6 +215,41 @@ def test_installPiholeWeb_index_php_no_errors(Pihole): assert 'index.js' in web_directory assert 'blockingpage.css' in web_directory +def test_installPiholeWeb_index_js_no_errors(Pihole): + ''' confirms all web page assets from Core repo are installed when necessary ''' + installWeb = Pihole.run(''' + source /opt/pihole/basic-install.sh + mkdir -p /var/www/html/pihole + touch /var/www/html/pihole/index.js + installPiholeWeb + ''') + assert 'Installing pihole custom index page...' in installWeb.stdout + assert 'No default index.lighttpd.html file found... not backing up' not in installWeb.stdout + assert 'index.php missing, replacing...' in installWeb.stdout + assert 'Existing index.js detected, not overwriting' in installWeb.stdout + assert 'blockingpage.css missing, replacing...' in installWeb.stdout + web_directory = Pihole.run('ls -r /var/www/html/pihole').stdout + assert 'index.php' in web_directory + assert 'index.js' in web_directory + assert 'blockingpage.css' in web_directory + +def test_installPiholeWeb_blockingpage_css_no_errors(Pihole): + ''' confirms all web page assets from Core repo are installed when necessary ''' + installWeb = Pihole.run(''' + source /opt/pihole/basic-install.sh + mkdir -p /var/www/html/pihole + touch /var/www/html/pihole/blockingpage.css + installPiholeWeb + ''') + assert 'Installing pihole custom index page...' in installWeb.stdout + assert 'No default index.lighttpd.html file found... not backing up' not in installWeb.stdout + assert 'index.php missing, replacing...' in installWeb.stdout + assert 'index.js missing, replacing...' in installWeb.stdout + assert 'Existing blockingpage.css detected, not overwriting' in installWeb.stdout + web_directory = Pihole.run('ls -r /var/www/html/pihole').stdout + assert 'index.php' in web_directory + assert 'index.js' in web_directory + assert 'blockingpage.css' in web_directory # Helper functions def mock_command(script, args, container): From d5587e32d01dbd79c218b5b0377fd4a947519017 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 27 Jan 2017 21:29:17 -0800 Subject: [PATCH 4/6] Populated directory test --- test/test_automated_install.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/test_automated_install.py b/test/test_automated_install.py index b7c82f88..f8e2ec3d 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -251,6 +251,29 @@ def test_installPiholeWeb_blockingpage_css_no_errors(Pihole): assert 'index.js' in web_directory assert 'blockingpage.css' in web_directory +def test_installPiholeWeb_already_populated_no_errors(Pihole): + ''' confirms all web page assets from Core repo are installed when necessary ''' + installWeb = Pihole.run(''' + source /opt/pihole/basic-install.sh + mkdir -p /var/www/html/pihole + touch /var/www/html/pihole/index.php + touch /var/www/html/pihole/index.js + touch /var/www/html/pihole/blockingpage.css + installPiholeWeb + ''') + assert 'Installing pihole custom index page...' in installWeb.stdout + assert 'No default index.lighttpd.html file found... not backing up' not in installWeb.stdout + assert 'Existing index.php detected, not overwriting' in installWeb.stdout + assert 'index.php missing, replacing...' not in installWeb.stdout + assert 'Existing index.js detected, not overwriting' in installWeb.stdout + assert 'index.js missing, replacing...' not in installWeb.stdout + assert 'Existing blockingpage.css detected, not overwriting' in installWeb.stdout + assert 'blockingpage.css missing, replacing... ' not in installWeb.stdout + web_directory = Pihole.run('ls -r /var/www/html/pihole').stdout + assert 'index.php' in web_directory + assert 'index.js' in web_directory + assert 'blockingpage.css' in web_directory + # Helper functions def mock_command(script, args, container): ''' Allows for setup of commands we don't really want to have to run for real in unit tests ''' From 1421c31179bae16ea77520c036324150cfcec848 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 27 Jan 2017 21:32:52 -0800 Subject: [PATCH 5/6] `install` index and blockingpage assets. --- 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 ce5d044e..591415bd 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -821,7 +821,7 @@ installPiholeWeb() { else printf "\n:::\tNo default index.lighttpd.html file found... not backing up" fi - cp /etc/.pihole/advanced/index.* /var/www/html/pihole/. + install /etc/.pihole/advanced/{index,blockingpage}.* /var/www/html/pihole/. echo " done!" fi # Install Sudoer file From 52e0aa11afcabd512c1238ff16cb3cdc000fda93 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 27 Jan 2017 21:50:32 -0800 Subject: [PATCH 6/6] Have install create directory --- automated install/basic-install.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 591415bd..9fed0bca 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -815,15 +815,17 @@ installPiholeWeb() { fi else - mkdir -p /var/www/html/pihole + echo "::: Creating directory for blocking page" + install -d /var/www/html/pihole + install -D /etc/.pihole/advanced/{index,blockingpage}.* /var/www/html/pihole/ if [ -f /var/www/html/index.lighttpd.html ]; then mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig else printf "\n:::\tNo default index.lighttpd.html file found... not backing up" fi - install /etc/.pihole/advanced/{index,blockingpage}.* /var/www/html/pihole/. echo " done!" fi + # Install Sudoer file echo ":::" echo -n "::: Installing sudoer file..."