parent
fca7769b33
commit
7ecf7c6f28
|
@ -72,12 +72,11 @@ prepare_configs() {
|
|||
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;' "${setupVars}"
|
||||
fi
|
||||
# echo the information to the user
|
||||
# P
|
||||
{
|
||||
echo "PIHOLE_INTERFACE=${PIHOLE_INTERFACE}"
|
||||
echo "IPV4_ADDRESS=${IPV4_ADDRESS}"
|
||||
echo "IPV6_ADDRESS=${IPV6_ADDRESS}"
|
||||
echo "PIHOLE_DNS_1=${PIHOLE_DNS_1}"
|
||||
echo "PIHOLE_DNS_2=${PIHOLE_DNS_2}"
|
||||
echo "QUERY_LOGGING=${QUERY_LOGGING}"
|
||||
echo "INSTALL_WEB_SERVER=${INSTALL_WEB_SERVER}"
|
||||
echo "INSTALL_WEB_INTERFACE=${INSTALL_WEB_INTERFACE}"
|
||||
|
@ -134,8 +133,9 @@ setup_dnsmasq_dns() {
|
|||
change_setting "PIHOLE_DNS_1" "${DNS1}"
|
||||
fi
|
||||
if [[ -n "$DNS2" && -z "$setupDNS2" ]] ; then
|
||||
if [ "$DNS2" = "no" ] ; then
|
||||
if [[ "$DNS2" == "no" ]] ; then
|
||||
delete_setting "PIHOLE_DNS_2"
|
||||
unset PIHOLE_DNS_2
|
||||
else
|
||||
change_setting "PIHOLE_DNS_2" "${DNS2}"
|
||||
fi
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/bin/bash -ex /
|
||||
#!/bin/bash -ex
|
||||
|
||||
mkdir -p /etc/pihole/
|
||||
mkdir -p /var/run/pihole
|
||||
|
|
|
@ -39,7 +39,8 @@ def DockerGeneric(request, _test_args, _args, _image, _cmd, _entrypoint):
|
|||
_args = '{} -e PYTEST=1'.format(_args)
|
||||
docker_run = 'docker run -d -t {args} {test_args} {entry} {image} {cmd}'\
|
||||
.format(args=_args, test_args=_test_args, entry=_entrypoint, image=_image, cmd=_cmd)
|
||||
print docker_run
|
||||
# Print a human runable version of the container run command for faster debugging
|
||||
print docker_run.replace('-d -t', '--rm -it').replace('tail -f /dev/null', 'bash')
|
||||
docker_id = check_output(docker_run)
|
||||
|
||||
def teardown():
|
||||
|
|
|
@ -56,33 +56,33 @@ def test_bad_input_to_WEB_PORT(Docker, test_args, expected_error):
|
|||
|
||||
# DNS Environment Variable behavior in combinations of modified pihole LTE settings
|
||||
@pytest.mark.parametrize('args_env, expected_stdout, dns1, dns2', [
|
||||
('-e ServerIP="1.2.3.4"', 'default DNS', '8.8.8.8', '8.8.4.4' ),
|
||||
('-e ServerIP="1.2.3.4" -e DNS1="1.2.3.4"', 'custom DNS', '1.2.3.4', '8.8.4.4' ),
|
||||
('-e ServerIP="1.2.3.4" -e DNS2="1.2.3.4"', 'custom DNS', '8.8.8.8', '1.2.3.4' ),
|
||||
('-e ServerIP="1.2.3.4" -e DNS1="1.2.3.4" -e DNS2="2.2.3.4"', 'custom DNS', '1.2.3.4', '2.2.3.4' ),
|
||||
('-e ServerIP="1.2.3.4" -e DNS1="1.2.3.4" -e DNS2="no"', 'custom DNS', '1.2.3.4', None ),
|
||||
('-e ServerIP="1.2.3.4" -e DNS2="no"', 'custom DNS', '8.8.8.8', None ),
|
||||
('', 'default DNS', '8.8.8.8', '8.8.4.4' ),
|
||||
('-e DNS1="1.2.3.4"', 'custom DNS', '1.2.3.4', '8.8.4.4' ),
|
||||
('-e DNS2="1.2.3.4"', 'custom DNS', '8.8.8.8', '1.2.3.4' ),
|
||||
('-e DNS1="1.2.3.4" -e DNS2="2.2.3.4"', 'custom DNS', '1.2.3.4', '2.2.3.4' ),
|
||||
('-e DNS1="1.2.3.4" -e DNS2="no"', 'custom DNS', '1.2.3.4', None ),
|
||||
('-e DNS2="no"', 'custom DNS', '8.8.8.8', None ),
|
||||
])
|
||||
def test_override_default_servers_with_DNS_EnvVars(Docker, args_env, expected_stdout, dns1, dns2):
|
||||
''' on first boot when DNS vars are NOT set explain default google DNS settings are used
|
||||
or when DNS vars are set override the pihole DNS settings '''
|
||||
assert Docker.run('test -f /.piholeFirstBoot').rc == 0
|
||||
function = Docker.run('. /bash_functions.sh ; eval `grep setup_dnsmasq /start.sh`')
|
||||
function = Docker.run('. /bash_functions.sh ; eval `grep "^setup_dnsmasq " /start.sh`')
|
||||
assert expected_stdout in function.stdout
|
||||
|
||||
time.sleep(1)
|
||||
docker_dns_servers = Docker.run('grep "^server=" /etc/dnsmasq.d/01-pihole.conf').stdout
|
||||
expected_servers = 'server={}\n'.format(dns1) if dns2 == None else 'server={}\nserver={}\n'.format(dns1, dns2)
|
||||
assert expected_servers == docker_dns_servers
|
||||
|
||||
|
||||
@pytest.mark.parametrize('args_env, dns1, dns2, expected_stdout', [
|
||||
('-e ServerIP="1.2.3.4"', '9.9.9.1', '9.9.9.2',
|
||||
('', '9.9.9.1', '9.9.9.2',
|
||||
'Existing DNS servers used'),
|
||||
('-e ServerIP="1.2.3.4" -e DNS1="1.2.3.4"', '9.9.9.1', '9.9.9.2',
|
||||
('-e DNS1="1.2.3.4"', '9.9.9.1', '9.9.9.2',
|
||||
'Docker DNS variables not used\nExisting DNS servers used'),
|
||||
('-e ServerIP="1.2.3.4" -e DNS2="1.2.3.4"', '8.8.8.8', '1.2.3.4',
|
||||
('-e DNS2="1.2.3.4"', '8.8.8.8', '1.2.3.4',
|
||||
'Docker DNS variables not used\nExisting DNS servers used'),
|
||||
('-e ServerIP="1.2.3.4" -e DNS1="1.2.3.4" -e DNS2="2.2.3.4"', '1.2.3.4', '2.2.3.4',
|
||||
('-e DNS1="1.2.3.4" -e DNS2="2.2.3.4"', '1.2.3.4', '2.2.3.4',
|
||||
'Docker DNS variables not used\nExisting DNS servers used'),
|
||||
])
|
||||
def test_DNS_Envs_are_secondary_to_setupvars(Docker, args_env, expected_stdout, dns1, dns2):
|
||||
|
@ -93,11 +93,13 @@ def test_DNS_Envs_are_secondary_to_setupvars(Docker, args_env, expected_stdout,
|
|||
|
||||
# and a user already has custom pihole dns variables in setup vars
|
||||
setupVars = '/etc/pihole/setupVars.conf'
|
||||
Docker.run('sed -i "/^PIHOLE_DNS_1/ c\PIHOLE_DNS_1={}" {}'.format(dns1, setupVars))
|
||||
Docker.run('sed -i "/^PIHOLE_DNS_2/ c\PIHOLE_DNS_2={}" {}'.format(dns2, setupVars))
|
||||
Docker.run('sed -i "/^PIHOLE_DNS_1/ d" {}'.format(dns1, setupVars))
|
||||
Docker.run('sed -i "/^PIHOLE_DNS_2/ d" {}'.format(dns2, setupVars))
|
||||
Docker.run('echo "PIHOLE_DNS_1={}" >> {}'.format(dns1, setupVars))
|
||||
Docker.run('echo "PIHOLE_DNS_2={}" >> {}'.format(dns2, setupVars))
|
||||
|
||||
# When we run setup dnsmasq during startup of the container
|
||||
function = Docker.run('. /bash_functions.sh ; eval `grep setup_dnsmasq /start.sh`')
|
||||
function = Docker.run('. /bash_functions.sh ; eval `grep "^setup_dnsmasq " /start.sh`')
|
||||
assert expected_stdout in function.stdout
|
||||
|
||||
expected_servers = 'server={}\nserver={}\n'.format(dns1, dns2)
|
||||
|
@ -115,15 +117,15 @@ def test_DNS_Envs_are_secondary_to_setupvars(Docker, args_env, expected_stdout,
|
|||
|
||||
|
||||
@pytest.mark.parametrize('args_env, expected_stdout, expected_config_line', [
|
||||
('-e ServerIP="1.2.3.4"', 'binding to default interface: eth0', 'interface=eth0' ),
|
||||
('-e ServerIP="1.2.3.4" -e INTERFACE="eth0"', 'binding to default interface: eth0', 'interface=eth0' ),
|
||||
('-e ServerIP="1.2.3.4" -e INTERFACE="br0"', 'binding to custom interface: br0', 'interface=br0'),
|
||||
('', 'binding to default interface: eth0', 'interface=eth0' ),
|
||||
('-e INTERFACE="eth0"', 'binding to default interface: eth0', 'interface=eth0' ),
|
||||
('-e INTERFACE="br0"', 'binding to custom interface: br0', 'interface=br0'),
|
||||
])
|
||||
def test_DNS_interface_override_defaults(Docker, args_env, expected_stdout, expected_config_line):
|
||||
''' When INTERFACE environment var is passed in, overwrite dnsmasq interface '''
|
||||
function = Docker.run('. /bash_functions.sh ; eval `grep setup_dnsmasq /start.sh`')
|
||||
function = Docker.run('. /bash_functions.sh ; eval `grep "^setup_dnsmasq " /start.sh`')
|
||||
assert expected_stdout in function.stdout
|
||||
|
||||
time.sleep(1)
|
||||
docker_dns_interface = Docker.run('grep "^interface" /etc/dnsmasq.d/01-pihole.conf').stdout
|
||||
assert expected_config_line + '\n' == docker_dns_interface
|
||||
|
||||
|
@ -152,10 +154,7 @@ def test_debian_setup_php_env(Docker, expected_lines, repeat_function):
|
|||
assert False, "Found line {} times (more than once): {}".format(expected_line)
|
||||
|
||||
|
||||
# Overwrite entrypoint / cmd with noop, just run our method for this unit
|
||||
@pytest.mark.parametrize('entrypoint,cmd', [('--entrypoint=tail','-f /dev/null')])
|
||||
@pytest.mark.parametrize('args_env', [('-e ServerIP=1.2.3.4')])
|
||||
def test_webPassword_random_generation(Docker, args_env):
|
||||
def test_webPassword_random_generation(Docker):
|
||||
''' When a user sets webPassword env the admin password gets set to that '''
|
||||
function = Docker.run('. /bash_functions.sh ; eval `grep generate_password /start.sh`')
|
||||
assert 'assigning random password' in function.stdout.lower()
|
||||
|
|
Loading…
Reference in New Issue