From d0cbdf143c2e24d74b7c0b23680d2ccf7fbce470 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Stucke?= Date: Wed, 30 Aug 2023 16:34:06 +0200 Subject: [PATCH 1/6] manage_users: default config name fix the default config in the `manage_users.py` script still used the old config file name as default value --- src/manage_users.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/manage_users.py b/src/manage_users.py index d72f21f42..230eade83 100755 --- a/src/manage_users.py +++ b/src/manage_users.py @@ -43,7 +43,9 @@ def setup_argparse(): parser = argparse.ArgumentParser() parser.add_argument('-v', '--version', action='version', version=f'FACT User Management (FACTUM) {__VERSION__}') - parser.add_argument('-C', '--config_file', help='set path to config File', default=f'{get_config_dir()}/main.cfg') + parser.add_argument( + '-C', '--config_file', help='set path to config File', default=f'{get_config_dir()}/fact-core-config.toml' + ) return parser.parse_args() From e6ac672a8282d3f7f0bde619266a630fbe321eac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Stucke?= Date: Mon, 28 Aug 2023 13:45:19 +0200 Subject: [PATCH 2/6] updated some dependencies --- src/install/requirements_backend.txt | 2 +- src/install/requirements_frontend.txt | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/install/requirements_backend.txt b/src/install/requirements_backend.txt index 7862eb6a9..927b04723 100644 --- a/src/install/requirements_backend.txt +++ b/src/install/requirements_backend.txt @@ -8,7 +8,7 @@ pyyaml==6.0.1 # FIXME This is only needed by the compare/file_header plugin # See Issue #832 -flask==2.3.2 +flask==2.3.3 git+https://github.com/fkie-cad/common_helper_yara.git diff --git a/src/install/requirements_frontend.txt b/src/install/requirements_frontend.txt index b97a498d5..9c61e2e88 100644 --- a/src/install/requirements_frontend.txt +++ b/src/install/requirements_frontend.txt @@ -1,12 +1,12 @@ bcrypt==4.0.1 -email-validator==1.3.0 +email-validator==1.3.1 flask-login==0.6.2 flask-paginate==2022.1.8 -flask-security-too==5.2.0 +flask-security-too==5.3.0 flask-wtf==1.1.1 -flask==2.3.2 +flask==2.3.3 flask_restx==1.1.0 -flask_sqlalchemy==3.0.2 +flask_sqlalchemy==3.0.5 itsdangerous==2.1.2 matplotlib==3.5.3 more_itertools==9.0.0 @@ -17,7 +17,7 @@ uwsgi==2.0.22 virtualenv # must be below dependent packages (flask, flask-login, flask-restx) -werkzeug==2.3.4 +werkzeug==2.3.7 # Used for username validation by flask-security bleach==5.0.1 From b19ae043c351ad348b24763bec8d9f11e10db237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Stucke?= Date: Mon, 28 Aug 2023 13:45:49 +0200 Subject: [PATCH 3/6] fixed various deprecation warnings --- src/analysis/plugin/plugin.py | 4 ++-- src/config.py | 10 +++++----- src/conftest.py | 12 ++++++------ .../test/test_file_system_metadata_routes.py | 7 +++---- .../compare/file_header/code/file_header.py | 2 +- .../compare/file_header/test/test_file_header.py | 2 +- src/test/conftest.py | 16 ++++++++-------- src/test/integration/web_interface/rest/base.py | 2 +- .../web_interface/rest/test_rest_binary.py | 6 +++--- .../web_interface/rest/test_rest_statistics.py | 4 ++-- .../unit/compare/compare_plugin_test_class.py | 4 ++-- src/test/unit/compare/test_plugin_base.py | 2 +- .../unit/web_interface/test_plugin_routes.py | 2 +- 13 files changed, 36 insertions(+), 37 deletions(-) diff --git a/src/analysis/plugin/plugin.py b/src/analysis/plugin/plugin.py index 27a5ff90d..3027aa3cd 100644 --- a/src/analysis/plugin/plugin.py +++ b/src/analysis/plugin/plugin.py @@ -134,7 +134,7 @@ def get_analysis(self, file_handle: io.FileIO, virtual_file_path: dict, analyses # Misses the root uid, which must be added by the scheduler tags_dict = {} for tag in tags: - tag_dict = tag.dict() + tag_dict = tag.model_dump() name = tag_dict.pop('name') tags_dict.update({name: tag_dict}) @@ -145,7 +145,7 @@ def get_analysis(self, file_handle: io.FileIO, virtual_file_path: dict, analyses 'system_version': self.metadata.system_version, 'summary': summary, 'tags': tags_dict, - 'result': result.dict() if result else None, + 'result': result.model_dump() if result else None, } def get_tags(self, result: Schema, summary: list[str]) -> list[Tag]: diff --git a/src/config.py b/src/config.py index 64241ce33..7b7b4edec 100644 --- a/src/config.py +++ b/src/config.py @@ -171,9 +171,9 @@ def load(path: str | None = None): When you only import the ``config`` module the ``load`` function will be looked up at runtime. See `this blog entry `_ for some more information. """ - Common.update_forward_refs() - Backend.update_forward_refs() - Frontend.update_forward_refs() + Common.model_rebuild() + Backend.model_rebuild() + Frontend.model_rebuild() if path is None: path = Path(__file__).parent / 'config/fact-core-config.toml' @@ -190,7 +190,7 @@ def load(path: str | None = None): preset_dict = {} for preset in preset_list: p = Common.AnalysisPreset(**preset) - preset_dict[p.name] = p.dict() + preset_dict[p.name] = p.model_dump() common_dict['analysis_preset'] = preset_dict @@ -198,7 +198,7 @@ def load(path: str | None = None): plugin_dict = {} for plugin in plugin_list: p = Backend.Plugin(**plugin) - plugin_dict[p.name] = p.dict() + plugin_dict[p.name] = p.model_dump() backend_dict['plugin'] = plugin_dict diff --git a/src/conftest.py b/src/conftest.py index ebccf97d4..e34e6e17f 100644 --- a/src/conftest.py +++ b/src/conftest.py @@ -9,7 +9,8 @@ import pytest from pydantic import BaseModel, Field -from pydantic.utils import deep_update +from pydantic.v1 import ConfigDict +from pydantic.v1.utils import deep_update import config from analysis.PluginBase import AnalysisBasePlugin @@ -123,7 +124,7 @@ def backend_config(request, common_config, _firmware_file_storage_directory) -> }, } - test_config.update(common_config.dict()) + test_config.update(common_config.model_dump()) test_config = deep_update(test_config, overwrite_config) return config.Backend(**test_config) @@ -146,7 +147,7 @@ def frontend_config(request, common_config) -> config.Frontend: }, } - test_config.update(common_config.dict()) + test_config.update(common_config.model_dump()) test_config = deep_update(test_config, overwrite_config) return config.Frontend(**test_config) @@ -178,6 +179,8 @@ def patch_config(monkeypatch, common_config, backend_config, frontend_config): class AnalysisPluginTestConfig(BaseModel): """A class configuring the :py:func:`analysis_plugin` fixture.""" + model_config = ConfigDict(arbitrary_types_allowed=True) + #: The class of the plugin to be tested. It will most probably be called ``AnalysisPlugin``. plugin_class: Union[Type[AnalysisBasePlugin], Type[AnalysisPluginV0]] = AnalysisBasePlugin #: Whether or not to start the workers (see ``AnalysisPlugin.start``). @@ -187,9 +190,6 @@ class AnalysisPluginTestConfig(BaseModel): #: Not supported for AnalysisPluginV0 init_kwargs: dict = Field(default_factory=dict) - class Config: - arbitrary_types_allowed = True - @pytest.fixture def analysis_plugin(request, patch_config): # noqa: ARG001 diff --git a/src/plugins/analysis/file_system_metadata/test/test_file_system_metadata_routes.py b/src/plugins/analysis/file_system_metadata/test/test_file_system_metadata_routes.py index 930560177..1b4622994 100644 --- a/src/plugins/analysis/file_system_metadata/test/test_file_system_metadata_routes.py +++ b/src/plugins/analysis/file_system_metadata/test/test_file_system_metadata_routes.py @@ -1,5 +1,4 @@ from base64 import b64encode -from unittest import TestCase from decorator import contextmanager from flask import Flask @@ -107,7 +106,7 @@ class DbMock: class TestFileSystemMetadataRoutes: - def setup(self): + def setup_method(self): app = Flask(__name__) app.config.from_object(__name__) app.config['TESTING'] = True @@ -121,8 +120,8 @@ def test_get_analysis_results_of_parent_fo(self): assert 'test_value' in rv.data.decode() -class TestFileSystemMetadataRoutesRest(TestCase): - def setUp(self): +class TestFileSystemMetadataRoutesRest: + def setup_method(self): app = Flask(__name__) app.config.from_object(__name__) app.config['TESTING'] = True diff --git a/src/plugins/compare/file_header/code/file_header.py b/src/plugins/compare/file_header/code/file_header.py index 7a2f82ef8..c3b880ff9 100644 --- a/src/plugins/compare/file_header/code/file_header.py +++ b/src/plugins/compare/file_header/code/file_header.py @@ -1,6 +1,6 @@ import binascii -from flask import Markup +from markupsafe import Markup from compare.PluginBase import CompareBasePlugin diff --git a/src/plugins/compare/file_header/test/test_file_header.py b/src/plugins/compare/file_header/test/test_file_header.py index 4a4036f87..afdd20cdb 100644 --- a/src/plugins/compare/file_header/test/test_file_header.py +++ b/src/plugins/compare/file_header/test/test_file_header.py @@ -1,4 +1,4 @@ -from flask import Markup +from markupsafe import Markup from test.unit.compare.compare_plugin_test_class import ComparePluginTest diff --git a/src/test/conftest.py b/src/test/conftest.py index caaabb342..16525a8f1 100644 --- a/src/test/conftest.py +++ b/src/test/conftest.py @@ -2,9 +2,11 @@ from typing import List, NamedTuple, Type, TypeVar import pytest -from pydantic import BaseModel, Extra +from pydantic import BaseModel from pathlib import Path +from pydantic.v1 import ConfigDict + import config from scheduler.analysis import AnalysisScheduler from scheduler.comparison_scheduler import ComparisonScheduler @@ -64,7 +66,7 @@ def merge_markers(request, name: str, dtype: Type[T]) -> T: if isinstance(argument, dict): marker_dict.update(argument) elif isinstance(argument, BaseModel): - marker_dict.update(argument.dict()) + marker_dict.update(argument.model_dump()) else: raise _err return dtype(**marker_dict) @@ -81,6 +83,8 @@ class DatabaseInterfaces(NamedTuple): class MockDataStorage(BaseModel): + model_config = ConfigDict(extra='allow') + postgres_server: str postgres_port: int postgres_database: str @@ -103,21 +107,17 @@ class MockDataStorage(BaseModel): redis_host: str redis_port: int - class Config: - extra = Extra.forbid - class ConfigCommonMock(BaseModel): """This class is a mock of :py:class:`config.Common` which only contains postgres and redis configuration. """ + model_config = ConfigDict(extra='forbid') + postgres: config.Common.Postgres redis: config.Common.Redis - class Config: - extra = Extra.forbid - class MockIntercom: def __init__(self): diff --git a/src/test/integration/web_interface/rest/base.py b/src/test/integration/web_interface/rest/base.py index 9d59496d5..b725dfd44 100644 --- a/src/test/integration/web_interface/rest/base.py +++ b/src/test/integration/web_interface/rest/base.py @@ -2,7 +2,7 @@ class RestTestBase: - def setup(self): + def setup_method(self): self.frontend = WebFrontEnd() self.frontend.app.config['TESTING'] = True self.test_client = self.frontend.app.test_client() diff --git a/src/test/integration/web_interface/rest/test_rest_binary.py b/src/test/integration/web_interface/rest/test_rest_binary.py index 0b6526735..08d0d4806 100644 --- a/src/test/integration/web_interface/rest/test_rest_binary.py +++ b/src/test/integration/web_interface/rest/test_rest_binary.py @@ -12,12 +12,12 @@ @pytest.mark.usefixtures('database_interfaces') class TestRestDownload(RestTestBase): - def setup(self): - super().setup() + def setup_method(self): + super().setup_method() self.db_interface = BackendDbInterface() self.test_queue = Queue() - def teardown(self): + def teardown_method(self): self.test_queue.close() def test_rest_download_valid(self, backend_config): diff --git a/src/test/integration/web_interface/rest/test_rest_statistics.py b/src/test/integration/web_interface/rest/test_rest_statistics.py index 3da575f6c..08a18502b 100644 --- a/src/test/integration/web_interface/rest/test_rest_statistics.py +++ b/src/test/integration/web_interface/rest/test_rest_statistics.py @@ -8,8 +8,8 @@ @pytest.mark.usefixtures('database_interfaces') class TestRestStatistics(RestTestBase): - def setup(self): - super().setup() + def setup_method(self): + super().setup_method() self.stats_updater = StatsUpdateDbInterface() self.stats_updater.update_statistic( 'file_type', diff --git a/src/test/unit/compare/compare_plugin_test_class.py b/src/test/unit/compare/compare_plugin_test_class.py index 0307906f9..9a242b91f 100644 --- a/src/test/unit/compare/compare_plugin_test_class.py +++ b/src/test/unit/compare/compare_plugin_test_class.py @@ -9,7 +9,7 @@ class ComparePluginTest: PLUGIN_NAME = 'base' PLUGIN_CLASS = None - def setup(self): + def setup_method(self): self.config = self.generate_config() self.config.add_section('expert-settings') self.config.set('expert-settings', 'ssdeep-ignore', '80') @@ -17,7 +17,7 @@ def setup(self): self.c_plugin = self.setup_plugin() self.setup_test_fw() - def teardown(self): + def teardown_method(self): gc.collect() def setup_plugin(self): diff --git a/src/test/unit/compare/test_plugin_base.py b/src/test/unit/compare/test_plugin_base.py index b1d42dceb..685e9af78 100644 --- a/src/test/unit/compare/test_plugin_base.py +++ b/src/test/unit/compare/test_plugin_base.py @@ -14,7 +14,7 @@ def compare_plugin(): return ComparePlugin(view_updater=CommonDatabaseMock()) -@pytest.mark.backend_config( +@pytest.mark.backend_config_overwrite( { 'ssdeep_ignore': 80, } diff --git a/src/test/unit/web_interface/test_plugin_routes.py b/src/test/unit/web_interface/test_plugin_routes.py index 911c29c82..696bb7c79 100644 --- a/src/test/unit/web_interface/test_plugin_routes.py +++ b/src/test/unit/web_interface/test_plugin_routes.py @@ -24,7 +24,7 @@ def __init__(self, app, db=None, intercom=None, api=None, status=None): # noqa: class TestPluginRoutes: - def setup(self): + def setup_method(self): self.app = Flask(__name__) self.app.config.from_object(__name__) self.api = Api(self.app) From cf30ca97a1230ef53aab938bf91ed651b8e6267f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Stucke?= Date: Mon, 28 Aug 2023 14:16:19 +0200 Subject: [PATCH 4/6] fixed deprecation warnings of qemu exec tests --- src/plugins/analysis/qemu_exec/test/test_routes.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/plugins/analysis/qemu_exec/test/test_routes.py b/src/plugins/analysis/qemu_exec/test/test_routes.py index ea0a1cde9..7fcae2f07 100644 --- a/src/plugins/analysis/qemu_exec/test/test_routes.py +++ b/src/plugins/analysis/qemu_exec/test/test_routes.py @@ -86,8 +86,8 @@ class DbMock: frontend = DbInterfaceMock() -class TestFileSystemMetadataRoutes: - def setup(self): +class TestQemuExecRoutes: + def setup_method(self): app = Flask(__name__) app.config.from_object(__name__) app.config['TESTING'] = True @@ -119,8 +119,8 @@ def test_error_inside(self): assert 'some error' in response -class TestFileSystemMetadataRoutesRest: - def setup(self): +class TestQemuExecRoutesRest: + def setup_method(self): app = Flask(__name__) app.config.from_object(__name__) app.config['TESTING'] = True From a31382a00173fa54df32dc73411833d38540cceb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Stucke?= Date: Mon, 11 Sep 2023 12:52:52 +0200 Subject: [PATCH 5/6] pydantic v2 import fix --- src/conftest.py | 3 +-- src/test/conftest.py | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/conftest.py b/src/conftest.py index e34e6e17f..6a2f9e293 100644 --- a/src/conftest.py +++ b/src/conftest.py @@ -8,8 +8,7 @@ from typing import Type, Union import pytest -from pydantic import BaseModel, Field -from pydantic.v1 import ConfigDict +from pydantic import BaseModel, ConfigDict, Field from pydantic.v1.utils import deep_update import config diff --git a/src/test/conftest.py b/src/test/conftest.py index 16525a8f1..d31f43afc 100644 --- a/src/test/conftest.py +++ b/src/test/conftest.py @@ -2,11 +2,9 @@ from typing import List, NamedTuple, Type, TypeVar import pytest -from pydantic import BaseModel +from pydantic import BaseModel, ConfigDict from pathlib import Path -from pydantic.v1 import ConfigDict - import config from scheduler.analysis import AnalysisScheduler from scheduler.comparison_scheduler import ComparisonScheduler From 9f38a85a46d18bab69f35c2a2b161d901130dc51 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 28 Sep 2023 14:49:04 +0200 Subject: [PATCH 6/6] build(deps): bump cryptography from 41.0.3 to 41.0.4 in /src/install (#1130) Bumps [cryptography](https://github.com/pyca/cryptography) from 41.0.3 to 41.0.4. - [Changelog](https://github.com/pyca/cryptography/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pyca/cryptography/compare/41.0.3...41.0.4) --- updated-dependencies: - dependency-name: cryptography dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- src/install/requirements_backend.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/install/requirements_backend.txt b/src/install/requirements_backend.txt index 927b04723..74dc04ab5 100644 --- a/src/install/requirements_backend.txt +++ b/src/install/requirements_backend.txt @@ -1,4 +1,4 @@ -cryptography==41.0.3 +cryptography==41.0.4 docker==6.0.1 MarkupSafe==2.1.1 networkx==2.6.3