def test_tanium_execute_override_timestamp(tmp_path, monkeypatch: MonkeyPatch):
    """Test execute override timestamp call."""
    monkeybusiness = MonkeyBusiness()
    monkeypatch.setattr(tanium, '_uuid_component',
                        monkeybusiness.uuid_component)
    monkeypatch.setattr(tanium, '_uuid_inventory',
                        monkeybusiness.uuid_inventory)
    monkeypatch.setattr(tanium, '_uuid_observation',
                        monkeybusiness.uuid_observation)
    monkeypatch.setattr(tanium, '_uuid_result', monkeybusiness.uuid_result)
    tanium.TaniumTransformer.set_timestamp('2020-02-24T19:31:13+00:00')
    assert tanium.TaniumTransformer.get_timestamp(
    ) == '2020-02-24T19:31:13+00:00'
    config = configparser.ConfigParser()
    config_path = pathlib.Path(
        'tests/data/tasks/tanium/demo-tanium-to-oscal.config')
    config.read(config_path)
    section = config['task.tanium-to-oscal']
    section['output-dir'] = str(tmp_path)
    section['cpus-max'] = '1'
    tgt = tanium_to_oscal.TaniumToOscal(section)
    retval = tgt.execute()
    assert retval == TaskOutcome.SUCCESS
    assert len(os.listdir(str(tmp_path))) == 1
    f_expected = pathlib.Path(
        'tests/data/tasks/tanium/output/') / 'Tanium.oscal.2020.json'
    f_produced = tmp_path / 'Tanium.oscal.json'
    assert list(open(f_produced, encoding=const.FILE_ENCODING)) == list(
        open(f_expected, encoding=const.FILE_ENCODING))
def test_tanium_simulate_no_overwrite(tmp_path):
    """Test simulate no overwrite call."""
    config = configparser.ConfigParser()
    config_path = pathlib.Path(
        'tests/data/tasks/tanium/demo-tanium-to-oscal.config')
    config.read(config_path)
    section = config['task.tanium-to-oscal']
    section['output-dir'] = str(tmp_path)
    tgt = tanium_to_oscal.TaniumToOscal(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 = tanium_to_oscal.TaniumToOscal(section)
    retval = tgt.simulate()
    assert retval == TaskOutcome.SIM_FAILURE
    assert len(os.listdir(str(tmp_path))) == 1
def test_tanium_print_info(tmp_path):
    """Test print_info call."""
    config = configparser.ConfigParser()
    config_path = pathlib.Path(
        'tests/data/tasks/tanium/demo-tanium-to-oscal.config')
    config.read(config_path)
    section = config['task.tanium-to-oscal']
    section['output-dir'] = str(tmp_path)
    tgt = tanium_to_oscal.TaniumToOscal(section)
    retval = tgt.print_info()
    assert retval is None
def test_tanium_execute_no_ouput_dir(tmp_path):
    """Test execute with no output dir call."""
    config = configparser.ConfigParser()
    config_path = pathlib.Path(
        'tests/data/tasks/tanium/demo-tanium-to-oscal.config')
    config.read(config_path)
    config.remove_option('task.tanium-to-oscal', 'output-dir')
    section = config['task.tanium-to-oscal']
    tgt = tanium_to_oscal.TaniumToOscal(section)
    retval = tgt.execute()
    assert retval == TaskOutcome.FAILURE
    assert len(os.listdir(str(tmp_path))) == 0
def test_tanium_execute_bad_timestamp(tmp_path):
    """Test execute with bad timestamp."""
    config = configparser.ConfigParser()
    config_path = pathlib.Path(
        'tests/data/tasks/tanium/demo-tanium-to-oscal.config')
    config.read(config_path)
    section = config['task.tanium-to-oscal']
    section['timestamp'] = str('bogus')
    tgt = tanium_to_oscal.TaniumToOscal(section)
    retval = tgt.execute()
    assert retval == TaskOutcome.FAILURE
    assert len(os.listdir(str(tmp_path))) == 0
def test_tanium_simulate_bad_input_file(tmp_path):
    """Test simulate with bad input file call."""
    config = configparser.ConfigParser()
    config_path = pathlib.Path(
        'tests/data/tasks/tanium/demo-tanium-to-oscal.config')
    config.read(config_path)
    config.remove_option('task.tanium-to-oscal', 'input-dir')
    config.set('task.tanium-to-oscal', 'input-dir',
               'tests/data/tasks/tanium/input-bad')
    section = config['task.tanium-to-oscal']
    section['output-dir'] = str(tmp_path)
    tgt = tanium_to_oscal.TaniumToOscal(section)
    retval = tgt.simulate()
    assert retval == TaskOutcome.SIM_FAILURE
    assert len(os.listdir(str(tmp_path))) == 0
def execute_no_overwrite_dir_part2(tmp_path, monkeypatch: MonkeyPatch):
    """Attempt to overwrite."""
    monkeybusiness = MonkeyBusiness()
    monkeypatch.setattr(tanium, '_uuid_component',
                        monkeybusiness.uuid_component)
    monkeypatch.setattr(tanium, '_uuid_inventory',
                        monkeybusiness.uuid_inventory)
    monkeypatch.setattr(tanium, '_uuid_observation',
                        monkeybusiness.uuid_observation)
    monkeypatch.setattr(tanium, '_uuid_result', monkeybusiness.uuid_result)
    config = configparser.ConfigParser()
    config_path = pathlib.Path(
        'tests/data/tasks/tanium/demo-tanium-to-oscal.config')
    config.read(config_path)
    section = config['task.tanium-to-oscal']
    section['output-overwrite'] = 'false'
    section['output-dir'] = str(tmp_path)
    section['cpus-max'] = '1'
    tgt = tanium_to_oscal.TaniumToOscal(section)
    retval = tgt.execute()
    assert retval == TaskOutcome.FAILURE
def test_tanium_execute_cpus(tmp_path, monkeypatch: MonkeyPatch):
    """Test execute optional call."""
    monkeybusiness = MonkeyBusiness()
    monkeypatch.setattr(tanium, '_uuid_component',
                        monkeybusiness.uuid_component)
    monkeypatch.setattr(tanium, '_uuid_inventory',
                        monkeybusiness.uuid_inventory)
    monkeypatch.setattr(tanium, '_uuid_observation',
                        monkeybusiness.uuid_observation)
    monkeypatch.setattr(tanium, '_uuid_result', monkeybusiness.uuid_result)
    config = configparser.ConfigParser()
    config_path = pathlib.Path(
        'tests/data/tasks/tanium/demo-tanium-to-oscal.config')
    config.read(config_path)
    section = config['task.tanium-to-oscal']
    section['output-dir'] = str(tmp_path)
    # set values for number of CPUs to unattainable numbers forcing code to chose reasonable ones.
    section['cpus-max'] = '1000000'
    section['cpus-min'] = '2000000'
    tgt = tanium_to_oscal.TaniumToOscal(section)
    retval = tgt.execute()
    assert retval == TaskOutcome.SUCCESS
def test_tanium_execute_blocksize(tmp_path, monkeypatch: MonkeyPatch):
    """Test execute optional call."""
    monkeybusiness = MonkeyBusiness()
    monkeypatch.setattr(tanium, '_uuid_component',
                        monkeybusiness.uuid_component)
    monkeypatch.setattr(tanium, '_uuid_inventory',
                        monkeybusiness.uuid_inventory)
    monkeypatch.setattr(tanium, '_uuid_observation',
                        monkeybusiness.uuid_observation)
    monkeypatch.setattr(tanium, '_uuid_result', monkeybusiness.uuid_result)
    config = configparser.ConfigParser()
    config_path = pathlib.Path(
        'tests/data/tasks/tanium/demo-tanium-to-oscal.config')
    config.read(config_path)
    section = config['task.tanium-to-oscal']
    section['output-dir'] = str(tmp_path)
    section['blocksize'] = '0'
    section['cpus-max'] = '0'
    section['cpus-min'] = '0'
    tgt = tanium_to_oscal.TaniumToOscal(section)
    retval = tgt.execute()
    assert retval == TaskOutcome.SUCCESS
예제 #10
0
def test_tanium_execute_one_file(tmp_path, monkeypatch: MonkeyPatch):
    """Test execute call."""
    monkeybusiness = MonkeyBusiness()
    monkeypatch.setattr(tanium, '_uuid_component',
                        monkeybusiness.uuid_component)
    monkeypatch.setattr(tanium, '_uuid_inventory',
                        monkeybusiness.uuid_inventory)
    monkeypatch.setattr(tanium, '_uuid_observation',
                        monkeybusiness.uuid_observation)
    monkeypatch.setattr(tanium, '_uuid_result', monkeybusiness.uuid_result)
    tanium.TaniumTransformer.set_timestamp('2021-02-24T19:31:13+00:00')
    assert tanium.TaniumTransformer.get_timestamp(
    ) == '2021-02-24T19:31:13+00:00'
    config = configparser.ConfigParser()
    config_path = pathlib.Path(
        'tests/data/tasks/tanium/demo-tanium-to-oscal.config')
    config.read(config_path)
    section = config['task.tanium-to-oscal']
    section['output-dir'] = str(tmp_path)
    tgt = tanium_to_oscal.TaniumToOscal(section)
    retval = tgt.execute()
    assert retval == TaskOutcome.SUCCESS
    assert len(os.listdir(str(tmp_path))) == 1
예제 #11
0
def test_tanium_simulate_no_config(tmp_path):
    """Test simulate no config call."""
    tgt = tanium_to_oscal.TaniumToOscal(None)
    retval = tgt.simulate()
    assert retval == TaskOutcome.SIM_FAILURE
    assert len(os.listdir(str(tmp_path))) == 0