xoxys.iptables/molecule/ec2-centos-7/tests/test_default.py
Robert Kaussow 69a58a8cd7
Some checks failed
continuous-integration/drone/push Build is failing
fix default rules list
2019-09-18 15:19:46 +02:00

35 lines
1.2 KiB
Python

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
def test_iptables_default_rules(host):
defaults = [
'-P INPUT ACCEPT',
'-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -m comment --comment "ansible[iptables_default_head]"',
'-A INPUT -i lo -j ACCEPT -m comment --comment "ansible[iptables_default_head]"',
'-A INPUT -p icmp --icmp-type echo-request -j ACCEPT -m comment --comment "ansible[iptables_default_head]"',
'-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT -m comment --comment "ansible[iptables_default_head]"',
'-A INPUT -j REJECT -m comment --comment "ansible[iptables_default_head]"'
]
rules = host.iptables.rules("filter", "INPUT")
assert defaults == rules