1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-11-04 22:40:12 +01:00

add test case for _exodus_compile_signatures

This commit is contained in:
Michael Pöhn 2022-07-06 02:14:17 +02:00
parent 94c9f0bef9
commit a1677b5cb0
2 changed files with 27 additions and 3 deletions

View File

@ -144,7 +144,7 @@ def get_embedded_classes(apkfile, depth=0):
# taken from exodus_core
def _compile_signatures(signatures):
def _exodus_compile_signatures(signatures):
"""
Compiles the regex associated to each signature, in order to speed up the trackers detection.
@ -178,7 +178,7 @@ def load_trackers_signatures():
)
)
logging.debug('{} trackers signatures loaded'.format(len(signatures)))
return signatures, _compile_signatures(signatures)
return signatures, _exodus_compile_signatures(signatures)
def scan_binary(apkfile, extract_signatures=None):

View File

@ -338,6 +338,27 @@ class ScannerTest(unittest.TestCase):
self.assertEqual(0, count, 'there should be this many errors')
class Test__exodus_compile_signatures(unittest.TestCase):
def setUp(self):
self.m1 = mock.Mock()
self.m1.code_signature = r"^random\sregex$"
self.m2 = mock.Mock()
self.m2.code_signature = r"^another.+regex$"
self.mock_sigs = [self.m1, self.m2]
def test_ok(self):
result = fdroidserver.scanner._exodus_compile_signatures(self.mock_sigs)
self.assertListEqual(result, [
re.compile(self.m1.code_signature),
re.compile(self.m2.code_signature),
])
def test_not_iterable(self):
result = fdroidserver.scanner._exodus_compile_signatures(123)
self.assertListEqual(result, [])
if __name__ == "__main__":
os.chdir(os.path.dirname(__file__))
@ -352,5 +373,8 @@ if __name__ == "__main__":
(fdroidserver.common.options, args) = parser.parse_args(['--verbose'])
newSuite = unittest.TestSuite()
newSuite.addTest(unittest.makeSuite(ScannerTest))
newSuite.addTests([
unittest.makeSuite(ScannerTest),
unittest.makeSuite(Test__exodus_compile_signatures),
])
unittest.main(failfast=False)