xoxys.iptables/molecule/ec2-centos-7/tests/test_default.py

35 lines
1.1 KiB
Python
Raw Normal View History

2019-09-18 09:29:48 +00:00
import os
import testinfra.utils.ansible_runner
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
def test_iptables_is_installed(host):
iptables = host.package("iptables")
assert iptables.is_installed
def test_iptables_running_and_enabled(host):
iptables = host.service("iptables")
assert iptables.is_running
assert iptables.is_enabled
2019-09-18 09:55:28 +00:00
def test_iptables_default_rules(host):
2019-09-18 09:29:48 +00:00
defaults = [
2019-09-18 13:19:46 +00:00
'-P INPUT ACCEPT',
2019-09-18 14:26:13 +00:00
'-A INPUT -m state --state RELATED,ESTABLISHED -m comment --comment "ansible[iptables_default_head]" -j ACCEPT',
'-A INPUT -i lo -m comment --comment "ansible[iptables_default_head]" -j ACCEPT',
2019-09-18 14:50:46 +00:00
'-A INPUT -p icmp -m icmp --icmp-type 8 -m comment --comment "ansible[iptables_default_head]" -j ACCEPT',
2019-09-18 14:26:13 +00:00
'-A INPUT -p tcp -m tcp --dport 22 -m comment --comment "ansible[iptables_default_head]" -j ACCEPT',
'-A INPUT -j REJECT'
2019-09-18 09:29:48 +00:00
]
2019-09-18 10:53:57 +00:00
rules = host.iptables.rules("filter", "INPUT")
2019-09-18 10:01:07 +00:00
assert defaults == rules