Example #1
0
def test_datastream_content_paths():
    data = PolicyData()
    data.content_type = "datastream"
    data.content_url = "https://example.com/hardening.xml"
    data.datastream_id = "id_datastream_1"
    data.xccdf_id = "id_xccdf_new"
    data.content_path = "/usr/share/oscap/testing_ds.xml"
    data.cpe_path = "/usr/share/oscap/cpe.xml"
    data.tailoring_path = "/usr/share/oscap/tailoring.xml"
    data.profile_id = "Web Server"

    assert common.get_content_name(data) == "hardening.xml"

    expected_path = "/tmp/openscap_data/hardening.xml"
    assert common.get_raw_preinst_content_path(data) == expected_path

    expected_path = "/tmp/openscap_data/hardening.xml"
    assert common.get_preinst_content_path(data) == expected_path

    expected_path = "/root/openscap_data/hardening.xml"
    assert common.get_postinst_content_path(data) == expected_path

    expected_path = "/tmp/openscap_data/usr/share/oscap/tailoring.xml"
    assert common.get_preinst_tailoring_path(data) == expected_path

    expected_path = "/root/openscap_data/usr/share/oscap/tailoring.xml"
    assert common.get_postinst_tailoring_path(data) == expected_path
Example #2
0
def test_archive_content_paths():
    data = PolicyData()
    data.content_type = "archive"
    data.content_url = "http://example.com/oscap_content.tar"
    data.content_path = "oscap/xccdf.xml"
    data.profile_id = "Web Server"
    data.content_path = "oscap/xccdf.xml"
    data.tailoring_path = "oscap/tailoring.xml"

    assert common.get_content_name(data) == "oscap_content.tar"

    expected_path = "/tmp/openscap_data/oscap_content.tar"
    assert common.get_raw_preinst_content_path(data) == expected_path

    expected_path = "/tmp/openscap_data/oscap/xccdf.xml"
    assert common.get_preinst_content_path(data) == expected_path

    expected_path = "/root/openscap_data/oscap/xccdf.xml"
    assert common.get_postinst_content_path(data) == expected_path

    expected_path = "/tmp/openscap_data/oscap/tailoring.xml"
    assert common.get_preinst_tailoring_path(data) == expected_path

    expected_path = "/root/openscap_data/oscap/tailoring.xml"
    assert common.get_postinst_tailoring_path(data) == expected_path
Example #3
0
def test_cancel_tasks(service: OSCAPService):
    data = PolicyData()
    data.content_type = "scap-security-guide"
    data.profile_id = "Web Server"

    service.policy_enabled = True
    service.policy_data = data

    # Collect all tasks.
    tasks = service.configure_with_tasks() + service.install_with_tasks()

    # No task is canceled by default.
    for task in tasks:
        assert task.check_cancel() is False

    callback = Mock()
    service.installation_canceled.connect(callback)

    # The first task should fail with the given data.
    with pytest.raises(Exception):
        tasks[0].run_with_signals()

    # That should cancel all tasks.
    callback.assert_called_once()

    for task in tasks:
        assert task.check_cancel() is True
Example #4
0
def test_configure_with_tasks(service: OSCAPService,
                              interface: OSCAPInterface):
    data = PolicyData()
    data.content_type = "scap-security-guide"
    data.profile_id = "Web Server"

    service.policy_enabled = True
    service.policy_data = data

    object_paths = interface.ConfigureWithTasks()
    assert len(object_paths) == 2

    tasks = TaskContainer.from_object_path_list(object_paths)
    assert isinstance(tasks[0], installation.PrepareValidContent)
    assert isinstance(tasks[1], installation.EvaluateRulesTask)
Example #5
0
def test_install_with_tasks(service: OSCAPService, interface: OSCAPInterface):
    data = PolicyData()
    data.content_type = "scap-security-guide"
    data.profile_id = "Web Server"
    data.remediate = "both"

    service.policy_enabled = True
    service.policy_data = data

    object_paths = interface.InstallWithTasks()
    assert len(object_paths) == 3

    tasks = TaskContainer.from_object_path_list(object_paths)
    assert isinstance(tasks[0], installation.InstallContentTask)
    assert isinstance(tasks[1], installation.RemediateSystemTask)
    assert isinstance(tasks[2], installation.ScheduleFirstbootRemediationTask)
Example #6
0
def test_datastream_requirements(service: OSCAPService,
                                 interface: OSCAPInterface):
    data = PolicyData()
    data.content_type = "datastream"
    data.profile_id = "Web Server"

    service.policy_enabled = True
    service.policy_data = data

    requirements = Requirement.from_structure_list(
        interface.CollectRequirements())

    assert len(requirements) == 2
    assert requirements[0].type == REQUIREMENT_TYPE_PACKAGE
    assert requirements[0].name == "openscap"
    assert requirements[1].type == REQUIREMENT_TYPE_PACKAGE
    assert requirements[1].name == "openscap-scanner"
Example #7
0
def test_scap_security_guide_paths():
    data = PolicyData()
    data.content_type = "scap-security-guide"
    data.profile_id = "Web Server"
    data.content_path = "/usr/share/xml/scap/ssg/content.xml"

    expected_msg = "Using scap-security-guide, no single content file"
    with pytest.raises(ValueError, match=expected_msg):
        common.get_content_name(data)

    expected_path = None
    assert common.get_raw_preinst_content_path(data) == expected_path

    expected_path = "/usr/share/xml/scap/ssg/content.xml"
    assert common.get_preinst_content_path(data) == expected_path

    expected_path = "/usr/share/xml/scap/ssg/content.xml"
    assert common.get_postinst_content_path(data) == expected_path

    expected_path = ""
    assert common.get_preinst_tailoring_path(data) == expected_path

    expected_path = ""
    assert common.get_postinst_tailoring_path(data) == expected_path