diff --git a/examples/config.yml b/examples/config.yml index 59453376..b094a032 100644 --- a/examples/config.yml +++ b/examples/config.yml @@ -373,3 +373,9 @@ # - suss # - exodus # - https://example.com/signatures.json + +# The scanner can use signature sources from the internet. These are +# cached locally. To force them to be refreshed from the network on +# every run, set this to true: +# +# refresh_scanner: true diff --git a/fdroidserver/scanner.py b/fdroidserver/scanner.py index d96f2f6c..478191c2 100644 --- a/fdroidserver/scanner.py +++ b/fdroidserver/scanner.py @@ -325,15 +325,15 @@ class SUSSDataController(SignatureDataController): self.set_data(json.loads(SUSS_DEFAULT)) -class ScannerTool(): +class ScannerTool: def __init__(self): - # we could add support for loading additional signature source # definitions from config.yml here self.scanner_data_lookup() - if options and options.refresh_scanner: + config = common.get_config() + if (options and options.refresh_scanner) or config.get('refresh_scanner'): self.refresh() self.load() diff --git a/tests/scanner.TestCase b/tests/scanner.TestCase index d9181506..aba95323 100755 --- a/tests/scanner.TestCase +++ b/tests/scanner.TestCase @@ -704,6 +704,20 @@ class Test_SignatureDataController(unittest.TestCase): class Test_ScannerTool(unittest.TestCase): + def setUp(self): + fdroidserver.common.options = None + fdroidserver.common.config = None + self.basedir = os.path.join(localmodule, 'tests') + os.chdir(self.basedir) + self._td = mkdtemp() + self.testdir = self._td.name + + def tearDown(self): + fdroidserver.common.options = None + fdroidserver.common.config = None + os.chdir(self.basedir) + self._td.cleanup() + def test_load(self): st = mock.Mock() st.sdcs = [mock.Mock(), mock.Mock()] @@ -711,7 +725,8 @@ class Test_ScannerTool(unittest.TestCase): st.sdcs[0].load.assert_called_once_with() st.sdcs[1].load.assert_called_once_with() - def test_refresh_default(self): + def test_refresh_no_options_or_config(self): + """This simulates what happens when running something like scan_source()""" with mock.patch('fdroidserver.scanner.ScannerTool.refresh') as refresh: fdroidserver.scanner.ScannerTool() refresh.assert_not_called() @@ -730,6 +745,22 @@ class Test_ScannerTool(unittest.TestCase): fdroidserver.scanner.ScannerTool() refresh.assert_not_called() + def test_refresh_from_config(self): + os.chdir(self.testdir) + pathlib.Path('config.yml').write_text('refresh_scanner: true') + with mock.patch('fdroidserver.scanner.ScannerTool.refresh') as refresh: + fdroidserver.scanner.ScannerTool() + refresh.assert_called_once() + + def test_refresh_options_overrides_config(self): + fdroidserver.scanner.options = mock.Mock() + fdroidserver.scanner.options.refresh_scanner = True + os.chdir(self.testdir) + pathlib.Path('config.yml').write_text('refresh_scanner: false') + with mock.patch('fdroidserver.scanner.ScannerTool.refresh') as refresh: + fdroidserver.scanner.ScannerTool() + refresh.assert_called_once() + class Test_main(unittest.TestCase): def setUp(self):