Skip to content

Commit

Permalink
chore: Manually fix ruff issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jstucke authored and maringuu committed Mar 6, 2024
1 parent 630f102 commit 1085351
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/plugins/analysis/architecture_detection/internal/dt.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _get_compatible_entry(dts: str) -> str | None:
break

cpu = cpus[cpu_name]
if 'compatible' not in cpu.keys():
if 'compatible' not in cpu:
continue

compatible = cpu['compatible']
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/analysis/cve_lookup/code/cve_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def process_object(self, file_object: FileObject) -> FileObject:
cves = {'cve_results': {}}
connection = DbConnection(f'sqlite:///{DB_PATH}')
lookup = Lookup(file_object, connection)
for _key, value in file_object.processed_analysis['software_components']['result'].items():
for value in file_object.processed_analysis['software_components']['result'].values():
product = value['meta']['software_name']
version = value['meta']['version'][0]
if product and version:
Expand Down
7 changes: 6 additions & 1 deletion src/plugins/analysis/file_type/code/file_type.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import io
from __future__ import annotations

import typing
from typing import List

import pydantic
Expand All @@ -8,6 +10,9 @@
from analysis.plugin import AnalysisPluginV0
from analysis.plugin.compat import AnalysisBasePluginAdapterMixin

if typing.TYPE_CHECKING:
import io


class AnalysisPlugin(AnalysisPluginV0, AnalysisBasePluginAdapterMixin):
class Schema(pydantic.BaseModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def _add_protection_info(hardening_result: list[list[str]]) -> list[HardeningChe
for single_result in hardening_result:
config_key = single_result[0]
actual_value = _detach_actual_value_from_result(single_result)
protection_info = PROTECTS_AGAINST[config_key] if config_key in PROTECTS_AGAINST else []
protection_info = PROTECTS_AGAINST.get(config_key, [])
full_result.append(HardeningCheckResult(*single_result, actual_value, protection_info))
return full_result

Expand Down
7 changes: 3 additions & 4 deletions src/plugins/analysis/kernel_config/test/test_kernel_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import glob
from pathlib import Path
from subprocess import CompletedProcess

Expand Down Expand Up @@ -81,7 +80,7 @@ def test_extract_ko_success(self, analysis_plugin):
assert analysis_plugin.probably_kernel_config(result)

def test_process_objects_kernel_image(self, analysis_plugin):
for valid_image in glob.glob(str(TEST_DATA_DIR / 'synthetic/*.image')):
for valid_image in (TEST_DATA_DIR / 'synthetic').glob('*.image'):
test_file = FileObject(file_path=str(valid_image))
test_file.processed_analysis['file_type'] = {'result': {'mime': 'application/octet-stream'}}
test_file.processed_analysis['software_components'] = {'summary': ['Linux Kernel']}
Expand All @@ -91,7 +90,7 @@ def test_process_objects_kernel_image(self, analysis_plugin):
assert test_file.processed_analysis[analysis_plugin.NAME]['is_kernel_config']
assert len(test_file.processed_analysis[analysis_plugin.NAME]['kernel_config']) > 0

for bad_image in glob.glob(str(TEST_DATA_DIR / 'random_invalid/*.image')):
for bad_image in (TEST_DATA_DIR / 'random_invalid').glob('*.image'):
test_file = FileObject(file_path=str(bad_image))
test_file.processed_analysis['file_type'] = {'result': {'mime': 'application/octet-stream'}}
test_file.processed_analysis['software_components'] = {'summary': ['Linux Kernel']}
Expand Down Expand Up @@ -149,7 +148,7 @@ def test_try_extract_fail():


def test_try_extract_random_fail():
for fp in glob.glob(str(TEST_DATA_DIR / 'random_invalid/*.image')):
for fp in (TEST_DATA_DIR / 'random_invalid').glob('*.image'):
test_file = FileObject(file_path=fp)
test_file.processed_analysis['file_type'] = {'result': {'mime': 'application/octet-stream'}}
test_file.processed_analysis['software_components'] = {'summary': ['Linux Kernel']}
Expand Down
8 changes: 6 additions & 2 deletions src/scheduler/analysis/plugin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import ctypes
import io
import logging
Expand All @@ -14,11 +16,13 @@
from pydantic import BaseModel, ConfigDict

import config
from analysis.plugin import AnalysisPluginV0
from objects.file import FileObject
from objects.file import FileObject # noqa: TCH001 # needed by pydantic
from statistic.analysis_stats import ANALYSIS_STATS_LIMIT
from storage.fsorganizer import FSOrganizer

if typing.TYPE_CHECKING:
from analysis.plugin import AnalysisPluginV0


class PluginRunner:
class Config(BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion src/scheduler/analysis/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ def check_exceptions(self) -> bool:
:return: Boolean value stating if any attached process ran into an exception
"""
for _, plugin in self.analysis_plugins.items():
for plugin in self.analysis_plugins.values():
if isinstance(plugin, AnalysisPluginV0):
continue
if plugin.check_exceptions():
Expand Down
4 changes: 3 additions & 1 deletion src/start_fact_frontend.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /usr/bin/env python3
"""
Firmware Analysis and Comparison Tool (FACT)
Copyright (C) 2015-2024 Fraunhofer FKIE
Copyright (C) 2015-2023 Fraunhofer FKIE
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -17,6 +17,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""

from __future__ import annotations

import logging
import pickle
import signal
Expand Down
6 changes: 4 additions & 2 deletions src/test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from multiprocessing import Event, Queue, Value
from pathlib import Path
from typing import List, NamedTuple, Type, TypeVar
Expand Down Expand Up @@ -290,7 +292,7 @@ def _unpacking_lock_manager() -> UnpackingLockManager: # noqa: PT005


@pytest.fixture(name='test_config')
def _scheduler_test_config(request) -> 'SchedulerTestConfig': # noqa: PT005
def _scheduler_test_config(request) -> SchedulerTestConfig: # noqa: PT005
return SchedulerTestConfig.get_instance_from_request(request)


Expand Down Expand Up @@ -566,7 +568,7 @@ def Acceptance(**kwargs): # noqa: N802
)

@staticmethod
def get_instance_from_request(request: pytest.FixtureRequest) -> 'SchedulerTestConfig':
def get_instance_from_request(request: pytest.FixtureRequest) -> SchedulerTestConfig:
err = ValueError(f'{request.module} is neither a unit, acceptance nor integration test')

test_config_dict = merge_markers(request, 'SchedulerTestConfig', dict)
Expand Down
2 changes: 2 additions & 0 deletions src/test/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from typing import Type

import pytest
Expand Down
4 changes: 2 additions & 2 deletions src/test/unit/web_interface/rest/test_rest_firmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class DbMock(CommonDatabaseMock):
def rest_get_firmware_uids(
limit: int = 10,
offset: int = 0,
query=None,
recursive=False,
query=None, # noqa: ARG004
recursive=False, # noqa: ARG004
inverted=False, # noqa: ARG004
):
return [f'uid{i}' for i in range(offset, limit or 10)]
Expand Down

0 comments on commit 1085351

Please sign in to comment.