mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-15 02:42:58 +00:00
Full test suite for firewallD configuration.
This commit is contained in:
parent
9c7f7756b4
commit
8529c1287f
1 changed files with 27 additions and 1 deletions
|
@ -65,8 +65,10 @@ def test_setupVars_saved_to_file(Pihole):
|
||||||
assert "{}={}".format(k, v) in output
|
assert "{}={}".format(k, v) in output
|
||||||
|
|
||||||
def test_configureFirewall_firewalld_running_no_errors(Pihole):
|
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)
|
mock_command('firewall-cmd', 'running', '0', Pihole)
|
||||||
|
# Whiptail dialog returns Ok for user prompt
|
||||||
mock_command('whiptail', '', '0', Pihole)
|
mock_command('whiptail', '', '0', Pihole)
|
||||||
configureFirewall = Pihole.run('''
|
configureFirewall = Pihole.run('''
|
||||||
source /opt/pihole/basic-install.sh
|
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 --permanent --add-port=80/tcp --add-port=53/tcp --add-port=53/udp' in firewall_calls
|
||||||
assert 'firewall-cmd --reload' 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
|
# Helper functions
|
||||||
def mock_command(script, result, retVal, container):
|
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 '''
|
''' Allows for setup of commands we don't really want to have to run for real in unit tests '''
|
||||||
|
|
Loading…
Reference in a new issue