mirror of
https://github.com/suitenumerique/django-lasuite
synced 2026-04-25 17:15:14 +02:00
♻️(malware) reuse existing file_hash when rescheduling a task
When a task is rescheduled, the file_hash saved in the table is not reused leading to redownloading the file to compute its hash. This download can be avoided if the file_hash is correctly reused.
This commit is contained in:
@@ -11,6 +11,7 @@ and this project adheres to
|
||||
### Changed
|
||||
|
||||
- ⬆️(oidc) allow use mozilla-django-oidc >5.0.0 with PyJWT
|
||||
- ♻️(malware) reuse existing file_hash when rescheduling a task
|
||||
|
||||
## [0.0.22] - 2025-12-04
|
||||
|
||||
|
||||
@@ -80,7 +80,8 @@ class JCOPBackend(BaseBackend):
|
||||
return
|
||||
|
||||
analyse_file_async.delay(
|
||||
malware_detection_record.path,
|
||||
file_path=malware_detection_record.path,
|
||||
file_hash=malware_detection_record.file_hash,
|
||||
**malware_detection_record.parameters,
|
||||
)
|
||||
|
||||
@@ -165,7 +166,7 @@ class JCOPBackend(BaseBackend):
|
||||
|
||||
def check_analysis(self, file_path: str, file_hash: str | None = None, **kwargs) -> bool:
|
||||
"""Start the analysis process for a file."""
|
||||
if file_hash is None:
|
||||
if not file_hash:
|
||||
with default_storage.open(file_path, "rb") as file:
|
||||
file_hash = hashlib.file_digest(file, "sha256").hexdigest()
|
||||
self._update_detection_file_hash(file_path, file_hash)
|
||||
|
||||
@@ -909,7 +909,26 @@ def test_jcop_backend_reschedule_processing_task(jcop_generate_file_path, jcop_b
|
||||
with mock.patch.object(analyse_file_async, "delay") as analyse_file_async_mock:
|
||||
jcop_backend.reschedule_processing_task(malware_detection)
|
||||
analyse_file_async_mock.assert_called_once_with(
|
||||
file_path,
|
||||
file_path=file_path,
|
||||
file_hash="",
|
||||
)
|
||||
|
||||
|
||||
def test_jcop_backend_reschedule_processing_task_with_file_hash(jcop_generate_file_path, jcop_backend):
|
||||
"""Reschedule the processing task for a malware detection record."""
|
||||
file_path, file_hash = jcop_generate_file_path
|
||||
malware_detection = factories.MalwareDetectionFactory(
|
||||
path=file_path,
|
||||
file_hash=file_hash,
|
||||
status=MalwareDetectionStatus.PROCESSING,
|
||||
backend="lasuite.malware_detection.backends.jcop.JCOPBackend",
|
||||
)
|
||||
|
||||
with mock.patch.object(analyse_file_async, "delay") as analyse_file_async_mock:
|
||||
jcop_backend.reschedule_processing_task(malware_detection)
|
||||
analyse_file_async_mock.assert_called_once_with(
|
||||
file_path=file_path,
|
||||
file_hash=file_hash,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user