1
0
mirror of https://github.com/pi-hole/pi-hole synced 2024-12-22 14:58:08 +00:00

Full test suite for firewallD configuration.

This commit is contained in:
Dan Schaper 2017-01-24 11:03:37 -08:00
parent 9c7f7756b4
commit 8529c1287f
No known key found for this signature in database
GPG Key ID: 572E999E385B7BFC

View File

@ -65,8 +65,10 @@ def test_setupVars_saved_to_file(Pihole):
assert "{}={}".format(k, v) in output
def test_configureFirewall_firewalld_running_no_errors(Pihole):
''' confirms firewalld rules are applied when appropriate '''
''' confirms firewalld rules are applied when firewallD is running '''
# firewallD returns 'running' as status
mock_command('firewall-cmd', 'running', '0', Pihole)
# Whiptail dialog returns Ok for user prompt
mock_command('whiptail', '', '0', Pihole)
configureFirewall = Pihole.run('''
source /opt/pihole/basic-install.sh
@ -79,6 +81,30 @@ def test_configureFirewall_firewalld_running_no_errors(Pihole):
assert 'firewall-cmd --permanent --add-port=80/tcp --add-port=53/tcp --add-port=53/udp' in firewall_calls
assert 'firewall-cmd --reload' in firewall_calls
def test_configureFirewall_firewalld_disabled_no_errors(Pihole):
''' confirms firewalld rules are not applied when firewallD is not running '''
# firewallD returns non-running status
mock_command('firewall-cmd', 'stopped', '0', Pihole)
configureFirewall = Pihole.run('''
source /opt/pihole/basic-install.sh
configureFirewall
''')
expected_stdout = 'No active firewall detected.. skipping firewall configuration.'
assert expected_stdout in configureFirewall.stdout
def test_configureFirewall_firewalld_enabled_declined_no_errors(Pihole):
''' confirms firewalld rules are not applied when firewallD is running, user declines ruleset '''
# firewallD returns running status
mock_command('firewall-cmd', 'running', '0', Pihole)
# Whiptail dialog returns Cancel for user prompt
mock_command('whiptail', '', '1', Pihole)
configureFirewall = Pihole.run('''
source /opt/pihole/basic-install.sh
configureFirewall
''')
expected_stdout = 'Not installing firewall rulesets.'
assert expected_stdout in configureFirewall.stdout
# Helper functions
def mock_command(script, result, retVal, container):
''' Allows for setup of commands we don't really want to have to run for real in unit tests '''