diff options
author | Michael Weiser <michael.weiser@gmx.de> | 2019-01-22 14:11:22 +0000 |
---|---|---|
committer | Michael Weiser <michael.weiser@gmx.de> | 2019-01-22 16:41:34 +0000 |
commit | 7f039c16d3383537e52589a03e31c8dfec928ecf (patch) | |
tree | 5eb97ecac46126876bebf8a0e67c24ddd7a0ae82 /test.py | |
parent | fb0a41f82befcc413f3028c84664f35c91d9b059 (diff) |
Rework rule result reason handling in Sample
Sample's reason property has only one user: analysis_save() of
PeekabooDatabase. We only save the analysis result after running the
ruleset and at the end of that RulesetEngine.report() which runs
Sample.report() which runs Sample.determine_result() which sets the
reason based on what the ruleset has done. So having a logic in the
reason property that goes looking for a reason in the database is
redundant.
We turn the reason property into a getter Sample.get_reason() to catch
other, undetected users and get in line with Sample.get_result(). The
reason returned by the getter will now be None for a freshly created
Sample because that reflects that no analysis has been done on it yet.
Removing the database lookup from the reason property in turn makes
PeekabooDatabase.fetch_rule_result() redundant so we remove that as
well.
Diffstat (limited to 'test.py')
-rw-r--r-- | test.py | 15 |
1 files changed, 5 insertions, 10 deletions
@@ -86,14 +86,10 @@ class TestDatabase(unittest.TestCase): sample_info = self.db_con.sample_info_fetch(self.sample) self.assertEqual(self.sample.sha256sum, sample_info.sha256sum) - def test_3_fetch_rule_result(self): - rule_result = self.db_con.fetch_rule_result(self.sample) - # RuleResults from the DB have 'db' as rule name - self.assertEqual(rule_result.rule, 'db') - self.assertEqual(rule_result.result, Result.checked) - self.assertEqual(rule_result.reason, 'This is just a test case.') - # We assert True since the DB rule result always sets further_analysis to True - self.assertTrue(rule_result.further_analysis) + def test_3_fetch_result(self): + sample_info = self.db_con.sample_info_fetch(self.sample) + self.assertEqual(sample_info.result, Result.checked) + self.assertEqual(sample_info.reason, 'This is just a test case.') def test_4_known(self): self.assertTrue(self.db_con.known(self.sample)) @@ -233,8 +229,7 @@ class TestSample(unittest.TestCase): self.assertIsNotNone(self.sample.sha256sum) self.assertEqual(self.sample.job_id, -1) self.assertEqual(self.sample.get_result(), Result.unchecked) - self.assertEqual(self.sample.reason, - 'Ausschlaggebendes Ergebnis laut Datenbank: Datei ist dem System noch nicht bekannt') + self.assertEqual(self.sample.get_reason(), None) self.assertFalse(self.sample.office_macros) self.assertFalse(self.sample.known) |