From 043492277e3d69e573f618df6ac4b9d8542b7429 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Sat, 21 Sep 2024 17:19:02 +0200 Subject: [PATCH] scanner: always use built-in ruleset when running tests The SUSS rule sets are changing all the time, but the test cases are not. So this makes the test cases just use the built-in ruleset so the test cases don't randomly break. --- fdroidserver/scanner.py | 6 +++++- tests/scanner.TestCase | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/fdroidserver/scanner.py b/fdroidserver/scanner.py index 94eddcc0..ee26fce4 100644 --- a/fdroidserver/scanner.py +++ b/fdroidserver/scanner.py @@ -354,6 +354,8 @@ class SUSSDataController(SignatureDataController): class ScannerTool: + refresh_allowed = True + def __init__(self): # we could add support for loading additional signature source # definitions from config.yml here @@ -362,7 +364,9 @@ class ScannerTool: options = common.get_options() options_refresh_scanner = ( - hasattr(options, "refresh_scanner") and options.refresh_scanner + hasattr(options, "refresh_scanner") + and options.refresh_scanner + and ScannerTool.refresh_allowed ) if options_refresh_scanner or common.get_config().get('refresh_scanner'): self.refresh() diff --git a/tests/scanner.TestCase b/tests/scanner.TestCase index 3127f023..9d0440c0 100755 --- a/tests/scanner.TestCase +++ b/tests/scanner.TestCase @@ -33,6 +33,11 @@ import fdroidserver.scanner from testcommon import TmpCwd, mkdtemp, mock_open_to_str, parse_args_for_test +# Always use built-in default rules so changes in downloaded rules don't break tests. +@mock.patch( + 'fdroidserver.scanner.SUSSDataController.load', + fdroidserver.scanner.SUSSDataController.load_from_defaults, +) class ScannerTest(unittest.TestCase): def setUp(self): logging.basicConfig(level=logging.INFO) @@ -40,6 +45,7 @@ class ScannerTest(unittest.TestCase): os.chdir(self.basedir) self._td = mkdtemp() self.testdir = self._td.name + fdroidserver.scanner.ScannerTool.refresh_allowed = False def tearDown(self): os.chdir(self.basedir) @@ -712,6 +718,7 @@ class Test_ScannerTool(unittest.TestCase): os.chdir(self.basedir) self._td = mkdtemp() self.testdir = self._td.name + fdroidserver.scanner.ScannerTool.refresh_allowed = True def tearDown(self): fdroidserver.common.options = None