コード例 #1
0
    def test_generate_and_store_file_objects_zero_file(self):
        file_paths = ['{}/zero_byte'.format(get_test_data_dir()), '{}/get_files_test/testfile1'.format(get_test_data_dir())]
        moved_files = self.unpacker.move_extracted_files(file_paths, get_test_data_dir())

        self.assertEqual(len(moved_files), 1, 'number of objects not correct')
        self.assertEqual(moved_files[0].name, 'testfile1', 'wrong object created')
        self.assertIn('/get_files_test/testfile1', str(moved_files[0].absolute()))
コード例 #2
0
 def test_file_is_zero(self):
     self.assertTrue(
         file_is_empty('{}/zero_byte'.format(get_test_data_dir())),
         'file is empty but stated differently')
     self.assertFalse(
         file_is_empty('{}/get_files_test/testfile1'.format(
             get_test_data_dir())), 'file not empty but stated differently')
     self.assertFalse(
         file_is_empty(os.path.join(get_test_data_dir(), 'broken_link')),
         'Broken link is not empty')
コード例 #3
0
    def test_move_extracted_files(self, mock_shutil):
        file_paths = [f'{get_test_data_dir()}/fake_file', f'{get_test_data_dir()}/get_files_test/testfile1']
        moved_files = self.unpacker.move_extracted_files(file_paths, get_test_data_dir())

        self.assertEqual(len(moved_files), 2, 'number of objects not correct')
        self.assertEqual(moved_files[1].name, 'testfile1', 'wrong object created')
        self.assertIn('/get_files_test/testfile1', str(moved_files[1].absolute()))
コード例 #4
0
 def test_extraction(self):
     in_file = '{}/generic_carver_test'.format(get_test_data_dir())
     files, meta_data = self.unpacker._extract_files_from_file_using_specific_unpacker(in_file, self.tmp_dir.name, self.unpacker.unpacker_plugins['generic/carver'])
     files = set(files)
     self.assertEqual(len(files), 1, 'file number incorrect')
     self.assertEqual(files, {'{}/64.zip'.format(self.tmp_dir.name)}, 'not all files found')
     self.assertIn('output', meta_data)
コード例 #5
0
ファイル: test_npk.py プロジェクト: sung3r/fact_extractor
    def test_extraction_bad_file():
        file_path = str(Path(get_test_data_dir(), 'test_data_file.bin'))

        with TemporaryDirectory() as tmp_dir:
            meta_data = unpack_function(file_path, tmp_dir)

        assert 'Invalid' in meta_data['error']
コード例 #6
0
 def test_extraction(self):
     in_file = "{}/generic_carver_test".format(get_test_data_dir())
     files, meta_data = self.unpacker.extract_files_from_file(in_file, self.tmp_dir.name)
     files = set(files)
     self.assertEqual(len(files), 1, "file number incorrect")
     self.assertEqual(files, {'{}/_generic_carver_test.extracted/64.zip'.format(self.tmp_dir.name)}, "not all files found")
     self.assertIn('output', meta_data)
コード例 #7
0
ファイル: test_srec.py プロジェクト: JRomainG/fact_extractor
    def test_extraction_bad_file():
        file_path = Path(get_test_data_dir(), 'test_data_file.bin')

        with TemporaryDirectory() as tmp_dir:
            meta_data = unpack_function(file_path, tmp_dir)

        assert 'not starting with an \'S\'' in meta_data['output']
コード例 #8
0
    def test_extraction_bad_file():
        file_path = Path(get_test_data_dir(), 'test_data_file.bin')

        with TemporaryDirectory() as tmp_dir:
            meta_data = unpack_function(file_path, tmp_dir)

        assert 'Failed to slice tek record' in meta_data['output']
コード例 #9
0
 def test_extraction(self):
     in_file = '{}/generic_carver_test'.format(get_test_data_dir())
     files, meta_data = self.unpacker._extract_files_from_file_using_specific_unpacker(in_file, self.tmp_dir.name, self.unpacker.unpacker_plugins['generic/carver'])
     files = set(files)
     assert len(files) == 1, 'file number incorrect'
     assert files == {'{}/64.zip'.format(self.tmp_dir.name)}, 'not all files found'
     assert 'output' in meta_data
     assert 'filter_log' in meta_data
コード例 #10
0
    def test_move_extracted_files_raise_assert(self, mock_shutil):
        file_paths = [f'{get_test_data_dir()}/fake_file', f'{get_test_data_dir()}/get_files_test/testfile1']
        # Raise exception once, so fake_file shouldn't exist is the returned moved_files
        mock_shutil.side_effect = [OSError('File exists'), '']

        moved_files = self.unpacker.move_extracted_files(file_paths, get_test_data_dir())

        self.assertEqual(len(moved_files), 1, 'number of objects not correct')
        self.assertEqual(moved_files[0].name, 'testfile1', 'wrong object created')
        self.assertIn('/get_files_test/testfile1', str(moved_files[0].absolute()))
コード例 #11
0
    def _unpack_fallback_check(self, fallback_mime, fallback_plugin_name):
        broken_zip = Path(get_test_data_dir(), 'container/broken.zip')
        self.unpacker.unpack(broken_zip)
        meta_data = self.get_unpacker_meta()

        self.assertEqual(meta_data['0_ERROR_7z'][0:6], '\n7-Zip')
        self.assertEqual(meta_data['0_FALLBACK_7z'], '7z (failed) -> {} (fallback)'.format(fallback_mime))
        self.assertEqual(meta_data['plugin_used'], fallback_plugin_name)

        return meta_data
コード例 #12
0
    def test_extract_everything(self):
        self.unpacker.extract_everything = True
        file_paths = [
            f'{get_test_data_dir()}/zero_byte',
            f'{get_test_data_dir()}/get_files_test/testfile1'
        ]
        moved_files = self.unpacker.move_extracted_files(
            file_paths, get_test_data_dir())
        moved_files.sort()

        self.assertEqual(len(moved_files), 2, 'number of objects not correct')
        self.assertEqual(moved_files[1].name, 'zero_byte',
                         'empty files should not be discarded')
コード例 #13
0
def test_unpack_status_packed_file(config_fixture):
    test_packed_file_path = Path(get_test_data_dir(), 'container/test.7z')

    result = dict()
    get_unpack_status(test_packed_file_path, test_packed_file_path.read_bytes(), list(), result, config_fixture)

    assert result['entropy'] > 0.7, 'entropy not valid'
    assert result['summary'] == ['packed'], '7z file should be packed'

    result = dict()
    config_fixture.set('ExpertSettings', 'compressed_file_types', 'application/x-7z-compressed, ')
    get_unpack_status(test_packed_file_path, test_packed_file_path.read_bytes(), list(), result, config_fixture)
    assert result['summary'] == ['unpacked'], 'Unpacking Whitelist does not work'
コード例 #14
0
    def setUp(self):
        self.config = ConfigParser()
        self.ds_tmp_dir = TemporaryDirectory(prefix='fact_tests_')
        self.tmp_dir = TemporaryDirectory(prefix='fact_tests_')

        self.config.add_section('unpack')
        self.config.set('unpack', 'data_folder', self.ds_tmp_dir.name)
        self.config.set('unpack', 'blacklist', 'text/plain, image/png')
        self.config.add_section('ExpertSettings')
        self.config.set('ExpertSettings', 'header_overhead', '256')

        self.unpacker = Unpacker(config=self.config)
        os.makedirs(str(self.unpacker._report_folder), exist_ok=True)
        os.makedirs(str(self.unpacker._file_folder), exist_ok=True)

        self.test_file_path = Path(get_test_data_dir(),
                                   'get_files_test/testfile1')
コード例 #15
0
 def test_main_unpack_exclude_files(self):
     test_file_path = Path(get_test_data_dir(), 'container/test.zip')
     self.unpacker.exclude = ['*/get_files_test/*test*']
     self.main_unpack_check(test_file_path, 0, 3, '7z')
コード例 #16
0
 def test_main_unpack_exclude_subdirectory(self):
     test_file_path = Path(get_test_data_dir(), 'container/test.zip')
     self.unpacker.exclude = ['*/generic folder/*']
     self.main_unpack_check(test_file_path, 2, 1, '7z')
コード例 #17
0
 def test_main_unpack_exclude_archive(self):
     test_file_path = Path(get_test_data_dir(), 'container/test.zip')
     self.unpacker.exclude = ['*test.zip']
     self.main_unpack_check(test_file_path, 0, 1, None)
コード例 #18
0
 def test_main_unpack_function(self):
     test_file_path = Path(get_test_data_dir(), 'container/test.zip')
     self.main_unpack_check(test_file_path, 3, 0, '7z')
コード例 #19
0
def test_read_list_from_config__key_not_in_config(monkeypatch):
    monkeypatch.setattr('helperFunctions.config.get_config_dir', lambda: '{}/helperFunctions'.format(get_test_data_dir()))
    test_config = load_config('test.cfg')
    result = read_list_from_config(test_config, 'foo', 'bar')
    assert result == []

    result = read_list_from_config(test_config, 'test', 'bar')
    assert result == []
コード例 #20
0
def test_read_list_from_config(monkeypatch, input_data, expected):
    monkeypatch.setattr('helperFunctions.config.get_config_dir', lambda: '{}/helperFunctions'.format(get_test_data_dir()))
    test_config = load_config('test.cfg')
    test_config.add_section('test_section')
    test_config.set('test_section', 'test_option', input_data)
    result = read_list_from_config(test_config, 'test_section', 'test_option')
    assert result == expected
コード例 #21
0
def test_load_config(monkeypatch):
    monkeypatch.setattr('helperFunctions.config.get_config_dir', lambda: '{}/helperFunctions'.format(get_test_data_dir()))
    test_config = load_config('test.cfg')
    assert test_config['test']['test'] == 'test_config', 'config not correct'
コード例 #22
0
    def test_extraction_bad_file():
        file_path = Path(get_test_data_dir(), 'test_data_file.bin')

        meta_data = meta_data_for_failed_analysis(file_path)

        assert 'Invalid characters in record' in meta_data['output']
コード例 #23
0
 def test_file_is_zero_broken_link(self):
     self.assertFalse(
         file_is_empty(os.path.join(get_test_data_dir(), 'broken_link')),
         'Broken link is not empty')
コード例 #24
0
def test_unpack_with_bad_file(tmpdir):
    meta_data = unpack_function(
        str(Path(get_test_data_dir()) / 'generic_carver_test'), str(tmpdir))
    assert 'error' in meta_data
    assert 'Unknown ros header' in meta_data['error']