summaryrefslogtreecommitdiffstats
path: root/ansible/roles/setup/molecule/default/tests/test_default.py
blob: 6bf6b6badaa0503814cdc68a720cf926ec4390ae (plain)
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
import os
import pytest
from os.path import expanduser

import testinfra.utils.ansible_runner

testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')


@pytest.fixture
def get_vars(host):
    defaults_files = "file=../../defaults/main.yml name=role_defaults"
    ansible_vars = host.ansible(
        "include_vars",
        defaults_files)["ansible_facts"]["role_defaults"]
    return ansible_vars


def test_authorized_keys(host, get_vars):
    public_key_file = get_vars['offline_ssh_key_file_name'] + '.pub'
    with open(expanduser("~") + '/.ssh/' + public_key_file, 'r') as pkf:
        public_key_content = pkf.read().strip()

    f = host.file('/root/.ssh/authorized_keys')
    assert f.exists
    assert f.user == 'root'
    assert f.group == 'root'
    assert oct(f.mode) == '0o600'
    assert f.content_string == public_key_content