mirror of
https://github.com/pi-hole/pi-hole.git
synced 2025-04-10 01:20:23 +00:00
mock systemctl
Signed-off-by: pvogt09 <50047961+pvogt09@users.noreply.github.com>
This commit is contained in:
parent
ff77aa8da3
commit
e35d49c950
1 changed files with 76 additions and 23 deletions
|
@ -134,24 +134,61 @@ def test_installPiholeWeb_fresh_install_no_errors(Pihole):
|
||||||
|
|
||||||
def test_installPihole_fresh_install_readableBlockpage(Pihole):
|
def test_installPihole_fresh_install_readableBlockpage(Pihole):
|
||||||
'''
|
'''
|
||||||
confirms all web page assets from Core repo are readable by $LIGHTTPD_USER on a fresh build
|
confirms all web page assets from Core repo are readable
|
||||||
|
by $LIGHTTPD_USER on a fresh build
|
||||||
'''
|
'''
|
||||||
|
# mock systemctl to start lighttpd and FTL
|
||||||
|
mock_command_2(
|
||||||
|
'systemctl',
|
||||||
|
{
|
||||||
|
'enable lighttpd': (
|
||||||
|
'',
|
||||||
|
'0'
|
||||||
|
),
|
||||||
|
'restart lighttpd': (
|
||||||
|
'/etc/init.d/lighttpd restart',
|
||||||
|
'0'
|
||||||
|
),
|
||||||
|
'start lighttpd': (
|
||||||
|
'/etc/init.d/lighttpd start',
|
||||||
|
'0'
|
||||||
|
),
|
||||||
|
'enable pihole-FTL': (
|
||||||
|
'',
|
||||||
|
'0'
|
||||||
|
),
|
||||||
|
'restart pihole-FTL': (
|
||||||
|
'/etc/init.d/pihole-FTL start',
|
||||||
|
'0'
|
||||||
|
),
|
||||||
|
'start pihole-FTL': (
|
||||||
|
'/etc/init.d/pihole-FTL start',
|
||||||
|
'0'
|
||||||
|
)
|
||||||
|
},
|
||||||
|
Pihole
|
||||||
|
)
|
||||||
|
# create configuration file
|
||||||
|
setup_var_file = 'cat <<EOF> /etc/pihole/setupVars.conf\n'
|
||||||
|
for k, v in SETUPVARS.items():
|
||||||
|
setup_var_file += "{}={}\n".format(k, v)
|
||||||
|
setup_var_file += "EOF\n"
|
||||||
|
Pihole.run(setup_var_file)
|
||||||
installWeb = Pihole.run('''
|
installWeb = Pihole.run('''
|
||||||
export TERM=xterm
|
export TERM=xterm
|
||||||
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
umask 0027
|
umask 0027
|
||||||
source /opt/pihole/basic-install.sh
|
runUnattended=true
|
||||||
|
useUpdateVars=true
|
||||||
|
source /opt/pihole/basic-install.sh > /dev/null
|
||||||
|
runUnattended=true
|
||||||
|
useUpdateVars=true
|
||||||
main
|
main
|
||||||
echo "LIGHTTPD_USER=${LIGHTTPD_USER}"
|
echo "LIGHTTPD_USER=${LIGHTTPD_USER}"
|
||||||
echo "webroot=${webroot}"
|
echo "webroot=${webroot}"
|
||||||
|
echo "INSTALL_WEB_INTERFACE=${INSTALL_WEB_INTERFACE}"
|
||||||
|
echo "INSTALL_WEB_SERVER=${INSTALL_WEB_SERVER}"
|
||||||
''')
|
''')
|
||||||
# distro_check > /dev/null
|
|
||||||
# clone_or_update_repos
|
|
||||||
# install_dependent_packages ${PIHOLE_WEB_DEPS[@]}
|
|
||||||
# create_pihole_user
|
|
||||||
# installPihole
|
|
||||||
# echo "LIGHTTPD_USER=${LIGHTTPD_USER}"
|
|
||||||
# echo "webroot=${webroot}"
|
|
||||||
# ''')
|
|
||||||
assert 0 == installWeb.rc
|
assert 0 == installWeb.rc
|
||||||
webuser = ''
|
webuser = ''
|
||||||
user = re.findall("^\s*LIGHTTPD_USER=.*$", installWeb.stdout, re.MULTILINE)
|
user = re.findall("^\s*LIGHTTPD_USER=.*$", installWeb.stdout, re.MULTILINE)
|
||||||
|
@ -163,6 +200,18 @@ def test_installPihole_fresh_install_readableBlockpage(Pihole):
|
||||||
webroot = match.replace('webroot=', '').strip()
|
webroot = match.replace('webroot=', '').strip()
|
||||||
if not webroot.strip():
|
if not webroot.strip():
|
||||||
webroot = '/var/www/html'
|
webroot = '/var/www/html'
|
||||||
|
installWebInterface = True
|
||||||
|
interface = re.findall("^\s*INSTALL_WEB_INTERFACE=.*$", installWeb.stdout, re.MULTILINE)
|
||||||
|
for match in interface:
|
||||||
|
testvalue = match.replace('INSTALL_WEB_INTERFACE=', '').strip().lower()
|
||||||
|
if not testvalue.strip():
|
||||||
|
installWebInterface = testvalue == "true"
|
||||||
|
installWebServer = True
|
||||||
|
server = re.findall("^\s*INSTALL_WEB_SERVER=.*$", installWeb.stdout, re.MULTILINE)
|
||||||
|
for match in server:
|
||||||
|
testvalue = match.replace('INSTALL_WEB_SERVER=', '').strip().lower()
|
||||||
|
if not testvalue.strip():
|
||||||
|
installWebServer = testvalue == "true"
|
||||||
exit_status_success = 0
|
exit_status_success = 0
|
||||||
test_cmd = 'su --shell /bin/bash --command "test -{0} {1}" -p {2}'
|
test_cmd = 'su --shell /bin/bash --command "test -{0} {1}" -p {2}'
|
||||||
# check directories above $webroot for read and execute permission
|
# check directories above $webroot for read and execute permission
|
||||||
|
@ -191,19 +240,23 @@ def test_installPihole_fresh_install_readableBlockpage(Pihole):
|
||||||
check_admin = test_cmd.format('x', webroot + '/admin', webuser)
|
check_admin = test_cmd.format('x', webroot + '/admin', webuser)
|
||||||
actual_rc = Pihole.run(check_admin).rc
|
actual_rc = Pihole.run(check_admin).rc
|
||||||
assert exit_status_success == actual_rc
|
assert exit_status_success == actual_rc
|
||||||
check_pihole = test_cmd.format('r', webroot + '/pihole', webuser)
|
# check web interface files
|
||||||
actual_rc = Pihole.run(check_pihole).rc
|
if installWebInterface == True:
|
||||||
assert exit_status_success == actual_rc
|
check_pihole = test_cmd.format('r', webroot + '/pihole', webuser)
|
||||||
check_pihole = test_cmd.format('x', webroot + '/pihole', webuser)
|
actual_rc = Pihole.run(check_pihole).rc
|
||||||
actual_rc = Pihole.run(check_pihole).rc
|
assert exit_status_success == actual_rc
|
||||||
assert exit_status_success == actual_rc
|
check_pihole = test_cmd.format('x', webroot + '/pihole', webuser)
|
||||||
# check most important files in $webroot for read permission by
|
actual_rc = Pihole.run(check_pihole).rc
|
||||||
check_index = test_cmd.format('r', webroot + '/admin/index.php', webuser)
|
assert exit_status_success == actual_rc
|
||||||
actual_rc = Pihole.run(check_index).rc
|
# check most important files in $webroot for read permission
|
||||||
assert exit_status_success == actual_rc
|
check_index = test_cmd.format('r',
|
||||||
check_blockpage = test_cmd.format('r', webroot + '/admin/blockingpage.css', webuser)
|
webroot + '/pihole/index.php', webuser)
|
||||||
actual_rc = Pihole.run(check_blockpage).rc
|
actual_rc = Pihole.run(check_index).rc
|
||||||
assert exit_status_success == actual_rc
|
assert exit_status_success == actual_rc
|
||||||
|
check_blockpage = test_cmd.format('r',
|
||||||
|
webroot + '/pihole/blockingpage.css', webuser)
|
||||||
|
actual_rc = Pihole.run(check_blockpage).rc
|
||||||
|
assert exit_status_success == actual_rc
|
||||||
|
|
||||||
|
|
||||||
def test_update_package_cache_success_no_errors(Pihole):
|
def test_update_package_cache_success_no_errors(Pihole):
|
||||||
|
|
Loading…
Add table
Reference in a new issue