Fix repeated results due to global results[] variable

This commit is contained in:
Donncha Ó Cearbhaill 2022-01-07 18:24:24 +01:00
parent e85c70c603
commit b2e9f0361b
3 changed files with 16 additions and 7 deletions

View File

@ -8,18 +8,18 @@ from ..utils import get_backup_folder
class TestDatausageModule: class TestDatausageModule:
def test_datausage(self): def test_datausage(self):
m = Datausage(base_folder=get_backup_folder(), log=logging) m = Datausage(base_folder=get_backup_folder(), log=logging, results=[])
run_module(m) run_module(m)
assert len(m.results) == 42 assert len(m.results) == 42
assert len(m.timeline) == 60 assert len(m.timeline) == 60
assert len(m.detected) == 0 assert len(m.detected) == 0
def test_detection(self, indicator_file): def test_detection(self, indicator_file):
m = Datausage(base_folder=get_backup_folder(), log=logging) m = Datausage(base_folder=get_backup_folder(), log=logging, results=[])
ind = Indicators(log=logging) ind = Indicators(log=logging)
ind.parse_stix2(indicator_file) ind.parse_stix2(indicator_file)
# Adds a file that exists in the manifest # Adds a file that exists in the manifest
ind.ioc_processes[0] = "CumulativeUsageTracker" ind.ioc_processes[0] = "CumulativeUsageTracker"
m.indicators = ind m.indicators = ind
run_module(m) run_module(m)
assert len(m.detected) == 4 assert len(m.detected) == 2

View File

@ -9,18 +9,18 @@ from ..utils import get_backup_folder
class TestManifestModule: class TestManifestModule:
def test_manifest(self): def test_manifest(self):
m = Manifest(base_folder=get_backup_folder(), log=logging) m = Manifest(base_folder=get_backup_folder(), log=logging, results=[])
run_module(m) run_module(m)
assert len(m.results) == 3721 assert len(m.results) == 3721
assert len(m.timeline) == 5881 assert len(m.timeline) == 5881
assert len(m.detected) == 0 assert len(m.detected) == 0
def test_detection(self, indicator_file): def test_detection(self, indicator_file):
m = Manifest(base_folder=get_backup_folder(), log=logging) m = Manifest(base_folder=get_backup_folder(), log=logging, results=[])
ind = Indicators(log=logging) ind = Indicators(log=logging)
ind.parse_stix2(indicator_file) ind.parse_stix2(indicator_file)
# Adds a file that exists in the manifest # Adds a file that exists in the manifest
ind.ioc_files[0] = "com.apple.CoreBrightness.plist" ind.ioc_files[0] = "com.apple.CoreBrightness.plist"
m.indicators = ind m.indicators = ind
run_module(m) run_module(m)
assert len(m.detected) == 2 assert len(m.detected) == 1

View File

@ -7,7 +7,16 @@ from ..utils import get_backup_folder
class TestManifestModule: class TestManifestModule:
def test_manifest(self): def test_manifest(self):
m = TCC(base_folder=get_backup_folder(), log=logging) m = TCC(base_folder=get_backup_folder(), log=logging, results=[])
run_module(m)
assert len(m.results) == 11
assert len(m.timeline) == 11
assert len(m.detected) == 0
assert m.results[0]["service"] == "kTCCServiceUbiquity"
assert m.results[0]["auth_value"] == "allowed"
def test_manifest_2(self):
m = TCC(base_folder=get_backup_folder(), log=logging, results=[])
run_module(m) run_module(m)
assert len(m.results) == 11 assert len(m.results) == 11
assert len(m.timeline) == 11 assert len(m.timeline) == 11