Skip to content

Commit

Permalink
Adding task_depth param to test services that relies on it
Browse files Browse the repository at this point in the history
  • Loading branch information
gdesmar committed Sep 18, 2024
1 parent 8ca3e7c commit 330b119
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions assemblyline_service_utilities/testing/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,23 @@ def _create_service_task(self, file_path, params):
submission_params = params.get("submission_params", {})
tags = params.get("tags", [])
filename = params.get("filename", os.path.basename(file_path))
depth = params.get("task_depth", ServiceTask.fields()["depth"].default)

return ServiceTask(
{
"sid": get_random_id(),
"metadata": metadata,
"deep_scan": False,
"depth": depth,
"service_name": self.service_class.__name__,
"service_config": {
param.name: submission_params.get(param.name, param.default) for param in self.submission_params
},
"fileinfo": {
k: v
for k, v in self.identify.fileinfo(file_path, skip_fuzzy_hashes=True).items()
for k, v in self.identify.fileinfo(
file_path, skip_fuzzy_hashes=True, calculate_entropy=False
).items()
if k in fileinfo_keys
},
"filename": filename,
Expand Down Expand Up @@ -485,7 +489,10 @@ def _data_compare(ih: IssueHelper, original, new, data_type, ignore_new_extra_fi
ih.add_issue(
data_type,
ih.ACTION_CHANGED,
f"@{root} - Value of {data_type} with key '{k}' has changed from {truncate(v)} to {truncate(new[k])}.",
(
f"@{root} - Value of {data_type} with key '{k}' has changed "
f"from {truncate(v)} to {truncate(new[k])}."
),
)

# Only ignore new files in the "extra" data
Expand Down Expand Up @@ -574,12 +581,16 @@ def _file_compare(ih: IssueHelper, f_type, original, new):
ih.add_issue(f_type, record[0], message)

def regenerate_results(self, save_files=False, sample_sha256=""):
for f in self.result_list():
result_list = self.result_list()
for i, f in enumerate(result_list):
if sample_sha256 and f != sample_sha256:
print(f"{sample_sha256} requested. Skipping {f}...")
continue
try:
print(f"Executing {f}")
if not sample_sha256:
print(f"Executing {f} [{(i+1)*100//len(result_list)}%]")
else:
print(f"Executing {f}")
self._execute_sample(f, save=True, save_files=save_files)
except FileMissing:
print(f"[W] File {f} was not found in any of the following locations: {', '.join(self.locations)}")
Expand Down

0 comments on commit 330b119

Please sign in to comment.