Files
@ 0bfda9b0c3fe
Branch filter:
Location: majic-ansible-roles/roles/wsgi_website/molecule/default/tests/test_parameters_optional.py - annotation
0bfda9b0c3fe
3.7 KiB
text/x-python
MAR-132: Pin packages as part of wsgi_website role test to ensure reproducability:
- Provide explicit list of packages being deployed. This should ensure
we can always reproduce the tests without being affected by new
releases of packages.
- Updated expected requirements in test for the jedi version.
- Provide explicit list of packages being deployed. This should ensure
we can always reproduce the tests without being affected by new
releases of packages.
- Updated expected requirements in test for the jedi 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 | b5ed796b566a 998aab91d6b4 998aab91d6b4 998aab91d6b4 998aab91d6b4 998aab91d6b4 f05151d6f802 998aab91d6b4 998aab91d6b4 a1e0221d24e7 998aab91d6b4 998aab91d6b4 998aab91d6b4 998aab91d6b4 f05151d6f802 998aab91d6b4 f05151d6f802 f05151d6f802 f05151d6f802 f05151d6f802 998aab91d6b4 f05151d6f802 f05151d6f802 998aab91d6b4 998aab91d6b4 a1e0221d24e7 998aab91d6b4 998aab91d6b4 998aab91d6b4 998aab91d6b4 a1e0221d24e7 998aab91d6b4 998aab91d6b4 998aab91d6b4 998aab91d6b4 998aab91d6b4 998aab91d6b4 a1e0221d24e7 998aab91d6b4 998aab91d6b4 998aab91d6b4 998aab91d6b4 998aab91d6b4 a1e0221d24e7 998aab91d6b4 998aab91d6b4 998aab91d6b4 998aab91d6b4 998aab91d6b4 998aab91d6b4 998aab91d6b4 998aab91d6b4 a1e0221d24e7 998aab91d6b4 998aab91d6b4 998aab91d6b4 998aab91d6b4 998aab91d6b4 998aab91d6b4 c8d4251a6ea5 998aab91d6b4 998aab91d6b4 a1e0221d24e7 998aab91d6b4 998aab91d6b4 998aab91d6b4 998aab91d6b4 a1e0221d24e7 998aab91d6b4 998aab91d6b4 998aab91d6b4 a1e0221d24e7 998aab91d6b4 998aab91d6b4 998aab91d6b4 998aab91d6b4 a1e0221d24e7 998aab91d6b4 998aab91d6b4 998aab91d6b4 998aab91d6b4 a1e0221d24e7 998aab91d6b4 998aab91d6b4 998aab91d6b4 998aab91d6b4 a1e0221d24e7 998aab91d6b4 998aab91d6b4 998aab91d6b4 998aab91d6b4 a1e0221d24e7 998aab91d6b4 998aab91d6b4 998aab91d6b4 998aab91d6b4 998aab91d6b4 998aab91d6b4 a1e0221d24e7 998aab91d6b4 998aab91d6b4 998aab91d6b4 998aab91d6b4 a1e0221d24e7 998aab91d6b4 998aab91d6b4 998aab91d6b4 a1e0221d24e7 998aab91d6b4 998aab91d6b4 | import os
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts(['parameters-optional'])
def test_installed_packages(host):
"""
Tests if additional packages are installed.
"""
ansible_facts = host.ansible("setup")["ansible_facts"]
if ansible_facts['ansible_distribution_release'] == 'jessie':
mariadb_compat_package = 'libmariadb-client-lgpl-dev-compat'
elif ansible_facts['ansible_distribution_release'] == 'stretch':
mariadb_compat_package = 'libmariadbclient-dev-compat'
assert host.package(mariadb_compat_package).is_installed
assert host.package('global').is_installed
def test_https_enforcement(host):
"""
Tests if HTTPS is (not) being enforced.
"""
https_enforcement = host.run('curl -I http://parameters-optional.local/')
assert https_enforcement.rc == 0
assert 'HTTP/1.1 200 OK' in https_enforcement.stdout
assert 'HTTP/1.1 301 Moved Permanently' not in https_enforcement.stdout
assert 'Location: https://parameters-optional/' not in https_enforcement.stdout
https_enforcement = host.run('curl -I https://parameters-optional.local/')
assert https_enforcement.rc == 0
assert 'Strict-Transport-Security' not in https_enforcement.stdout
def test_index_page(host):
"""
Tests if index page is served correctly. This covers:
- Basic WSGI application operation.
- Handling of environment variables.
- Handling of proxy headers.
"""
page = host.run('curl -H "Accept-Encoding: plain" https://parameters-optional.local/')
assert page.rc == 0
assert "This is the WSGI application at parameters-optional.local." in page.stdout
assert "Requested URL was: https://parameters-optional.local/" in page.stdout
assert "MY_ENV_VAR: My environment variable" in page.stdout
assert "Accept-Encoding: None" in page.stdout
assert "Python version: 3." in page.stdout
def test_static_file_serving(host):
"""
Tests serving of static files.
"""
page = host.run('curl https://parameters-optional.local/static/static_file.txt')
assert page.rc == 0
assert page.stdout == open("tests/data/static_file.txt", 'r').read().rstrip()
page = host.run('curl https://parameters-optional.local/media/media_file.txt')
assert page.rc == 0
assert page.stdout == open("tests/data/media_file.txt", 'r').read().rstrip()
def test_additional_nginx_config(host):
"""
Tests if additional Nginx configuration directives are properly deployed.
"""
page = host.run('curl https://parameters-optional.local/static/missing_static_file.txt')
assert page.rc == 0
assert "Requested URL was: https://parameters-optional.local/my/own/error/page"
def test_environment_indicator(host):
"""
Tests if environment indicator is applied correctly.
"""
page = host.run('curl https://parameters-optional.local/')
assert page.rc == 0
assert "<div id='website-environment' style='background-color: #ff0000; width: 100%; text-align: center; position: fixed; bottom: 5px; color: #00ff00; " \
"font-weight: bold; z-index: 999999;'>parameters-optional</div></body>" in page.stdout
def test_nginx_rewrite_config(host):
"""
Tests if Nginx rewrite configuration is deployed correctly.
"""
page = host.run('curl https://parameters-optional.local/rewrite1/some/path')
assert page.rc == 0
assert "Requested URL was: https://parameters-optional.local/rewritten1/" in page.stdout
page = host.run('curl https://parameters-optional.local/rewrite2/some/other/path')
assert page.rc == 0
assert "Requested URL was: https://parameters-optional.local/rewritten2/some/other/path" in page.stdout
|