Beispiel #1
0
    def test_process_next_analysis_unknown_plugin(self):
        test_fw = Firmware(file_path=os.path.join(get_test_data_dir(), 'get_files_test/testfile1'))
        test_fw.scheduled_analysis = ['unknown_plugin']

        with mock_spy(self.sched, '_start_or_skip_analysis') as spy:
            self.sched.process_next_analysis(test_fw)
            assert not spy.was_called(), 'unknown plugin should simply be skipped'
Beispiel #2
0
 def test_skip_analysis_because_whitelist(self):
     self.sched.config.set('dummy_plugin_for_testing_only', 'mime_whitelist', 'foo, bar')
     test_fw = Firmware(file_path=os.path.join(get_test_data_dir(), 'get_files_test/testfile1'))
     test_fw.scheduled_analysis = ['file_hashes']
     test_fw.processed_analysis['file_type'] = {'mime': 'text/plain'}
     self.sched._start_or_skip_analysis('dummy_plugin_for_testing_only', test_fw)
     test_fw = self.tmp_queue.get(timeout=10)
     assert 'dummy_plugin_for_testing_only' in test_fw.processed_analysis
     assert 'skipped' in test_fw.processed_analysis['dummy_plugin_for_testing_only']
Beispiel #3
0
 def test_whole_run_analysis_selected(self):
     test_fw = Firmware(file_path=os.path.join(get_test_data_dir(), 'get_files_test/testfile1'))
     test_fw.scheduled_analysis = ['dummy_plugin_for_testing_only']
     self.sched.add_task(test_fw)
     test_fw = self.tmp_queue.get(timeout=10)
     self.assertEqual(len(test_fw.processed_analysis), 3, 'analysis not done')
     self.assertEqual(test_fw.processed_analysis['dummy_plugin_for_testing_only']['1'], 'first result', 'result not correct')
     self.assertEqual(test_fw.processed_analysis['dummy_plugin_for_testing_only']['summary'], ['first result', 'second result'])
     self.assertIn('file_hashes', test_fw.processed_analysis.keys(), 'Mandatory plug-in not executed')
     self.assertIn('file_type', test_fw.processed_analysis.keys(), 'Mandatory plug-in not executed')
Beispiel #4
0
    def test_reschedule_failed_analysis_task(self):
        task = Firmware(binary='foo')
        error_message = 'There was an exception'
        task.analysis_exception = ('foo', error_message)
        task.scheduled_analysis = ['no_deps', 'bar']
        task.processed_analysis['foo'] = {'error': 1}
        self._add_plugins()
        self.scheduler._reschedule_failed_analysis_task(task)

        assert 'foo' in task.processed_analysis
        assert task.processed_analysis['foo'] == {'failed': error_message}
        assert 'bar' not in task.scheduled_analysis
        assert 'bar' in task.processed_analysis
        assert task.processed_analysis['bar'] == {'failed': 'Analysis of dependency foo failed'}
        assert 'no_deps' in task.scheduled_analysis
Beispiel #5
0
    def test_run_analysis_with_tag(self):
        test_fw = Firmware(file_path='{}/container/with_key.7z'.format(get_test_data_dir()))
        test_fw.release_date = '2017-01-01'
        test_fw.scheduled_analysis = ['crypto_material']

        self._unpack_scheduler.add_task(test_fw)

        assert self.analysis_finished_event.wait(timeout=20)

        processed_fo = self.backend_interface.get_object(self.uid_of_key_file, analysis_filter=['crypto_material'])
        assert processed_fo.processed_analysis['crypto_material']['tags'], 'no tags set in analysis'

        processed_fw = self.backend_interface.get_object(test_fw.uid, analysis_filter=['crypto_material'])
        assert processed_fw.analysis_tags, 'tags not propagated properly'
        assert processed_fw.analysis_tags['crypto_material']['private_key_inside']