diff options
author | Alexandre Flament <alex@al-f.net> | 2022-12-04 23:43:59 +0100 |
---|---|---|
committer | Alexandre Flament <alex@al-f.net> | 2022-12-04 23:43:59 +0100 |
commit | 269326063ac9113dacb222c3b1dd0516483e05b8 (patch) | |
tree | 87cefff16d201a821ac8e554e08ae930246969e0 /tests | |
parent | ffb72dfdf7c364fa85e6814b9952703d65b1c274 (diff) | |
download | searxng-269326063ac9113dacb222c3b1dd0516483e05b8.tar.gz searxng-269326063ac9113dacb222c3b1dd0516483e05b8.zip |
Fix: don't crash when engine or name is missing in settings.yml
SearXNG crashes if the engine or name fields are missing.
With this commit, the app displays an error in the log and keeps loading.
Close #1951
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/test_engines_init.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/unit/test_engines_init.py b/tests/unit/test_engines_init.py index c72f5c8e5..2844569d1 100644 --- a/tests/unit/test_engines_init.py +++ b/tests/unit/test_engines_init.py @@ -53,3 +53,25 @@ class TestEnginesInit(SearxTestCase): self.assertIn('onions', engines.categories) self.assertIn('http://engine1.onion', engines.engines['engine1'].search_url) self.assertEqual(engines.engines['engine1'].timeout, 120.0) + + def test_missing_name_field(self): + settings['outgoing']['using_tor_proxy'] = False + engine_list = [ + {'engine': 'dummy', 'shortcut': 'e1', 'categories': 'general'}, + ] + with self.assertLogs('searx.engines', level='ERROR') as cm: + engines.load_engines(engine_list) + self.assertEqual(len(engines.engines), 0) + self.assertEqual(cm.output, ['ERROR:searx.engines:An engine does not have a "name" field']) + + def test_missing_engine_field(self): + settings['outgoing']['using_tor_proxy'] = False + engine_list = [ + {'name': 'engine2', 'shortcut': 'e2', 'categories': 'onions'}, + ] + with self.assertLogs('searx.engines', level='ERROR') as cm: + engines.load_engines(engine_list) + self.assertEqual(len(engines.engines), 0) + self.assertEqual( + cm.output, ['ERROR:searx.engines:The "engine" field is missing for the engine named "engine2"'] + ) |