Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into mypy-hook
Browse files Browse the repository at this point in the history
  • Loading branch information
jstucke committed Sep 28, 2023
2 parents 4380f44 + 9f38a85 commit 0cb10ae
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 50 deletions.
4 changes: 2 additions & 2 deletions src/analysis/plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,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})

Expand All @@ -149,7 +149,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 isinstance(result, BaseModel) else None,
'result': result.model_dump() if isinstance(result, BaseModel) else None,
}

def get_tags(self, result: Schema, summary: list[str]) -> list[Tag]:
Expand Down
10 changes: 5 additions & 5 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ def load(path: Path | str | None = None):
When you only import the ``config`` module the ``load`` function will be looked up at runtime.
See `this blog entry <https://alexmarandon.com/articles/python_mock_gotchas/>`_ 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'

Expand All @@ -190,15 +190,15 @@ def load(path: 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

plugin_list = backend_dict.pop('plugin', [])
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

Expand Down
13 changes: 6 additions & 7 deletions src/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from typing import Type, Union, Iterator

import pytest
from pydantic import BaseModel, Field
from pydantic.utils import deep_update
from pydantic import BaseModel, ConfigDict, Field
from pydantic.v1.utils import deep_update

import config
from analysis.PluginBase import AnalysisBasePlugin
Expand Down Expand Up @@ -123,7 +123,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)
Expand All @@ -146,7 +146,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)
Expand Down Expand Up @@ -178,6 +178,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``).
Expand All @@ -187,9 +189,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
Expand Down
4 changes: 2 additions & 2 deletions src/install/requirements_backend.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cryptography==41.0.3
cryptography==41.0.4
docker==6.0.1
MarkupSafe==2.1.1
networkx==2.6.3
Expand All @@ -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

Expand Down
10 changes: 5 additions & 5 deletions src/install/requirements_frontend.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/manage_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from base64 import b64encode
from unittest import TestCase

from decorator import contextmanager
from flask import Flask
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/analysis/qemu_exec/test/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/compare/file_header/code/file_header.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import binascii

from flask import Markup
from markupsafe import Markup

from compare.PluginBase import CompareBasePlugin

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/compare/file_header/test/test_file_header.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flask import Markup
from markupsafe import Markup

from test.unit.compare.compare_plugin_test_class import ComparePluginTest

Expand Down
14 changes: 6 additions & 8 deletions src/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Iterator, List, NamedTuple, Type, TypeVar

import pytest
from pydantic import BaseModel, Extra
from pydantic import BaseModel, ConfigDict
from pathlib import Path

import config
Expand Down Expand Up @@ -65,7 +65,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)
Expand All @@ -82,6 +82,8 @@ class DatabaseInterfaces(NamedTuple):


class MockDataStorage(BaseModel):
model_config = ConfigDict(extra='allow')

postgres_server: str
postgres_port: int
postgres_database: str
Expand All @@ -104,21 +106,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):
Expand Down
2 changes: 1 addition & 1 deletion src/test/integration/web_interface/rest/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
6 changes: 3 additions & 3 deletions src/test/integration/web_interface/rest/test_rest_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,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[FileObject] = Queue()

def teardown(self):
def teardown_method(self):
self.test_queue.close()

def test_rest_download_valid(self, backend_config):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions src/test/unit/compare/compare_plugin_test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class ComparePluginTest:
PLUGIN_NAME = 'base'
PLUGIN_CLASS: Type[CompareBasePlugin] | None = None

def setup(self):
def setup_method(self):
self.compare_plugins = {}
self.c_plugin = self.setup_plugin()
self.setup_test_fw()

def teardown(self):
def teardown_method(self):
gc.collect()

def setup_plugin(self):
Expand Down
2 changes: 1 addition & 1 deletion src/test/unit/compare/test_plugin_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def compare_plugin():
)


@pytest.mark.backend_config(
@pytest.mark.backend_config_overwrite(
{
'ssdeep_ignore': 80,
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/unit/web_interface/test_plugin_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0cb10ae

Please sign in to comment.