|
Packit Service |
39273c |
import os
|
|
Packit Service |
39273c |
|
|
Packit Service |
39273c |
import pytest
|
|
Packit Service |
39273c |
|
|
Packit Service |
39273c |
from org_fedora_oscap import content_handling as ch
|
|
Packit Service |
39273c |
|
|
Packit Service |
39273c |
|
|
Packit Service |
39273c |
TESTING_FILES_PATH = os.path.join(
|
|
Packit Service |
39273c |
os.path.dirname(__file__), os.path.pardir, "testing_files")
|
|
Packit Service |
39273c |
DS_FILEPATH = os.path.join(
|
|
Packit Service |
39273c |
TESTING_FILES_PATH, "testing_ds.xml")
|
|
Packit Service |
39273c |
|
|
Packit Service |
39273c |
DS_IDS = "scap_org.open-scap_datastream_tst"
|
|
Packit Service |
39273c |
CHK_FIRST_ID = "scap_org.open-scap_cref_first-xccdf.xml"
|
|
Packit Service |
39273c |
CHK_SECOND_ID = "scap_org.open-scap_cref_second-xccdf.xml"
|
|
Packit Service |
39273c |
|
|
Packit Service |
39273c |
PROFILE1_ID = "xccdf_com.example_profile_my_profile"
|
|
Packit Service |
39273c |
PROFILE2_ID = "xccdf_com.example_profile_my_profile2"
|
|
Packit Service |
39273c |
PROFILE3_ID = "xccdf_com.example_profile_my_profile3"
|
|
Packit Service |
39273c |
|
|
Packit Service |
39273c |
|
|
Packit Service |
39273c |
@pytest.fixture()
|
|
Packit Service |
39273c |
def ds_handler():
|
|
Packit Service |
39273c |
return ch.DataStreamHandler(DS_FILEPATH)
|
|
Packit Service |
39273c |
|
|
Packit Service |
39273c |
|
|
Packit Service |
39273c |
def test_init_invalid_file_path():
|
|
Packit Service |
39273c |
with pytest.raises(ch.DataStreamHandlingError) as excinfo:
|
|
Packit Service |
39273c |
ch.DataStreamHandler("testing_ds.xmlll")
|
|
Packit Service |
39273c |
assert "Invalid file path" in str(excinfo.value)
|
|
Packit Service |
39273c |
|
|
Packit Service |
39273c |
|
|
Packit Service |
39273c |
def test_init_not_scap_content():
|
|
Packit Service |
39273c |
with pytest.raises(ch.DataStreamHandlingError) as excinfo:
|
|
Packit Service |
39273c |
ch.DataStreamHandler(os.path.join(TESTING_FILES_PATH, "testing_ks.cfg"))
|
|
Packit Service |
39273c |
assert "not a valid SCAP content file" in str(excinfo.value)
|
|
Packit Service |
39273c |
|
|
Packit Service |
39273c |
|
|
Packit Service |
39273c |
def test_init_xccdf_content():
|
|
Packit Service |
39273c |
with pytest.raises(ch.DataStreamHandlingError) as excinfo:
|
|
Packit Service |
39273c |
ch.DataStreamHandler(os.path.join(TESTING_FILES_PATH, "xccdf.xml"))
|
|
Packit Service |
39273c |
assert "not a data stream collection" in str(excinfo.value)
|
|
Packit Service |
39273c |
|
|
Packit Service |
39273c |
|
|
Packit Service |
39273c |
def test_get_data_streams(ds_handler):
|
|
Packit Service |
39273c |
assert DS_IDS in ds_handler.get_data_streams()
|
|
Packit Service |
39273c |
|
|
Packit Service |
39273c |
|
|
Packit Service |
39273c |
def test_get_data_streams_checklists(ds_handler):
|
|
Packit Service |
39273c |
expected_ids = {DS_IDS: [CHK_FIRST_ID, CHK_SECOND_ID]}
|
|
Packit Service |
39273c |
|
|
Packit Service |
39273c |
ds_ids = ds_handler.get_data_streams_checklists()
|
|
Packit Service |
39273c |
assert expected_ids == ds_ids
|
|
Packit Service |
39273c |
|
|
Packit Service |
39273c |
|
|
Packit Service |
39273c |
def test_get_checklists(ds_handler):
|
|
Packit Service |
39273c |
expected_checklists = [CHK_FIRST_ID, CHK_SECOND_ID]
|
|
Packit Service |
39273c |
|
|
Packit Service |
39273c |
chk_ids = ds_handler.get_checklists(DS_IDS)
|
|
Packit Service |
39273c |
assert expected_checklists == chk_ids
|
|
Packit Service |
39273c |
|
|
Packit Service |
39273c |
|
|
Packit Service |
39273c |
def test_get_checklists_invalid(ds_handler):
|
|
Packit Service |
39273c |
with pytest.raises(ch.DataStreamHandlingError) as excinfo:
|
|
Packit Service |
39273c |
ds_handler.get_checklists("invalid.id")
|
|
Packit Service |
39273c |
assert "Invalid data stream id given" in str(excinfo.value)
|
|
Packit Service |
39273c |
|
|
Packit Service |
39273c |
|
|
Packit Service |
39273c |
def test_get_profiles(ds_handler):
|
|
Packit Service |
39273c |
profile_ids = ds_handler.get_profiles(DS_IDS, CHK_FIRST_ID)
|
|
Packit Service |
39273c |
|
|
Packit Service |
39273c |
# When Benchmark doesn't contain Rules selected by default
|
|
Packit Service |
39273c |
# the default Profile should not be present
|
|
Packit Service |
39273c |
assert 2 == len(profile_ids)
|
|
Packit Service |
39273c |
assert PROFILE1_ID == profile_ids[0].id
|
|
Packit Service |
39273c |
assert PROFILE2_ID == profile_ids[1].id
|
|
Packit Service |
39273c |
|
|
Packit Service |
39273c |
|
|
Packit Service |
39273c |
def test_get_profiles_with_default(ds_handler):
|
|
Packit Service |
39273c |
profile_ids = ds_handler.get_profiles(DS_IDS, CHK_SECOND_ID)
|
|
Packit Service |
39273c |
|
|
Packit Service |
39273c |
# When Benchmark contains Rules selected by default
|
|
Packit Service |
39273c |
# the default Profile should be present
|
|
Packit Service |
39273c |
assert 2 == len(profile_ids)
|
|
Packit Service |
39273c |
assert "default" == profile_ids[0].id
|
|
Packit Service |
39273c |
assert PROFILE3_ID == profile_ids[1].id
|