-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: behavior with different suffix combinations
The test files were created with this script: # cd tests/files/suffixes # clean rm -rf chunks_carve/ extractions/ collisions.zip # reproduce output seq 100 | gzip > 0-160.gzip seq 128 | gzip > 160-375.gzip dd if=/dev/zero of=375-512.padding bs=1 count=137 cat 0-160.gzip 160-375.gzip 375-512.padding > chunks unblob --carve-suffix _carve chunks cp 0-160.gzip chunks_carve/ echo something else > chunks_carve/0-160.gzip_extract/gzip.uncompressed zip collisions.zip chunks chunks_carve/0-160.gzip chunks_carve/0-160.gzip_extract/gzip.uncompressed for input in collisions.zip chunks do unblob -e extractions/defaults/ $input unblob --carve-suffix _carve -e extractions/_carve_extract/ $input unblob --carve-suffix _c --extract-suffix _e -e extractions/_c_e/ $input done
- Loading branch information
1 parent
2767e86
commit 711e3d2
Showing
29 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
tests/integration/** filter=lfs diff=lfs merge=lfs -text | ||
tests/files/** filter=lfs diff=lfs merge=lfs -text |
Git LFS file not shown
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
tests/files/suffixes/extractions/_c_e/chunks_c/0-160.gzip_e/gzip.uncompressed
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
tests/files/suffixes/extractions/_c_e/chunks_c/160-375.gzip_e/gzip.uncompressed
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
tests/files/suffixes/extractions/_c_e/chunks_c/375-512.padding
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
tests/files/suffixes/extractions/_c_e/collisions.zip_e/chunks
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
.../files/suffixes/extractions/_c_e/collisions.zip_e/chunks_c/0-160.gzip_e/gzip.uncompressed
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
...iles/suffixes/extractions/_c_e/collisions.zip_e/chunks_c/160-375.gzip_e/gzip.uncompressed
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
tests/files/suffixes/extractions/_c_e/collisions.zip_e/chunks_c/375-512.padding
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
tests/files/suffixes/extractions/_c_e/collisions.zip_e/chunks_carve/0-160.gzip
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
...es/suffixes/extractions/_c_e/collisions.zip_e/chunks_carve/0-160.gzip_e/gzip.uncompressed
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
...fixes/extractions/_c_e/collisions.zip_e/chunks_carve/0-160.gzip_extract/gzip.uncompressed
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
...les/suffixes/extractions/_carve_extract/chunks_carve/0-160.gzip_extract/gzip.uncompressed
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
...s/suffixes/extractions/_carve_extract/chunks_carve/160-375.gzip_extract/gzip.uncompressed
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
tests/files/suffixes/extractions/_carve_extract/chunks_carve/375-512.padding
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
tests/files/suffixes/extractions/_carve_extract/collisions.zip_extract/chunks
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
.../files/suffixes/extractions/_carve_extract/collisions.zip_extract/chunks_carve/0-160.gzip
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
...s/_carve_extract/collisions.zip_extract/chunks_carve/0-160.gzip_extract/gzip.uncompressed
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
...s/files/suffixes/extractions/defaults/chunks_extract/0-160.gzip_extract/gzip.uncompressed
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
...files/suffixes/extractions/defaults/chunks_extract/160-375.gzip_extract/gzip.uncompressed
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
tests/files/suffixes/extractions/defaults/chunks_extract/375-512.padding
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
tests/files/suffixes/extractions/defaults/collisions.zip_extract/chunks
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
tests/files/suffixes/extractions/defaults/collisions.zip_extract/chunks_carve/0-160.gzip
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
...actions/defaults/collisions.zip_extract/chunks_carve/0-160.gzip_extract/gzip.uncompressed
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
...tions/defaults/collisions.zip_extract/chunks_extract/0-160.gzip_extract/gzip.uncompressed
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
...ons/defaults/collisions.zip_extract/chunks_extract/160-375.gzip_extract/gzip.uncompressed
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
...files/suffixes/extractions/defaults/collisions.zip_extract/chunks_extract/375-512.padding
Git LFS file not shown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
from pathlib import Path | ||
from typing import Optional | ||
|
||
import pytest | ||
|
||
from unblob.processing import ExtractionConfig, process_file | ||
from unblob.report import OutputDirectoryExistsReport | ||
from unblob.testing import check_output_is_the_same | ||
|
||
TEST_DATA_PATH = Path(__file__).parent / "files/suffixes" | ||
|
||
|
||
def _patch(extraction_config: ExtractionConfig, carve_suffix, extract_suffix): | ||
extraction_config.keep_extracted_chunks = False | ||
if carve_suffix is not None: | ||
extraction_config.carve_suffix = carve_suffix | ||
if extract_suffix is not None: | ||
extraction_config.extract_suffix = extract_suffix | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"carve_suffix,extract_suffix,expected_output_dir_name", | ||
[ | ||
(None, None, "defaults"), | ||
("_c", "_e", "_c_e"), | ||
("_carve", "_extract", "_carve_extract"), | ||
], | ||
) | ||
def test_top_level_carve( | ||
carve_suffix: Optional[str], | ||
extract_suffix: Optional[str], | ||
expected_output_dir_name: str, | ||
extraction_config: ExtractionConfig, | ||
): | ||
_patch(extraction_config, carve_suffix, extract_suffix) | ||
input_file = TEST_DATA_PATH / "chunks" | ||
carve_dir_name = input_file.name + extraction_config.carve_suffix | ||
extract_dir_name = input_file.name + extraction_config.extract_suffix | ||
expected_output_dir = ( | ||
TEST_DATA_PATH / "extractions" / expected_output_dir_name / carve_dir_name | ||
) | ||
|
||
reports = process_file(extraction_config, input_file) | ||
|
||
assert reports.errors == [] | ||
|
||
assert ( | ||
carve_dir_name == extract_dir_name | ||
or not (extraction_config.extract_root / extract_dir_name).exists() | ||
) | ||
check_output_is_the_same( | ||
expected_output_dir, extraction_config.extract_root / carve_dir_name | ||
) | ||
|
||
|
||
EXPECTED_COLLISION_PATHS: "dict[tuple[Optional[str], Optional[str]], set]" = { | ||
(None, None): { | ||
"collisions.zip_extract/chunks_carve/0-160.gzip_extract", | ||
}, | ||
("_carve", "_extract"): { | ||
"collisions.zip_extract/chunks_carve", | ||
"collisions.zip_extract/chunks_carve/0-160.gzip_extract", | ||
}, | ||
} | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"carve_suffix,extract_suffix,expected_output_dir_name", | ||
[ | ||
(None, None, "defaults"), | ||
("_c", "_e", "_c_e"), | ||
("_carve", "_extract", "_carve_extract"), | ||
], | ||
) | ||
def test_top_level_extract_and_collisions( | ||
carve_suffix: Optional[str], | ||
extract_suffix: Optional[str], | ||
expected_output_dir_name: str, | ||
extraction_config: ExtractionConfig, | ||
): | ||
_patch(extraction_config, carve_suffix, extract_suffix) | ||
input_file = TEST_DATA_PATH / "collisions.zip" | ||
carve_dir_name = input_file.name + extraction_config.carve_suffix | ||
extract_dir_name = input_file.name + extraction_config.extract_suffix | ||
expected_output_dir = ( | ||
TEST_DATA_PATH / "extractions" / expected_output_dir_name / extract_dir_name | ||
) | ||
|
||
reports = process_file(extraction_config, input_file) | ||
|
||
# check collision problems - the input was prepared to have collisions | ||
# during both the carving and extracting phases | ||
problem_paths = { | ||
e.path.relative_to(extraction_config.extract_root).as_posix() | ||
for e in reports.errors | ||
if isinstance(e, OutputDirectoryExistsReport) | ||
} | ||
key = (carve_suffix, extract_suffix) | ||
assert problem_paths == EXPECTED_COLLISION_PATHS.get(key, set()) | ||
# we expect only OutputDirectoryExistsReport-s | ||
assert len(reports.errors) == len(problem_paths) | ||
|
||
assert ( | ||
carve_dir_name == extract_dir_name | ||
or not (extraction_config.extract_root / carve_dir_name).exists() | ||
) | ||
check_output_is_the_same( | ||
expected_output_dir, extraction_config.extract_root / extract_dir_name | ||
) |