mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-11-04 22:40:29 +03:00
add test case for _exodus_compile_signatures
This commit is contained in:
parent
94c9f0bef9
commit
a1677b5cb0
2 changed files with 27 additions and 3 deletions
|
|
@ -144,7 +144,7 @@ def get_embedded_classes(apkfile, depth=0):
|
||||||
|
|
||||||
|
|
||||||
# taken from exodus_core
|
# 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.
|
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)))
|
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):
|
def scan_binary(apkfile, extract_signatures=None):
|
||||||
|
|
|
||||||
|
|
@ -338,6 +338,27 @@ class ScannerTest(unittest.TestCase):
|
||||||
self.assertEqual(0, count, 'there should be this many errors')
|
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__":
|
if __name__ == "__main__":
|
||||||
os.chdir(os.path.dirname(__file__))
|
os.chdir(os.path.dirname(__file__))
|
||||||
|
|
||||||
|
|
@ -352,5 +373,8 @@ if __name__ == "__main__":
|
||||||
(fdroidserver.common.options, args) = parser.parse_args(['--verbose'])
|
(fdroidserver.common.options, args) = parser.parse_args(['--verbose'])
|
||||||
|
|
||||||
newSuite = unittest.TestSuite()
|
newSuite = unittest.TestSuite()
|
||||||
newSuite.addTest(unittest.makeSuite(ScannerTest))
|
newSuite.addTests([
|
||||||
|
unittest.makeSuite(ScannerTest),
|
||||||
|
unittest.makeSuite(Test__exodus_compile_signatures),
|
||||||
|
])
|
||||||
unittest.main(failfast=False)
|
unittest.main(failfast=False)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue