|
1 | 1 | from pathlib import Path |
2 | | -from typing import List, Optional, Type |
| 2 | +from typing import Iterable, List, Optional, Type |
3 | 3 | from unittest import mock |
4 | 4 |
|
5 | 5 | import pytest |
|
10 | 10 | from unblob.extractors.command import MultiFileCommand |
11 | 11 | from unblob.handlers import BUILTIN_HANDLERS |
12 | 12 | from unblob.models import DirectoryHandler, Glob, Handler, HexString, MultiFile |
13 | | -from unblob.processing import DEFAULT_DEPTH, DEFAULT_PROCESS_NUM, ExtractionConfig |
| 13 | +from unblob.processing import ( |
| 14 | + DEFAULT_DEPTH, |
| 15 | + DEFAULT_PROCESS_NUM, |
| 16 | + DEFAULT_SKIP_MAGIC, |
| 17 | + ExtractionConfig, |
| 18 | +) |
14 | 19 | from unblob.ui import ( |
15 | 20 | NullProgressReporter, |
16 | 21 | ProgressReporter, |
@@ -367,3 +372,51 @@ def test_skip_extraction( |
367 | 372 | assert ( |
368 | 373 | process_file_mock.call_args.args[0].skip_extraction == skip_extraction |
369 | 374 | ), fail_message |
| 375 | + |
| 376 | + |
| 377 | +@pytest.mark.parametrize( |
| 378 | + "args, skip_magic, fail_message", |
| 379 | + [ |
| 380 | + ([], DEFAULT_SKIP_MAGIC, "Should have kept default skip magics"), |
| 381 | + ( |
| 382 | + ["--skip-magic", "SUPERMAGIC"], |
| 383 | + (*DEFAULT_SKIP_MAGIC, "SUPERMAGIC"), |
| 384 | + "Should have kept default skip magics", |
| 385 | + ), |
| 386 | + (["--clear-skip-magics"], [], "Should have cleared default skip magics"), |
| 387 | + ( |
| 388 | + ["--clear-skip-magics", "--skip-magic", "SUPERMAGIC"], |
| 389 | + ["SUPERMAGIC"], |
| 390 | + "Should have cleared default skip magics", |
| 391 | + ), |
| 392 | + ( |
| 393 | + ["--clear-skip-magics", "--skip-magic", DEFAULT_SKIP_MAGIC[1]], |
| 394 | + [DEFAULT_SKIP_MAGIC[1]], |
| 395 | + "Should allow user specified and remove the rest", |
| 396 | + ), |
| 397 | + ], |
| 398 | +) |
| 399 | +def test_clear_skip_magics( |
| 400 | + args: List[str], skip_magic: Iterable[str], fail_message: str, tmp_path: Path |
| 401 | +): |
| 402 | + runner = CliRunner() |
| 403 | + in_path = ( |
| 404 | + Path(__file__).parent |
| 405 | + / "integration" |
| 406 | + / "archive" |
| 407 | + / "zip" |
| 408 | + / "regular" |
| 409 | + / "__input__" |
| 410 | + / "apple.zip" |
| 411 | + ) |
| 412 | + params = [*args, "--extract-dir", str(tmp_path), str(in_path)] |
| 413 | + |
| 414 | + process_file_mock = mock.MagicMock() |
| 415 | + with mock.patch.object(unblob.cli, "process_file", process_file_mock): |
| 416 | + result = runner.invoke(unblob.cli.cli, params) |
| 417 | + |
| 418 | + assert result.exit_code == 0 |
| 419 | + process_file_mock.assert_called_once() |
| 420 | + assert sorted(process_file_mock.call_args.args[0].skip_magic) == sorted( |
| 421 | + skip_magic |
| 422 | + ), fail_message |
0 commit comments