Ejemplo n.º 1
0
    def __init__(self, contents, config):
        self.contents = contents
        self.config = config

        self.parsed = yaml.ordered_load("\n".join(contents))

        self.rule = None
Ejemplo n.º 2
0
def test_ansible_conformance():
    remediation = ssg.ansible.AnsibleRemediation.from_snippet_and_rule(
        os.path.join(DATADIR, "ansible.yml"), os.path.join(DATADIR, "file_owner_grub2_cfg.yml")
    )
    ref_remediation_dict = ordered_load(open(os.path.join(DATADIR, "ansible-resolved.yml")))

    remediation.update("rhel7")

    # The comparison has to be done this way due to possible order variations,
    # which don't matter, but they make tests to fail.
    assert set(remediation.parsed[0]["tags"]) == set(ref_remediation_dict[0]["tags"])
    assert set(remediation.parsed[1]["tags"]) == set(ref_remediation_dict[1]["tags"])
    assert set(remediation.parsed[0]["when"]) == set(ref_remediation_dict[0]["when"])
    assert set(remediation.parsed[1]["when"]) == set(ref_remediation_dict[1]["when"])
    assert set(remediation.parsed[0]["name"]) == set(ref_remediation_dict[0]["name"])
Ejemplo n.º 3
0
def test_ansible_conformance(env_yaml, cpe_platforms):
    remediation = sbr.AnsibleRemediation.from_snippet_and_rule(
        os.path.join(DATADIR, "ansible.yml"),
        os.path.join(DATADIR, "file_owner_grub2_cfg.yml"))
    ref_remediation_dict = ordered_load(
        open(os.path.join(DATADIR, "ansible-resolved.yml")))

    remediation.parse_from_file_with_jinja(env_yaml, cpe_platforms)
    # The comparison has to be done this way due to possible order variations,
    # which don't matter, but they make tests to fail.
    assert set(remediation.body[0]["tags"]) == set(
        ref_remediation_dict[0]["tags"])
    assert set(remediation.body[1]["tags"]) == set(
        ref_remediation_dict[1]["tags"])
    assert set(remediation.body[0]["when"]) == set(
        ref_remediation_dict[0]["when"])
    assert set(remediation.body[1]["when"]) == set(
        ref_remediation_dict[1]["when"])
    assert remediation.body[0]["name"] == ref_remediation_dict[0]["name"]
    assert remediation.body[1]["name"] == ref_remediation_dict[1]["name"]