diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index b23ee79e..797c0c76 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1431,13 +1431,7 @@ installConfigs() { # Make the directories if they do not exist and set the owners mkdir -p /run/lighttpd chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /run/lighttpd - test -d /var/cache - local varcache=$? mkdir -p /var/cache/lighttpd/compress - if [[ ! "${varcache}" -eq 0 ]]; then - chmod a+rx /var/cache - fi - chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/cache/lighttpd chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/cache/lighttpd/compress mkdir -p /var/cache/lighttpd/uploads chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/cache/lighttpd/uploads diff --git a/test/conftest.py b/test/conftest.py index 5b8be41e..e6a60273 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -121,6 +121,33 @@ def mock_command(script, args, container): scriptlog=script)) +def mock_command_run(script, args, container): + ''' + Allows for setup of commands we don't really want to have to run for real + in unit tests + ''' + full_script_path = '/usr/local/bin/{}'.format(script) + mock_script = dedent('''\ + #!/bin/bash -e + echo "\$0 \$@" >> /var/log/{script} + case "\$1 \$2" in'''.format(script=script)) + for k, v in args.items(): + case = dedent(''' + \"{arg}\") + echo {res} + exit {retcode} + ;;'''.format(arg=k, res=v[0], retcode=v[1])) + mock_script += case + mock_script += dedent(''' + esac''') + container.run(''' + cat < {script}\n{content}\nEOF + chmod +x {script} + rm -f /var/log/{scriptlog}'''.format(script=full_script_path, + content=mock_script, + scriptlog=script)) + + def mock_command_2(script, args, container): ''' Allows for setup of commands we don't really want to have to run for real @@ -147,7 +174,6 @@ def mock_command_2(script, args, container): content=mock_script, scriptlog=script)) - def run_script(Pihole, script): result = Pihole.run(script) assert result.rc == 0 diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 0b7792bf..c4f96705 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -7,6 +7,7 @@ from .conftest import ( info_box, cross_box, mock_command, + mock_command_run, mock_command_2, run_script ) @@ -421,7 +422,7 @@ def test_installPihole_fresh_install_readableFiles(Pihole): actual_rc = Pihole.run(check_pihole).rc -@pytest.mark.parametrize("test_webpage", [False]) +@pytest.mark.parametrize("test_webpage", [True]) def test_installPihole_fresh_install_readableBlockpage(Pihole, test_webpage): ''' confirms all web page assets from Core repo are readable @@ -429,11 +430,14 @@ def test_installPihole_fresh_install_readableBlockpage(Pihole, test_webpage): ''' # TODO: also add IP address from setupVars? # TODO: pi.hole can not be resolved because of some error in FTL or resolved - piholeWebpage = ["http://127.0.0.1/admin", "http://pi.hole/admin"] + piholeWebpage = [ + "http://127.0.0.1/admin", + "http://pi.hole/admin" + ] # Whiptail dialog returns Cancel for user prompt mock_command('whiptail', {'*': ('', '0')}, Pihole) # mock systemctl to start lighttpd and FTL - ligthttpdcommand = dedent(r'''\" + ligthttpdcommand = dedent(r'''\"\" echo 'starting lighttpd with {}' if [ command -v "apt-get" >/dev/null 2>&1 ]; then LIGHTTPD_USER="www-data" @@ -444,8 +448,10 @@ def test_installPihole_fresh_install_readableBlockpage(Pihole, test_webpage): fi mkdir -p "{run}" chown {usergroup} "{run}" - mkdir -p "{compress}" + mkdir -p "{cache}" + chown {usergroup} "/var/cache" chown {usergroup} "{cache}" + mkdir -p "{compress}" chown {usergroup} "{compress}" mkdir -p "{uploads}" chown {usergroup} "{uploads}" @@ -461,7 +467,7 @@ def test_installPihole_fresh_install_readableBlockpage(Pihole, test_webpage): find "{uploads}" -type f -exec chmod 0666 {chmodarg} \;; /usr/sbin/lighttpd -tt -f '{config}' /usr/sbin/lighttpd -f '{config}' - echo \"'''.format( + echo \"\"'''.format( '{}', usergroup='${{LIGHTTPD_USER}}:${{LIGHTTPD_GROUP}}', chmodarg='{{}}', @@ -472,10 +478,10 @@ def test_installPihole_fresh_install_readableBlockpage(Pihole, test_webpage): compress='/var/cache/lighttpd/compress' ) ) - FTLcommand = dedent('''\" + FTLcommand = dedent('''\"\" /etc/init.d/pihole-FTL restart - echo \"''') - mock_command_2( + echo \"\"''') + mock_command_run( 'systemctl', { 'enable lighttpd': ( @@ -517,6 +523,11 @@ def test_installPihole_fresh_install_readableBlockpage(Pihole, test_webpage): setup_var_file += "INSTALL_WEB_INTERFACE=true\n" setup_var_file += "EOF\n" Pihole.run(setup_var_file) + # TODO: set in dependance of currently build branch + b = Pihole.run('mkdir -p /etc/pihole && echo "development" > /etc/pihole/ftlbranch'); + assert 0 == b.rc + b = Pihole.run('cat /etc/pihole/ftlbranch'); + print(b.stdout) installWeb = Pihole.run(''' export TERM=xterm export DEBIAN_FRONTEND=noninteractive