|
1 | 1 | import argparse
|
2 | 2 | import platform
|
3 | 3 | import sys
|
4 |
| -from io import BytesIO |
| 4 | +from io import BytesIO, StringIO |
5 | 5 | from pathlib import Path
|
6 | 6 | from unittest.mock import MagicMock
|
7 | 7 |
|
|
17 | 17 | build_pipe,
|
18 | 18 | build_pipe_stdout,
|
19 | 19 | )
|
| 20 | +from dissect.target.tools.shell import main as target_shell |
| 21 | +from tests._utils import absolute_path |
20 | 22 |
|
21 | 23 | GREP_MATCH = "test1 and test2"
|
22 | 24 | GREP_MISSING = "test2 alone"
|
@@ -247,3 +249,32 @@ def _map_function(path: Path) -> str:
|
247 | 249 | tree = "|".join(sorted(path_map))
|
248 | 250 |
|
249 | 251 | assert tree == expected
|
| 252 | + |
| 253 | + |
| 254 | +@pytest.mark.parametrize( |
| 255 | + "provided_input, expected_output", |
| 256 | + [ |
| 257 | + ("hello", "world.txt"), # Latin |
| 258 | + ("ħēļľŏ", "ŵőřŀđ.txt"), # Latin Extended-A |
| 259 | + ("مرحبًا", "عالم.txt"), # Arabic |
| 260 | + ("你好", "世界.txt"), # Chineese Simplified |
| 261 | + ("привет", "мир.txt"), # Cyrillic |
| 262 | + ("🕵🕵🕵", "👀👀👀.txt"), # Emoji |
| 263 | + ], |
| 264 | +) |
| 265 | +def test_target_cli_unicode_argparse( |
| 266 | + capsys: pytest.CaptureFixture, |
| 267 | + monkeypatch: pytest.MonkeyPatch, |
| 268 | + provided_input: str, |
| 269 | + expected_output: str, |
| 270 | +) -> None: |
| 271 | + with monkeypatch.context() as m: |
| 272 | + target_file = absolute_path("_data/tools/shell/unicode.tar") |
| 273 | + m.setattr("sys.argv", ["target-shell", target_file]) |
| 274 | + m.setattr("sys.stdin", StringIO(f"ls unicode/charsets/{provided_input}")) |
| 275 | + target_shell() |
| 276 | + out, err = capsys.readouterr() |
| 277 | + out = out.replace("unicode.tar />", "").strip() |
| 278 | + |
| 279 | + assert out == expected_output |
| 280 | + assert "unrecognized arguments" not in err |
0 commit comments