Skip to content

Commit 4f71764

Browse files
authored
Merge pull request #389 from onekey-sec/internal-extract-root-must-be-absolute-path
internal API: ensure that ExtractConfig.extract_root is an absolute path
2 parents cd6ac2d + f0de272 commit 4f71764

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

tests/test_processing.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -154,19 +154,26 @@ def test_calculate_entropy_no_exception(path: Path, draw_plot: bool):
154154

155155

156156
@pytest.mark.parametrize(
157-
"extract_root, path, extract_dir_prefix",
157+
"extract_root, path, result",
158158
[
159-
("/extract", "firmware", "firmware"),
160-
("/extract", "relative/firmware", "firmware"),
161-
("/extract", "/extract/dir/firmware", "dir/firmware"),
162-
("/extract/dir", "/extract/dir/firmware", "firmware"),
163-
("/extract", "/some/place/else/firmware", "firmware"),
159+
("/extract", "firmware", "/extract/firmware_extract"),
160+
("/extract", "relative/firmware", "/extract/firmware_extract"),
161+
("/extract", "/extract/dir/firmware", "/extract/dir/firmware_extract"),
162+
(
163+
"/extract/dir",
164+
"/extract/dir/firmware",
165+
"/extract/dir/firmware_extract",
166+
),
167+
("/extract", "/some/place/else/firmware", "/extract/firmware_extract"),
168+
(
169+
"extract",
170+
"/some/place/else/firmware",
171+
str(Path(".").resolve() / "extract/firmware_extract"),
172+
),
164173
],
165174
)
166175
def test_ExtractionConfig_get_extract_dir_for(
167-
extract_root: str, path: str, extract_dir_prefix: str
176+
extract_root: str, path: str, result: str
168177
):
169178
cfg = ExtractionConfig(extract_root=Path(extract_root), entropy_depth=0)
170-
assert cfg.get_extract_dir_for(Path(path)) == (
171-
cfg.extract_root / Path(extract_dir_prefix + cfg.extract_suffix)
172-
)
179+
assert cfg.get_extract_dir_for(Path(path)) == Path(result)

unblob/processing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
@attr.define(kw_only=True)
5858
class ExtractionConfig:
59-
extract_root: Path
59+
extract_root: Path = attr.field(converter=lambda value: value.resolve())
6060
force_extract: bool = False
6161
entropy_depth: int
6262
entropy_plot: bool = False

0 commit comments

Comments
 (0)