def testAnalyzeFile(self):
        """Read a storage file that contains URL data and analyze it."""
        knowledge_base = self._SetUpKnowledgeBase()

        test_file = self._GetTestFilePath(['History'])
        event_queue = self._ParseFile(self._parser, test_file, knowledge_base)

        analysis_plugin = browser_search.BrowserSearchPlugin(event_queue)
        analysis_report_queue_consumer = self._RunAnalysisPlugin(
            analysis_plugin, knowledge_base)
        analysis_reports = self._GetAnalysisReportsFromQueue(
            analysis_report_queue_consumer)

        self.assertEqual(len(analysis_reports), 1)

        analysis_report = analysis_reports[0]

        # Due to the behavior of the join one additional empty string at the end
        # is needed to create the last empty line.
        expected_text = u'\n'.join([
            u' == ENGINE: GoogleSearch ==', u'1 really really funny cats',
            u'1 java plugin', u'1 funnycats.exe', u'1 funny cats', u'', u''
        ])

        self.assertEqual(analysis_report.text, expected_text)
        self.assertEqual(analysis_report.plugin_name, 'browser_search')

        expected_keys = set([u'GoogleSearch'])
        self.assertEqual(set(analysis_report.report_dict.keys()),
                         expected_keys)
    def testExamineEventAndCompileReport(self):
        """Tests the ExamineEvent and CompileReport functions."""
        parser = sqlite.SQLiteParser()
        plugin = browser_search.BrowserSearchPlugin()

        storage_writer = self._ParseAndAnalyzeFile(['History'], parser, plugin)

        self.assertEqual(storage_writer.number_of_events, 71)

        self.assertEqual(len(storage_writer.analysis_reports), 1)

        analysis_report = storage_writer.analysis_reports[0]

        # Due to the behavior of the join one additional empty string at the end
        # is needed to create the last empty line.
        expected_text = '\n'.join([
            ' == ENGINE: Google Search ==', '1 really really funny cats',
            '1 java plugin', '1 funnycats.exe', '1 funny cats', '', ''
        ])

        self.assertEqual(analysis_report.text, expected_text)
        self.assertEqual(analysis_report.plugin_name, 'browser_search')

        expected_keys = set(['Google Search'])
        self.assertEqual(set(analysis_report.report_dict.keys()),
                         expected_keys)
Beispiel #3
0
    def testExamineEventAndCompileReport(self):
        """Tests the ExamineEvent and CompileReport functions."""
        parser = sqlite.SQLiteParser()
        plugin = browser_search.BrowserSearchPlugin()

        storage_writer = self._ParseAndAnalyzeFile(['History'], parser, plugin)

        analysis_results = list(
            storage_writer.GetAttributeContainers(
                'browser_search_analysis_result'))
        self.assertEqual(len(analysis_results), 4)

        analysis_result = analysis_results[2]
        self.assertEqual(analysis_result.search_engine, 'Google Search')
        self.assertEqual(analysis_result.search_term,
                         'really really funny cats')
        self.assertEqual(analysis_result.number_of_queries, 1)

        number_of_reports = storage_writer.GetNumberOfAttributeContainers(
            'analysis_report')
        self.assertEqual(number_of_reports, 1)

        analysis_report = storage_writer.GetAttributeContainerByIndex(
            reports.AnalysisReport.CONTAINER_TYPE, 0)
        self.assertIsNotNone(analysis_report)

        self.assertEqual(analysis_report.plugin_name, 'browser_search')

        expected_analysis_counter = collections.Counter({
            'Google Search:funny cats':
            1,
            'Google Search:funnycats.exe':
            1,
            'Google Search:java plugin':
            1,
            'Google Search:really really funny cats':
            1
        })
        self.assertEqual(analysis_report.analysis_counter,
                         expected_analysis_counter)