2020-01-14 07:07:21 +00:00
|
|
|
import os
|
2020-01-14 07:52:08 +00:00
|
|
|
import pytest
|
2020-01-14 07:07:21 +00:00
|
|
|
|
|
|
|
import testinfra.utils.ansible_runner
|
|
|
|
|
|
|
|
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
|
|
|
|
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
|
|
|
|
|
|
|
|
|
2020-01-14 07:52:08 +00:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
'package_name',
|
2020-01-14 09:00:07 +00:00
|
|
|
[
|
2020-01-20 18:00:02 +00:00
|
|
|
'apache2',
|
2020-01-14 23:42:03 +00:00
|
|
|
'apt-transport-https',
|
2020-01-14 09:00:07 +00:00
|
|
|
'bash-completion',
|
2020-01-14 12:59:51 +00:00
|
|
|
'certbot',
|
2020-01-14 09:00:07 +00:00
|
|
|
'colordiff',
|
|
|
|
'curl',
|
2020-01-14 19:32:41 +00:00
|
|
|
'gnupg',
|
|
|
|
'gnupg2',
|
2020-01-14 09:00:07 +00:00
|
|
|
'iptables-persistent',
|
|
|
|
'less',
|
2020-01-20 18:00:02 +00:00
|
|
|
'nginx',
|
2020-01-18 10:23:56 +00:00
|
|
|
'procps',
|
2020-01-14 23:42:03 +00:00
|
|
|
'software-properties-common',
|
2020-01-14 09:00:07 +00:00
|
|
|
'vim',
|
2020-01-14 18:52:13 +00:00
|
|
|
'wget',
|
2020-01-14 09:00:07 +00:00
|
|
|
],
|
2020-01-14 07:52:08 +00:00
|
|
|
)
|
|
|
|
def test_packages(host, package_name):
|
|
|
|
assert host.package(package_name).is_installed
|
2020-01-14 08:07:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_vim_config(host):
|
|
|
|
f = host.file('/etc/vim/vimrc.local')
|
|
|
|
|
|
|
|
assert f.exists
|
|
|
|
assert f.is_file
|
|
|
|
assert f.user == 'root'
|
|
|
|
assert f.group == 'root'
|
|
|
|
assert f.mode == 0o644
|
2020-01-14 08:14:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_default_editor(host):
|
|
|
|
f = host.file('/usr/bin/editor')
|
|
|
|
|
|
|
|
assert f.exists
|
|
|
|
assert f.is_symlink
|
|
|
|
assert f.linked_to == '/usr/bin/vim.basic'
|
2020-01-14 09:00:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('version', [4, 6])
|
|
|
|
def test_iptables_config(host, version):
|
|
|
|
f = host.file('/etc/iptables/rules.v%d' % version)
|
|
|
|
|
|
|
|
assert f.exists
|
|
|
|
assert f.is_file
|
|
|
|
assert f.user == 'root'
|
|
|
|
assert f.group == 'root'
|
|
|
|
assert f.mode == 0o644
|
2020-01-14 10:23:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_nginx_default_removed(host):
|
|
|
|
assert host.file('/etc/nginx/sites-available/default').exists
|
|
|
|
assert not host.file('/etc/nginx/sites-enabled/default').exists
|
2020-01-14 10:55:56 +00:00
|
|
|
|
|
|
|
|
2020-01-20 18:00:02 +00:00
|
|
|
def test_apache_default_removed(host):
|
|
|
|
assert host.file('/etc/apache2/sites-available/000-default.conf').exists
|
|
|
|
assert not host.file('/etc/apache2/sites-enabled/000-default.conf').exists
|
|
|
|
|
|
|
|
|
2020-01-14 10:55:56 +00:00
|
|
|
def test_certbot_cli_config(host):
|
|
|
|
f = host.file('/etc/letsencrypt/cli.ini')
|
|
|
|
|
|
|
|
assert f.exists
|
|
|
|
assert f.is_file
|
|
|
|
assert f.user == 'root'
|
|
|
|
assert f.group == 'root'
|
|
|
|
assert f.mode == 0o644
|
|
|
|
|
|
|
|
|
|
|
|
def test_certbot_nginx_config(host):
|
|
|
|
f = host.file('/etc/letsencrypt/options-ssl-nginx.conf')
|
|
|
|
|
|
|
|
assert f.exists
|
|
|
|
assert f.is_file
|
|
|
|
assert f.user == 'root'
|
|
|
|
assert f.group == 'root'
|
|
|
|
assert f.mode == 0o644
|