summaryrefslogtreecommitdiff
path: root/tests/unit
AgeCommit message (Collapse)Author
2024-08-21Fix tineye engine url, datetime parsing, and minor refactorGrant Lanham
Changes made to tineye engine: 1. Importing logging if TYPE_CHECKING is enabled 2. Remove unecessary try-catch around json parsing the response, as this masked the original error and had no immediate benefit 3. Improve error handling explicitely for status code 422 and 400 upfront, deferring json_parsing only for these status codes and successful status codes 4. Unit test all new applicable changes to ensure compatability
2024-08-21[fix] unit tests: fix load / unload engines & fix messagesMarkus Heiser
- https://github.com/searxng/searxng/pull/3746#issuecomment-2300965005 - https://github.com/searxng/searxng/issues/2988#issuecomment-2226929084 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2024-07-14[mod] revision of the settings_loaderMarkus Heiser
The intention of this PR is to modernize the settings_loader implementations. The concept is old (remember, this is partly from 2014), back then we only had one config file, meanwhile we have had a folder with config files for a very long time. Callers can now load a YAML configuration from this folder as follows :: settings_loader.get_yaml_cfg('my-config.yml') - BTW this is a fix of #3557. - Further the `existing_filename_or_none` construct dates back to times when there was not yet a `pathlib.Path` in all Python versions we supported in the past. - Typehints have been added wherever appropriate At the same time, this patch should also be downward compatible and not introduce a new environment variable. The localization of the folder with the configurations is further based on: SEARXNG_SETTINGS_PATH (wich defaults to /etc/searxng/settings.yml) Which means, the default config folder is `/etc/searxng/`. ATTENTION: intended functional changes! If SEARXNG_SETTINGS_PATH was set and pointed to a not existing file, the previous implementation silently loaded the default configuration. This behavior has been changed: if the file or folder does not exist, an EnvironmentError exception will be thrown in future. Closes: https://github.com/searxng/searxng/issues/3557 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2024-07-13[fix] tear down TEST_ENGINES after TestBang is proceededMarkus Heiser
Engines are loaded into global name `searx.engines.engines` other applications such as statistics or the histogram use this global variable to search for values in their own memories, which can lead to key errors as described in - https://github.com/searxng/searxng/issues/2988 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de> Closes: https://github.com/searxng/searxng/issues/2988
2024-06-28[fix] unit test_xpath.py: name 'logger' is not definedMarkus Heiser
Depending on the order in which the unit tests are executed, the python modules of the engines are initialized (monkey patched) or not. As the order of the tests is not static, random errors may occur. To avaoid random `NameError: name 'logger' is not defined` in the unit tests of the xpath engine, a logger is monkey patched into the xpath py-module. ``` make test.unit TEST tests/unit ......EE................... ====================================================================== ERROR: test_response (tests.unit.engines.test_xpath.TestXpathEngine.test_response) ---------------------------------------------------------------------- Traceback (most recent call last): File "./tests/unit/engines/test_xpath.py", line 60, in test_response self.assertEqual(xpath.response(response), []) ^^^^^^^^^^^^^^^^^^^^^^^^ File "./searx/engines/xpath.py", line 309, in response logger.debug("found %s results", len(results)) ^^^^^^ NameError: name 'logger' is not defined ====================================================================== ERROR: test_response_results_xpath (tests.unit.engines.test_xpath.TestXpathEngine.test_response_results_xpath) ---------------------------------------------------------------------- Traceback (most recent call last): File "./tests/unit/engines/test_xpath.py", line 102, in test_response_results_xpath self.assertEqual(xpath.response(response), []) ^^^^^^^^^^^^^^^^^^^^^^^^ File "./searx/engines/xpath.py", line 309, in response logger.debug("found %s results", len(results)) ^^^^^^ NameError: name 'logger' is not defined ``` Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2024-06-23[fix] implement tests and remove usage of gen_useragent in enginesGrant Lanham
2024-06-23[fix] engine unit tests.Richard Lyons
Enables unit tests in the engines directory by adding __init__.py, and fixups for the enabled tests.
2024-03-11[mod] pylint all files with one profile / drop PYLINT_SEARXNG_DISABLE_OPTIONMarkus Heiser
In the past, some files were tested with the standard profile, others with a profile in which most of the messages were switched off ... some files were not checked at all. - ``PYLINT_SEARXNG_DISABLE_OPTION`` has been abolished - the distinction ``# lint: pylint`` is no longer necessary - the pylint tasks have been reduced from three to two 1. ./searx/engines -> lint engines with additional builtins 2. ./searx ./searxng_extra ./tests -> lint all other python files Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2024-03-09[black] upgrade black 22.12.0 --> 24.2.0Markus Heiser
The issue discussed in [1] has been solved since [2] has been merged into black / now we can upgrade without touching 69 files as it was needed with black 23.1.0 [3]. [1] https://github.com/searxng/searxng/pull/2159#issuecomment-1425723977 [2] https://github.com/psf/black/pull/4060 [3] https://github.com/searxng/searxng/pull/2159/files Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2024-01-31[mod] remove X-XSS-Protection headersMarkus Heiser
Deprecated header not used by browsers nowadays[1]: """In modern browsers, X-XSS-Protection has been deprecated in favor of the Content-Security-Policy to disable the use of inline JavaScript. Its use can introduce XSS vulnerabilities in otherwise safe websites. This should not be used unless you need to support older web browsers that don’t yet support CSP. It is thus recommended to set the header as X-XSS-Protection: 0."""[2] [1] https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection [2] https://infosec.mozilla.org/guidelines/web_security#x-xss-protection Closes: https://github.com/searxng/searxng/issues/3171 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2024-01-29[fix] do highlight replacement at onceallixx
Highlights all search queries in search result in one go. Fixes the case where search query contains word from highlight HTML code, which causes broken HTML to appear in search results. Closes #3057
2023-11-01[mod] isolation of botdetection from the limiterMarkus Heiser
This patch was inspired by the discussion around PR-2882 [2]. The goals of this patch are: 1. Convert plugin searx.plugin.limiter to normal code [1] 2. isolation of botdetection from the limiter [2] 3. searx/{tools => botdetection}/config.py and drop searx.tools 4. in URL /config, 'limiter.enabled' is true only if the limiter is really enabled (Redis is available). This patch moves all the code that belongs to botdetection into namespace searx.botdetection and code that belongs to limiter is placed in namespace searx.limiter. Tthe limiter used to be a plugin at some point botdetection was added, it was not a plugin. The modularization of these two components was long overdue. With the clear modularization, the documentation could then also be organized according to the architecture. [1] https://github.com/searxng/searxng/pull/2882 [2] https://github.com/searxng/searxng/pull/2882#issuecomment-1741716891 To test: - check the app works without the limiter, check `/config` - check the app works with the limiter and with the token, check `/config` - make docs.live .. and read - http://0.0.0.0:8000/admin/searx.limiter.html - http://0.0.0.0:8000/src/searx.botdetection.html#botdetection Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2023-10-22[fix] HTMLParser: undocumented not implemented methodMarkus Heiser
In python versions <py3.10 there is an issue with an undocumented method HTMLParser.error() [1][2] that was deprecated in Python 3.4 and removed in Python 3.5. To be compatible to higher versions (>=py3.10) an error method is implemented which throws an AssertionError exception like the higher Python versions do [3]. [1] https://github.com/python/cpython/issues/76025 [2] https://bugs.python.org/issue31844 [3] https://github.com/python/cpython/pull/8562 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2023-09-19[feat] implement feeling lucky featureBnyro
2023-09-18[fix] spellingjazzzooo
2023-08-09[fix] make flask_babel.gettext() work in engine modules (L10n & threads)Markus Heiser
incident: flask_babel.gettext() does not work in the engine modules. cause: the request() and response() functions of the engine modules run in the processor, whose search() method runs in a thread and in the threads the context of the Flask app does not exist. The context of the Flask app is needed by the gettext() function for the L10n. Solution: copy context of the Flask app into the threads. [1] special case: We cannot equip the search() method of the processors with the decorator [1], because the decorator requires a context (Flask app) that does not yet exist at the time of the initialization of the processors (the initialization of the processors is part of the initialization of the Flask app). [1] https://flask.palletsprojects.com/en/2.3.x/api/#flask.copy_current_request_context Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2023-06-19[mod] move some code from webapp module to webutils module (no functional ↵Markus Heiser
change) Over the years the webapp module became more and more a mess. To improve the modulaization a little this patch moves some implementations from the webapp module to webutils module. HINT: this patch brings non functional change Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2023-06-03Merge pull request #2357 / limiter -> botdetectionMarkus Heiser
The monolithic implementation of the limiter was divided into methods and implemented in the Python package searx.botdetection. Detailed documentation on the methods has been added. The methods are divided into two groups: 1. Probe HTTP headers - Method http_accept - Method http_accept_encoding - Method http_accept_language - Method http_connection - Method http_user_agent 2. Rate limit: - Method ip_limit - Method link_token (new) The (reduced) implementation of the limiter is now in the module searx.botdetection.limiter. The first group was transferred unchanged to this module. The ip_limit contains the sliding windows implemented by the limiter so far. This merge also fixes some long outstandig issue: - limiter does not evaluate the Accept-Language correct [1] - limiter needs a IPv6 prefix to block networks instead of IPs [2] Without additional configuration the limiter works as before (apart from the bugfixes). For the commissioning of additional methods (link_toke), a configuration must be made in an additional configuration file. Without this configuration, the limiter runs as before (zero configuration). The ip_limit Method implements the sliding windows of the vanilla limiter, additionally the link_token method can be used in this method. The link_token method can be used to investigate whether a request is suspicious. To activate the link_token method in the ip_limit method add the following to your /etc/searxng/limiter.toml:: [botdetection.ip_limit] link_token = true [1] https://github.com/searxng/searxng/issues/2455 [2] https://github.com/searxng/searxng/issues/2477
2023-06-02[mod] template preferences: split into elements (no functional change)Markus Heiser
HINT: this patch has no functional change / it is the preparation for following changes and bugfixes Over the years, the preferences template became an unmanageable beast. To make the source code more readable the monolith is splitted into elements. The splitting into elements also has the advantage that a new template can make use of them. The reversed checkbox is a quirk that is only used in the prefereces and must be eliminated in the long term. For this the macro 'checkbox_onoff_reversed' was added to the preferences.html template. The 'checkbox' macro is also a quirk of the preferences.html we don't want to use in other templates (it is an input-checkbox in a HTML form that was misused for status display). Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2023-06-01[fix] correct determination of the IP for the requestMarkus Heiser
For correct determination of the IP to the request the function botdetection.get_real_ip() is implemented. This fonction is used in the ip_limit and link_token method of the botdetection and it is used in the self_info plugin. A documentation about the X-Forwarded-For header has been added. [1] https://github.com/searxng/searxng/pull/2357#issuecomment-1566211059 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2023-03-24[mod] replace utils.match_language by locales.match_localeMarkus Heiser
This patch replaces the *full of magic* ``utils.match_language`` function by a ``locales.match_locale``. The ``locales.match_locale`` function is based on the ``locales.build_engine_locales`` introduced in 9ae409a0 [1]. In the past SearXNG did only support a search by a language but not in a region. This has been changed a long time ago and regions have been added to SearXNG core but not to the engines. The ``utils.match_language`` was the function to handle the different aspects of language/regions in SearXNG core and the supported *languages* in the engine. The ``utils.match_language`` did it with some magic and works good for most use cases but fails in some edge case. To replace the concurrence of languages and regions in the SearXNG core the ``locales.build_engine_locales`` was introduced in 9ae409a0 [1]. With the last patches all engines has been migrated to a ``fetch_traits`` and a language/region concept that is based on ``locales.build_engine_locales``. To summarize: there is no longer a need for the ``locales.match_language``. [1] https://github.com/searxng/searxng/pull/1652 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2023-02-17Add "Auto-detected" as a language.Alexandre Flament
When the user choose "Auto-detected", the choice remains on the following queries. The detected language is displayed. For example "Auto-detected (en)": * the next query language is going to be auto detected * for the current query, the detected language is English. This replace the autodetect_search_language plugin.
2023-01-17Merge pull request #2109 from ahmad-alkadri/fix/highlight-full-wordAlexandre Flament
Standalone words highlighting for query result in non-CJK characters
2023-01-15A little fix and modified the testing for content highlightahmad-alkadri
2023-01-15Add search.suspended_times settingsLéon Tiekötter
Make suspended_time changeable in settings.yml Allow different values to be set for different exceptions. Co-authored-by: Alexandre Flament <alex@al-f.net>
2022-12-16Replace langdetect with fasttextArtikusHG
2022-12-04Fix: don't crash when engine or name is missing in settings.ymlAlexandre Flament
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
2022-09-27[fix] typos / reported by @kianmeng in searx PR-3366Markus Heiser
[PR-3366] https://github.com/searx/searx/pull/3366 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2022-08-28Remove usage of SEARX environment variablesAlexandre FLAMENT
2022-08-11[fix] improve OpenSearch descriptionMarkus Heiser
Some HTTP-Clients do have issues with the ``opensearch.xml`` from SearXNG (related [1][2]) while other OpenSearch descriptions[3] (e.g. from qwant) work flawles. Inspired by the OpenSearch description from qwant and with informations from the specification[4] the ``opensearch.xml`` has been *improved*. - convert `<Url>` methods from lower case to upper case (`POST`|`GET`) - add `<moz:SearchForm>` and `xmlns:moz="http://www.mozilla.org/2006/browser/search/"` - add `<Query role="example" searchTerms="SearXNG" />` [4] OpenSearch description documents should include at least one Query element of `role="example"` that is expected to return search results. Search clients may use this example query to validate that the search engine is working properly. - modified `<LongName>` to SearXNG - modified `<Description>` the word 'hackable' scares uninitiated users and was removed - add the `type="image/png"` to `<Image>` Test can be done by:: make run Visit http://127.0.0.1:8888/ and add the search engine to your WEB-Browser / test with different WEB-Browser from desktop and Smartphones (are there any iOS user here, please test on Safari and Chrome). [1] https://app.element.io/#/room/#searxng:matrix.org/$xN_abdKhNqUlgXRBrb_9F3pqOxnSzGQ1TG0s0G9hQVw [2] https://github.com/searxng/searxng/issues/431 [3] https://developer.mozilla.org/en-US/docs/Web/OpenSearch [4] https://github.com/dewitt/opensearch/blob/master/opensearch-1-1-draft-6.md#the-query-element Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2022-07-08bing.py: resolve bing.com/ck/a redirectionsAlexandre Flament
add a new function searx.network.multi_requests to send multiple HTTP requests at once
2022-06-12[fix] move locale code from webapp.py to locales.py and fix #1303Markus Heiser
To improve modularization this patch: - moves *locale* related implementation from the webapp.py application to the locale.py module. - The initialization of the locales is now done in the application (webapp) and is no longer done while importing searx.locales. In the searx.locales module a new dictionary named `LOCALE_BEST_MATCH` has been added. In this dictionary we can map languages without a translation to languages we have a translation for. To fix #1303 zh-HK has been mapped to zh-Hant-TW (we do not need additional translations of traditional Chinese) Closes: https://github.com/searxng/searxng/issues/1303 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2022-05-07theme: remove __common__Alexandre Flament
2022-04-30[theme] peel out oscar from SearXNG developmentMarkus Heiser
This is the first step of removing oscar theme Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2022-04-16[fix] dailymotion engine: filter by language & countryMarkus Heiser
- fix the issue of fetching more the 7000 *languages* - improve the request function and filter by language & country - implement time_range_support & safesearch - add more fields to the response from dailymotion (allow_embed, length) - better clean up of HTML tags in the 'content' field. This is more or less a complete rework based on the '/videos' API from [1]. This patch cleans up the language list in SearXNG that has been polluted by the ISO-639-3 2 and 3 letter codes from dailymotion languages which have never been used. [1] https://developers.dailymotion.com/tools/ Closes: https://github.com/searxng/searxng/issues/1065 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2022-04-05[fix] add missing territory (country) nameMarkus Heiser
Related-to: https://github.com/searxng/searxng/pull/1029#issuecomment-1086824911 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2022-04-01[fix] issue when upgrading from werkzeug v2.0.3 to v2.1.0Markus Heiser
In v2.1.0 werkzeug [1] fixed an issue [2] to keep relative redirect locations by default [3]. Since relative locations are returned, we need to fix out test cases to avoid AssertionErrors like this one:: ====================================================================== FAIL: test_index_html_get (tests.unit.test_webapp.ViewsTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/runner/work/searxng/searxng/tests/unit/test_webapp.py", line 105, in test_index_html_get self.assertEqual(result.location, 'http://localhost/search?q=test') AssertionError: '/search?q=test' != 'http://localhost/search?q=test' - /search?q=test + http://localhost/search?q=test [1] https://werkzeug.palletsprojects.com/ [2] https://github.com/pallets/werkzeug/issues/2352 fixed in [3] https://github.com/pallets/werkzeug/pull/2354 Related-to: https://github.com/searxng/searxng/pull/1039#issuecomment-1085538288 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2022-03-19Merge pull request #894 from dalf/simple-aria-1Alexandre Flament
[enh] simple: basic ARIA fixes
2022-03-12[mod] replace /help by /info pages and include pages in project docsMarkus Heiser
This patch implements a bolierplate to share content from info-pages of the SearXNG instance (URL /info) with the project documentation (path /docs/user). The info pages are using Markdown (CommonMark), to include them in the project documentation (reST) the myst-parser [1] is used in the Sphinx-doc build chain. If base_url is known (defined in settings.yml) links to the instance are also inserted into the project documentation:: searxng_extra/docs_prebuild [1] https://www.sphinx-doc.org/en/master/usage/markdown.html Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2022-03-08[enh] simple: basic ARIA fixesAlexandre Flament
2022-03-05[mod] URL for the static file contains the sha1Alexandre Flament
* allow to cache the static file forever * avoid bugs when the static files are updated but not reloaded
2022-02-26[simple theme] replace Image_layout.js with flexbox CS impl.mrpaulblack
* drop image_layout.js from simple theme * move image_layout.js to oscar theme and delete common js dir (since its empty now) * align top position of image detail modal with bottom position of search header * use flexbox to display images; row height can be set via @results-image-row-height in defenitions.less * display span title underneath each image with a max width of 12rem * increase margin and padding around image article on desktop and tablet * make article height smaller on phone layout (height of 6rem) to display more content on current view * remove content from result, if the title and content matches * use a group that cotains the flex image article, if images are mixed with other categories * fix pylint issues in webapp.py * use the default.html result template in unit tests (thanks @return42)
2022-02-20[fix] changeover of the unit tests to the simple themeMarkus Heiser
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2022-02-05Merge pull request #848 from not-my-profile/help-routeAlexandre Flament
Introduce `/help` route
2022-02-04Merge pull request #839 from dalf/docs_searx_utilsMarkus Heiser
[mod] add documentation about searx.utils
2022-02-04preferences: Set autocomplete=off for formMartin Fischer
Otherwise you can change the value of a select, refresh the page and the preferences stay changed, leaving the wrong impression that they were saved.
2022-02-01[enh] introduce /help routeMartin Fischer
Translation will be implemented in the future. For now the "en" in /help/en/<pagename> is hardcoded.
2022-02-01[help] remove link from about.md titleMartin Fischer
Now that about.html extends page_with_header.html it already has a link to the start page and removing the link makes it easier to extract the page title from the Markdown for the following commit.
2022-01-29[mod] add documentation about searx.utilsAlexandre Flament
This module is a toolbox for the engines. Is should be documented. In addition, searx/utils.py is checked by pylint.
2022-01-17[typing] add results.TimingMartin Fischer