mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-11-19 21:30:10 +01:00
add tests for scanner.load_exodus_trackers_signatures
This commit is contained in:
parent
544772d3ab
commit
07a366a4d6
@ -36,6 +36,7 @@ from . import _
|
|||||||
from . import common
|
from . import common
|
||||||
from . import metadata
|
from . import metadata
|
||||||
from .exception import BuildException, VCSException
|
from .exception import BuildException, VCSException
|
||||||
|
from . import scanner
|
||||||
|
|
||||||
config = None
|
config = None
|
||||||
options = None
|
options = None
|
||||||
@ -161,7 +162,7 @@ def _exodus_compile_signatures(signatures):
|
|||||||
|
|
||||||
|
|
||||||
# taken from exodus_core
|
# taken from exodus_core
|
||||||
def load_trackers_signatures():
|
def load_exodus_trackers_signatures():
|
||||||
"""
|
"""
|
||||||
Load trackers signatures from the official Exodus database.
|
Load trackers signatures from the official Exodus database.
|
||||||
|
|
||||||
@ -178,7 +179,7 @@ def load_trackers_signatures():
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
logging.debug('{} trackers signatures loaded'.format(len(signatures)))
|
logging.debug('{} trackers signatures loaded'.format(len(signatures)))
|
||||||
return signatures, _exodus_compile_signatures(signatures)
|
return signatures, scanner._exodus_compile_signatures(signatures)
|
||||||
|
|
||||||
|
|
||||||
def scan_binary(apkfile, extract_signatures=None):
|
def scan_binary(apkfile, extract_signatures=None):
|
||||||
@ -544,7 +545,7 @@ def main():
|
|||||||
|
|
||||||
exodus = []
|
exodus = []
|
||||||
if options.exodus:
|
if options.exodus:
|
||||||
exodus = load_trackers_signatures()
|
exodus = load_exodus_trackers_signatures()
|
||||||
|
|
||||||
appids = []
|
appids = []
|
||||||
for apk in options.appid:
|
for apk in options.appid:
|
||||||
|
@ -359,6 +359,53 @@ class Test__exodus_compile_signatures(unittest.TestCase):
|
|||||||
self.assertListEqual(result, [])
|
self.assertListEqual(result, [])
|
||||||
|
|
||||||
|
|
||||||
|
class Test_load_exodus_trackers_signatures(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.requests_ret = mock.Mock()
|
||||||
|
self.requests_ret.json = mock.Mock(return_value={
|
||||||
|
"trackers": {
|
||||||
|
"1": {
|
||||||
|
"id": 1,
|
||||||
|
"name": "Steyer Puch 1",
|
||||||
|
"description": "blah blah blah",
|
||||||
|
"creation_date": "1956-01-01",
|
||||||
|
"code_signature": "com.puch.|com.steyer.",
|
||||||
|
"network_signature": "pst\\.com",
|
||||||
|
"website": "https://pst.com",
|
||||||
|
"categories": ["tracker"],
|
||||||
|
"documentation": [],
|
||||||
|
},
|
||||||
|
"2": {
|
||||||
|
"id": 2,
|
||||||
|
"name": "Steyer Puch 2",
|
||||||
|
"description": "blah blah blah",
|
||||||
|
"creation_date": "1956-01-01",
|
||||||
|
"code_signature": "com.puch.|com.steyer.",
|
||||||
|
"network_signature": "pst\\.com",
|
||||||
|
"website": "https://pst.com",
|
||||||
|
"categories": ["tracker"],
|
||||||
|
"documentation": [],
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
self.requests_func = mock.Mock(return_value=self.requests_ret)
|
||||||
|
self.compilesig_func = mock.Mock(return_value=9999)
|
||||||
|
|
||||||
|
def test_ok(self):
|
||||||
|
with mock.patch("requests.get", self.requests_func), mock.patch(
|
||||||
|
"fdroidserver.scanner._exodus_compile_signatures", self.compilesig_func
|
||||||
|
):
|
||||||
|
result_sigs, result_regex = fdroidserver.scanner.load_exodus_trackers_signatures()
|
||||||
|
self.requests_func.assert_called_once_with("https://reports.exodus-privacy.eu.org/api/trackers")
|
||||||
|
self.assertEqual(len(result_sigs), 2)
|
||||||
|
self.assertEqual(result_sigs[0].id, 1)
|
||||||
|
self.assertEqual(result_sigs[1].id, 2)
|
||||||
|
|
||||||
|
self.compilesig_func.assert_called_once_with(result_sigs)
|
||||||
|
self.assertEqual(result_regex, 9999)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
os.chdir(os.path.dirname(__file__))
|
os.chdir(os.path.dirname(__file__))
|
||||||
|
|
||||||
@ -376,5 +423,6 @@ if __name__ == "__main__":
|
|||||||
newSuite.addTests([
|
newSuite.addTests([
|
||||||
unittest.makeSuite(ScannerTest),
|
unittest.makeSuite(ScannerTest),
|
||||||
unittest.makeSuite(Test__exodus_compile_signatures),
|
unittest.makeSuite(Test__exodus_compile_signatures),
|
||||||
|
unittest.makeSuite(Test_load_exodus_trackers_signatures),
|
||||||
])
|
])
|
||||||
unittest.main(failfast=False)
|
unittest.main(failfast=False)
|
||||||
|
Loading…
Reference in New Issue
Block a user