def test_osco_simulate_no_overwrite(tmp_path): """Test simulate no overwrite call.""" config = configparser.ConfigParser() config_path = pathlib.Path( 'tests/data/tasks/osco/test-osco-to-oscal.config') config.read(config_path) section = config['task.osco-to-oscal'] section['output-dir'] = str(tmp_path) tgt = osco_to_oscal.OscoToOscal(section) retval = tgt.execute() assert retval == TaskOutcome.SUCCESS assert len(os.listdir(str(tmp_path))) == 1 section['output-overwrite'] = 'false' section['output-dir'] = str(tmp_path) tgt = osco_to_oscal.OscoToOscal(section) retval = tgt.simulate() assert retval == TaskOutcome.SIM_FAILURE assert len(os.listdir(str(tmp_path))) == 1
def test_osco_print_info(tmp_path): """Test print_info call.""" config = configparser.ConfigParser() config_path = pathlib.Path( 'tests/data/tasks/osco/test-osco-to-oscal.config') config.read(config_path) section = config['task.osco-to-oscal'] section['output-dir'] = str(tmp_path) tgt = osco_to_oscal.OscoToOscal(section) retval = tgt.print_info() assert retval is None
def test_osco_simulate_input_bad_yaml(tmp_path): """Test simulate call OSCO bad yaml data.""" config = configparser.ConfigParser() config_path = pathlib.Path( 'tests/data/tasks/osco/test-osco-to-oscal-bad-yaml.config') config.read(config_path) section = config['task.osco-to-oscal'] section['output-dir'] = str(tmp_path) tgt = osco_to_oscal.OscoToOscal(section) retval = tgt.simulate() assert retval == TaskOutcome.SIM_FAILURE assert len(os.listdir(str(tmp_path))) == 0
def test_osco_simulate_compressed(tmp_path): """Test simulate call with compressed OSCO xml data.""" config = configparser.ConfigParser() config_path = pathlib.Path( 'tests/data/tasks/osco/test-osco-to-oscal-compressed.config') config.read(config_path) section = config['task.osco-to-oscal'] section['output-dir'] = str(tmp_path) tgt = osco_to_oscal.OscoToOscal(section) retval = tgt.simulate() assert retval == TaskOutcome.SIM_SUCCESS assert len(os.listdir(str(tmp_path))) == 0
def test_osco_execute_no_ouput_dir(tmp_path): """Test execute with no output dir call.""" config = configparser.ConfigParser() config_path = pathlib.Path( 'tests/data/tasks/osco/test-osco-to-oscal.config') config.read(config_path) config.remove_option('task.osco-to-oscal', 'output-dir') section = config['task.osco-to-oscal'] tgt = osco_to_oscal.OscoToOscal(section) retval = tgt.execute() assert retval == TaskOutcome.FAILURE assert len(os.listdir(str(tmp_path))) == 0
def test_osco_execute_bad_timestamp(tmp_path): """Test execute with bad timestamp.""" config = configparser.ConfigParser() config_path = pathlib.Path( 'tests/data/tasks/osco/test-osco-to-oscal.config') config.read(config_path) section = config['task.osco-to-oscal'] section['timestamp'] = str('bogus') tgt = osco_to_oscal.OscoToOscal(section) retval = tgt.execute() assert retval == TaskOutcome.FAILURE assert len(os.listdir(str(tmp_path))) == 0
def test_simulate(tmpdir): """Test simulate call.""" config = configparser.ConfigParser() config_path = pathlib.Path( 'tests/data/tasks/osco/demo-osco-to-oscal.config') config.read(config_path) section = config['task.osco-to-oscal'] section['output-dir'] = str(tmpdir) tgt = osco_to_oscal.OscoToOscal(section) retval = tgt.simulate() assert retval == TaskOutcome.SIM_SUCCESS assert len(os.listdir(str(tmpdir))) == 0
def execute_no_overwrite_part2(tmpdir): """Attempt to overwrite.""" config = configparser.ConfigParser() config_path = pathlib.Path( 'tests/data/tasks/osco/demo-osco-to-oscal.config') config.read(config_path) section = config['task.osco-to-oscal'] section['output-overwrite'] = 'false' section['output-dir'] = str(tmpdir) tgt = osco_to_oscal.OscoToOscal(section) retval = tgt.execute() assert retval == TaskOutcome.FAILURE
def execute_no_overwrite_part1(tmpdir): """Create expected output.""" config = configparser.ConfigParser() config_path = pathlib.Path( 'tests/data/tasks/osco/demo-osco-to-oscal.config') config.read(config_path) section = config['task.osco-to-oscal'] section['output-dir'] = str(tmpdir) tgt = osco_to_oscal.OscoToOscal(section) retval = tgt.execute() assert retval == TaskOutcome.SUCCESS assert len(os.listdir(str(tmpdir))) == 1
def test_simulate_no_input_dir(tmpdir): """Test simulate with no input dir call.""" config = configparser.ConfigParser() config_path = pathlib.Path( 'tests/data/tasks/osco/demo-osco-to-oscal.config') config.read(config_path) config.remove_option('task.osco-to-oscal', 'input-dir') section = config['task.osco-to-oscal'] section['output-dir'] = str(tmpdir) tgt = osco_to_oscal.OscoToOscal(section) retval = tgt.simulate() assert retval == TaskOutcome.SIM_FAILURE assert len(os.listdir(str(tmpdir))) == 0
def test_simulate_no_oscal_metadata_file(tmpdir): """Test simulate with no metadata file call.""" config = configparser.ConfigParser() config_path = pathlib.Path( 'tests/data/tasks/osco/demo-osco-to-oscal-no-oscal-metadata.config') config.read(config_path) section = config['task.osco-to-oscal'] section['input-metadata'] = 'non-existant.yaml' section['output-dir'] = str(tmpdir) tgt = osco_to_oscal.OscoToOscal(section) retval = tgt.simulate() assert retval == TaskOutcome.SIM_SUCCESS assert len(os.listdir(str(tmpdir))) == 0
def execute_no_overwrite_part2(tmp_path, monkeypatch: MonkeyPatch): """Attempt to overwrite.""" monkeybusiness = MonkeyBusiness() monkeypatch.setattr(uuid, 'uuid4', monkeybusiness.uuid_mock2) osco.OscoTransformer.set_timestamp('2021-02-24T19:31:13+00:00') config = configparser.ConfigParser() config_path = pathlib.Path( 'tests/data/tasks/osco/test-osco-to-oscal.config') config.read(config_path) section = config['task.osco-to-oscal'] section['output-overwrite'] = 'false' section['output-dir'] = str(tmp_path) tgt = osco_to_oscal.OscoToOscal(section) retval = tgt.execute() assert retval == TaskOutcome.FAILURE
def test_execute_compressed(tmpdir): """Test execute call with compressed OSCO xml data.""" config = configparser.ConfigParser() config_path = pathlib.Path( 'tests/data/tasks/osco/demo-osco-to-oscal-compressed.config') config.read(config_path) section = config['task.osco-to-oscal'] section['output-dir'] = str(tmpdir) tgt = osco_to_oscal.OscoToOscal(section) retval = tgt.execute() assert retval == TaskOutcome.SUCCESS assert len(os.listdir(str(tmpdir))) == 1 f_expected = pathlib.Path('tests/data/tasks/osco/output/' ) / 'ssg-ocp4-ds-cis-111.222.333.444-pod.json' f_produced = tmpdir / 'ssg-ocp4-ds-cis-111.222.333.444-pod.json' assert [row for row in open(f_produced)] == [row for row in open(f_expected)]
def test_execute_no_oscal_metadata_file(tmpdir): """Test execute with no metadata file call.""" config = configparser.ConfigParser() config_path = pathlib.Path( 'tests/data/tasks/osco/demo-osco-to-oscal-no-oscal-metadata.config') config.read(config_path) section = config['task.osco-to-oscal'] section['input-metadata'] = 'non-existant.yaml' section['output-dir'] = str(tmpdir) tgt = osco_to_oscal.OscoToOscal(section) retval = tgt.execute() assert retval == TaskOutcome.SUCCESS assert len(os.listdir(str(tmpdir))) == 1 f_expected = pathlib.Path('tests/data/tasks/osco/output-no-oscal-metadata/' ) / 'ssg-ocp4-ds-cis-111.222.333.444-pod.json' f_produced = tmpdir / 'ssg-ocp4-ds-cis-111.222.333.444-pod.json' assert [row for row in open(f_produced)] == [row for row in open(f_expected)]
def test_osco_execute_input_configmaps(tmp_path, monkeypatch: MonkeyPatch): """Test execute call OSCO configmaps data.""" monkeybusiness = MonkeyBusiness() monkeypatch.setattr(uuid, 'uuid4', monkeybusiness.uuid_mock1) osco.OscoTransformer.set_timestamp('2021-02-24T19:31:13+00:00') config = configparser.ConfigParser() config_path = pathlib.Path( 'tests/data/tasks/osco/test-osco-to-oscal-configmaps.config') config.read(config_path) section = config['task.osco-to-oscal'] d_expected = pathlib.Path(section['output-dir']) d_produced = tmp_path section['output-dir'] = str(d_produced) tgt = osco_to_oscal.OscoToOscal(section) retval = tgt.execute() assert retval == TaskOutcome.SUCCESS list_dir = os.listdir(d_produced) assert len(list_dir) == 1 for fn in list_dir: f_expected = d_expected / fn f_produced = d_produced / fn result = text_files_equal(f_expected, f_produced) assert (result)
def test_osco_simulate_no_config(tmp_path): """Test simulate no config call.""" tgt = osco_to_oscal.OscoToOscal(None) retval = tgt.simulate() assert retval == TaskOutcome.SIM_FAILURE assert len(os.listdir(str(tmp_path))) == 0
def test_execute_no_config(tmpdir): """Test execute no config call.""" tgt = osco_to_oscal.OscoToOscal(None) retval = tgt.execute() assert retval == TaskOutcome.FAILURE assert len(os.listdir(str(tmpdir))) == 0