Files
@ 92011aae7258
Branch filter:
Location: majic-ansible-roles/roles/web_server/tests/test_default.py - annotation
92011aae7258
6.0 KiB
text/x-python
MAR-128: Upgraded tests for php_website role:
- Switch to new Molecule configuration.
- Updated set-up playbook to use become: yes.
- Moved some preparatory steps outside of the main playbook (eases
idempotence tests).
- Updated tests to reference the yml inventory file.
- Updated tests to use new fixture (host instead of individual ones).
- Switched to extracting hostname instead of hard-coding it in a
couple of tests.
- Fixed some linting issues.
- Updated hostname to include Debian version.
- Switch to new Molecule configuration.
- Updated set-up playbook to use become: yes.
- Moved some preparatory steps outside of the main playbook (eases
idempotence tests).
- Updated tests to reference the yml inventory file.
- Updated tests to use new fixture (host instead of individual ones).
- Switched to extracting hostname instead of hard-coding it in a
couple of tests.
- Fixed some linting issues.
- Updated hostname to include Debian version.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | 502fdc081d35 502fdc081d35 502fdc081d35 502fdc081d35 351cd42e5f56 502fdc081d35 502fdc081d35 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 502fdc081d35 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 351cd42e5f56 | import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
'.molecule/ansible_inventory').get_hosts(['parameters-mandatory', 'parameters-optional'])
def test_installed_packages(Package):
"""
Tests if the required packages have been installed.
"""
assert Package('nginx').is_installed
assert Package('virtualenv').is_installed
assert Package('virtualenvwrapper').is_installed
assert Package('php5-fpm').is_installed
def test_nginx_user(User):
"""
Tests if Nginx user has been set-up correctly to traverse TLS directories.
"""
assert 'ssl-cert' in User('www-data').groups
def test_default_tls_configuration_removed(File):
"""
Tests if TLS configuration has been removed from the main (default)
configuration file.
"""
assert 'ssl_protocols' not in File('/etc/nginx/nginx.conf').content
def test_nginx_configuration_verification_script(File):
"""
Tests if script used for verifying Nginx configuration is deployed
correctly.
"""
script = File('/usr/local/bin/nginx_verify_site.sh')
assert script.is_file
assert script.user == 'root'
assert script.group == 'root'
assert script.mode == 0o755
def test_tls_configuration_file(File):
"""
Tests permissions of TLS configuration file.
"""
config = File('/etc/nginx/conf.d/tls.conf')
assert config.is_file
assert config.user == 'root'
assert config.group == 'root'
assert config.mode == 0o644
def test_default_vhost_file(File):
"""
Tests permissions of default vhost configuration file.
"""
config = File('/etc/nginx/sites-available/default')
assert config.is_file
assert config.user == 'root'
assert config.group == 'root'
assert config.mode == 0o640
def test_default_website_enabled(File):
"""
Tests if default website has been enabled.
"""
config = File('/etc/nginx/sites-enabled/default')
assert config.is_symlink
assert config.linked_to == '/etc/nginx/sites-available/default'
def test_firewall_configuration_file(File, Sudo):
"""
Tests if firewall configuration file has been deployed correctly.
"""
with Sudo():
config = File('/etc/ferm/conf.d/30-web.conf')
assert config.is_file
assert config.user == 'root'
assert config.group == 'root'
assert config.mode == 0o640
def test_default_debian_index_removed(File, Sudo):
"""
Tests if default HTML pages provided by debian are removed.
"""
with Sudo():
assert not File('/var/www/html').exists
def test_default_vhost_root_directory(File, Sudo):
"""
Tests if the default vhost root directory exists.
"""
directory = File('/var/www/default')
assert directory.is_directory
assert directory.user == 'root'
assert directory.group == 'www-data'
assert directory.mode == 0o750
def test_default_vhost_index_page_file(File, Sudo):
"""
Tests permissions of default vhost index page.
"""
with Sudo():
page = File('/var/www/default/index.html')
assert page.is_file
assert page.user == 'root'
assert page.group == 'www-data'
assert page.mode == 0o640
def test_services(Service):
"""
Tests if services are enabled at boot and running.
"""
service = Service('nginx')
assert service.is_enabled
assert service.is_running
service = Service('php5-fpm')
assert service.is_enabled
assert service.is_running
def test_sockets(Socket):
"""
Tests if web server is listening on correct ports.
"""
assert Socket("tcp://80").is_listening
assert Socket("tcp://443").is_listening
def test_socket_directories(File, Sudo):
"""
Tests if directories containing sockets for WSGI and PHP apps are created
correctly.
"""
directory = File('/run/wsgi')
assert directory.is_directory
assert directory.user == 'root'
assert directory.group == 'www-data'
assert directory.mode == 0o750
directory = File('/run/php5-fpm')
assert directory.is_directory
assert directory.user == 'root'
assert directory.group == 'www-data'
assert directory.mode == 0o750
config = File('/etc/tmpfiles.d/wsgi.conf')
assert config.is_file
assert config.user == 'root'
assert config.group == 'root'
assert config.mode == 0o644
assert 'd /run/wsgi/ 0750 root www-data - -' in config.content
config = File('/etc/tmpfiles.d/php5-fpm.conf')
assert config.is_file
assert config.user == 'root'
assert config.group == 'root'
assert config.mode == 0o644
assert 'd /run/php5-fpm/ 0750 root www-data - -' in config.content
def test_php5_fpm_service_overrides(File):
"""
Tests if overrides for php5-fpm service are deployed correctly.
"""
directory = File('/etc/systemd/system/php5-fpm.service.d')
assert directory.is_directory
assert directory.user == 'root'
assert directory.group == 'root'
assert directory.mode == 0o755
config = File('/etc/systemd/system/php5-fpm.service.d/umask.conf')
assert config.is_file
assert config.user == 'root'
assert config.group == 'root'
assert config.mode == 0o644
def test_php_timezone_configuration(Command, File):
"""
Tests if PHP timezone configuration has been set correctly.
"""
config = File('/etc/php5/cli/conf.d/30-timezone.ini')
assert config.is_file
assert config.user == 'root'
assert config.group == 'root'
assert config.mode == 0o644
config = File('/etc/php5/fpm/conf.d/30-timezone.ini')
assert config.is_file
assert config.user == 'root'
assert config.group == 'root'
assert config.mode == 0o644
timezone = Command("php --php-ini /etc/php5/cli/php.ini -r 'echo ini_get(\"date.timezone\");'")
assert timezone.rc == 0
assert timezone.stdout == "GMT+0"
timezone = Command("php --php-ini /etc/php5/fpm/php.ini -r 'echo ini_get(\"date.timezone\");'")
assert timezone.rc == 0
assert timezone.stdout == "GMT+0"
|