diff --git a/roles/bootstrap/molecule/default/tests/test_default.py b/roles/bootstrap/molecule/default/tests/test_default.py index f5fb4117f9b073bf23c9803a7a8fd90d9af1c05f..e90ce8404bf4ad8b0e7749d7e61a0b593e320aab 100644 --- a/roles/bootstrap/molecule/default/tests/test_default.py +++ b/roles/bootstrap/molecule/default/tests/test_default.py @@ -49,3 +49,29 @@ def test_sudo_configuration(host): assert sudo_config.group == 'root' assert sudo_config.mode == 0o640 assert sudo_config.content_string == 'ansible ALL=(ALL:ALL) NOPASSWD:ALL\n' + + +def test_authorized_keys(host): + """ + Tests if Ansible user authorized_keys has been set-up correctly. + """ + + with host.sudo(): + + ssh_key = open('tests/data/ansible_key.pub', 'r').read().strip() + authorized_keys = host.file('/home/ansible/.ssh/authorized_keys') + + assert authorized_keys.is_file + assert ssh_key in authorized_keys.content_string + + +def test_root_authorized_keys(host): + """ + Tests if Ansible key been removed from root's authorized keys. + """ + + with host.sudo(): + + ssh_key = open('tests/data/ansible_key.pub', 'r').read().strip() + + assert ssh_key not in host.file('/root/.ssh/authorized_keys').content_string diff --git a/roles/bootstrap/molecule/default/tests/test_parameters_mandatory.py b/roles/bootstrap/molecule/default/tests/test_parameters_mandatory.py deleted file mode 100644 index 7eaccc564f05ac2f3f9c7ee79db3158531d5a56d..0000000000000000000000000000000000000000 --- a/roles/bootstrap/molecule/default/tests/test_parameters_mandatory.py +++ /dev/null @@ -1,33 +0,0 @@ -import os - -import testinfra.utils.ansible_runner - - -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('parameters-mandatory') - - -def test_authorized_keys(host): - """ - Tests if Ansible user authorized_keys has been set-up correctly. - """ - - with host.sudo(): - - ssh_key = open('tests/data/ansible_key.pub', 'r').read().strip() - authorized_keys = host.file('/home/ansible/.ssh/authorized_keys') - - assert authorized_keys.is_file - assert ssh_key in authorized_keys.content_string - - -def test_root_authorized_keys(host): - """ - Tests if Ansible key been removed from root's authorized keys. - """ - - with host.sudo(): - - ssh_key = open('tests/data/ansible_key.pub', 'r').read().strip() - - assert ssh_key not in host.file('/root/.ssh/authorized_keys').content_string diff --git a/roles/bootstrap/molecule/default/tests/test_parameters_optional.py b/roles/bootstrap/molecule/default/tests/test_parameters_optional.py deleted file mode 100644 index 7b4f3e5be3a8bc8edee100eea3f20ecca30f534e..0000000000000000000000000000000000000000 --- a/roles/bootstrap/molecule/default/tests/test_parameters_optional.py +++ /dev/null @@ -1,33 +0,0 @@ -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_authorized_keys(host): - """ - Tests if Ansible user authorized_keys has been set-up correctly. - """ - - with host.sudo(): - - ssh_key = open('tests/data/ansible_key.pub', 'r').read().strip() - authorized_keys = host.file('/home/ansible/.ssh/authorized_keys') - - assert authorized_keys.is_file - assert ssh_key in authorized_keys.content_string - - -def test_root_authorised_keys(host): - """ - Tests if Ansible key been removed from root's authorized keys. - """ - - with host.sudo(): - - ssh_key = open('tests/data/ansible_key.pub', 'r').read().strip() - - assert ssh_key not in host.file('/root/.ssh/authorized_keys').content_string