시험 도구 경로와 창 탐색 보호 수정
- 작성자
- 코노모리 카논
- 작성 시각
- 커밋
7f37d2ac64b64333aa2eea2a15ccf2c741bf8b68- 부모
- 07e5d2b
변경된 파일 5개
+133-14| @@ -98,10 +98,13 @@ def command(manifest, phase): | ||
| 98 | 98 | |
| 99 | 99 | def prepare_fixtures(root): |
| 100 | 100 | skipped = {} |
| 101 | 추가: work = test_work_directory(root) | |
| 102 | 추가: if work.resolve() != work: | |
| 103 | 추가: raise ValueError(f"안전한 작업 디렉터리가 필요함: {work}") | |
| 104 | 추가: work.mkdir(mode=0o700, parents=True, exist_ok=True) | |
| 105 | 추가: fixtures = output_directory(work, "fixtures", create=True) | |
| 101 | 106 | for name in sorted(FILE_FIXTURES): |
| 102 | 삭제: path = test_work_directory(root) / "fixtures" / name | |
| 103 | 삭제: if not path.exists() and not path.is_symlink(): | |
| 104 | 삭제: path.mkdir(mode=0o700, parents=True) | |
| 107 | 추가: path = output_directory(fixtures, name, create=True) | |
| 105 | 108 | info = path.lstat() |
| 106 | 109 | if ( |
| 107 | 110 | not stat.S_ISDIR(info.st_mode) |
| @@ -10,8 +10,24 @@ if [[ ! "$job" =~ ^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$ ]]; then | ||
| 10 | 10 | exit 2 |
| 11 | 11 | fi |
| 12 | 12 | ci_tools="${ZIPELO_CI_TOOLS:-$project_root/tests/work/$job/tools}" |
| 13 | 추가: ci_tools="$(python3 - "$project_root" "$job" "$ci_tools" <<'PYTHON' | |
| 14 | 추가: import os | |
| 15 | 추가: from pathlib import Path | |
| 16 | 추가: import sys | |
| 17 | 추가: | |
| 18 | 추가: project = Path(sys.argv[1]).resolve() | |
| 19 | 추가: allowed = project / "tests/work" / sys.argv[2] | |
| 20 | 추가: tools = Path(os.path.abspath(sys.argv[3])) | |
| 21 | 추가: for path in (project / "tests", project / "tests/work", allowed, tools, | |
| 22 | 추가: tools / "downloads", tools / "mingw"): | |
| 23 | 추가: if path.resolve() != path: | |
| 24 | 추가: raise SystemExit(f"작업 폴더 밖의 경로는 허용하지 않음: {path}") | |
| 25 | 추가: if not tools.is_relative_to(allowed): | |
| 26 | 추가: raise SystemExit(f"작업 폴더 밖의 경로는 허용하지 않음: {tools}") | |
| 27 | 추가: print(tools) | |
| 28 | 추가: PYTHON | |
| 29 | 추가: )" | |
| 13 | 30 | mkdir -p "$ci_tools/downloads" "$ci_tools/mingw" |
| 14 | 삭제: ci_tools="$(cd "$ci_tools" && pwd)" | |
| 15 | 31 | |
| 16 | 32 | # 도구를 프로젝트 안에 풀며 시스템 패키지는 설치하지 않음. |
| 17 | 33 | ( |
| @@ -47,6 +47,52 @@ class RunnerTests(unittest.TestCase): | ||
| 47 | 47 | self.assertFalse((outside / "task").exists()) |
| 48 | 48 | self.assertFalse((outside / "work").exists()) |
| 49 | 49 | |
| 50 | 추가: def test_fixture_parent_symlink_is_rejected_before_creating_children(self): | |
| 51 | 추가: with tempfile.TemporaryDirectory(dir=TEST_WORK) as directory: | |
| 52 | 추가: base = Path(directory) | |
| 53 | 추가: work = base / "work" | |
| 54 | 추가: work.mkdir() | |
| 55 | 추가: outside = base / "outside" | |
| 56 | 추가: outside.mkdir() | |
| 57 | 추가: (work / "fixtures").symlink_to(outside, target_is_directory=True) | |
| 58 | 추가: with ( | |
| 59 | 추가: patch.object(run_rust, "test_work_directory", return_value=work), | |
| 60 | 추가: self.assertRaisesRegex(ValueError, "작업 폴더 밖"), | |
| 61 | 추가: ): | |
| 62 | 추가: run_rust.prepare_fixtures(run_rust.ROOT) | |
| 63 | 추가: self.assertEqual(list(outside.iterdir()), []) | |
| 64 | 추가: | |
| 65 | 추가: def test_windows_setup_rejects_symlinked_parent_before_creating_tools(self): | |
| 66 | 추가: with tempfile.TemporaryDirectory(dir=TEST_WORK) as directory: | |
| 67 | 추가: base = Path(directory) | |
| 68 | 추가: project = base / "project" | |
| 69 | 추가: ci = project / "tests/ci" | |
| 70 | 추가: ci.mkdir(parents=True) | |
| 71 | 추가: work = project / "tests/work/task" | |
| 72 | 추가: work.mkdir(parents=True) | |
| 73 | 추가: script = ci / "setup_windows.sh" | |
| 74 | 추가: script.write_bytes((run_rust.ROOT / "tests/ci/setup_windows.sh").read_bytes()) | |
| 75 | 추가: commands = base / "bin" | |
| 76 | 추가: commands.mkdir() | |
| 77 | 추가: git = commands / "git" | |
| 78 | 추가: git.write_text('#!/bin/sh\nprintf "%s\n" "$FAKE_GIT_COMMON"\n') | |
| 79 | 추가: git.chmod(0o700) | |
| 80 | 추가: outside = base / "outside" | |
| 81 | 추가: outside.mkdir() | |
| 82 | 추가: (work / "linked").symlink_to(outside, target_is_directory=True) | |
| 83 | 추가: environment = { | |
| 84 | 추가: **os.environ, | |
| 85 | 추가: "PATH": str(commands) + os.pathsep + os.environ["PATH"], | |
| 86 | 추가: "FAKE_GIT_COMMON": str(project / ".git"), | |
| 87 | 추가: "ZIPELO_CI_JOB": "task", | |
| 88 | 추가: "ZIPELO_CI_TOOLS": str(work / "linked/tools"), | |
| 89 | 추가: } | |
| 90 | 추가: result = subprocess.run(["bash", str(script)], env=environment, | |
| 91 | 추가: capture_output=True, text=True) | |
| 92 | 추가: self.assertNotEqual(result.returncode, 0) | |
| 93 | 추가: self.assertIn("작업 폴더 밖", result.stderr) | |
| 94 | 추가: self.assertEqual(list(outside.iterdir()), []) | |
| 95 | 추가: | |
| 50 | 96 | def test_output_paths_reject_symlinks_outside_job(self): |
| 51 | 97 | with tempfile.TemporaryDirectory(dir=TEST_WORK) as directory: |
| 52 | 98 | work = Path(directory) |
| @@ -98,6 +98,48 @@ with patch.object(module.subprocess, "run", return_value=subprocess.CompletedPro | ||
| 98 | 98 | self.assertEqual(result.returncode, 0, result.stderr) |
| 99 | 99 | self.assertEqual(result.stdout.strip(), "blocked") |
| 100 | 100 | |
| 101 | 추가: def test_window_guards_stay_active_with_python_optimization(self): | |
| 102 | 추가: script = """import importlib.util | |
| 103 | 추가: import subprocess | |
| 104 | 추가: import sys | |
| 105 | 추가: from unittest.mock import Mock, patch | |
| 106 | 추가: | |
| 107 | 추가: spec = importlib.util.spec_from_file_location("ubuntu_smoke", sys.argv[1]) | |
| 108 | 추가: module = importlib.util.module_from_spec(spec) | |
| 109 | 추가: spec.loader.exec_module(module) | |
| 110 | 추가: app = Mock(pid=123) | |
| 111 | 추가: app.poll.return_value = 1 | |
| 112 | 추가: with patch.object(module.subprocess, "run") as search: | |
| 113 | 추가: try: | |
| 114 | 추가: module.wait_for_window(app, {}, timeout=0.5) | |
| 115 | 추가: except RuntimeError as error: | |
| 116 | 추가: if "조기에 종료" not in str(error): | |
| 117 | 추가: raise | |
| 118 | 추가: else: | |
| 119 | 추가: raise SystemExit("종료된 앱을 통과시킴") | |
| 120 | 추가: search.assert_not_called() | |
| 121 | 추가: app.poll.return_value = None | |
| 122 | 추가: with patch.object(module.subprocess, "run", return_value=subprocess.CompletedProcess([], 1)): | |
| 123 | 추가: with patch.object(module.time, "monotonic", side_effect=[0, 1]): | |
| 124 | 추가: with patch.object(module.time, "sleep") as sleep: | |
| 125 | 추가: try: | |
| 126 | 추가: module.wait_for_window(app, {}, timeout=0.5) | |
| 127 | 추가: except RuntimeError as error: | |
| 128 | 추가: if "시간 초과" not in str(error): | |
| 129 | 추가: raise | |
| 130 | 추가: else: | |
| 131 | 추가: raise SystemExit("창 탐색 제한 시간을 통과시킴") | |
| 132 | 추가: sleep.assert_not_called() | |
| 133 | 추가: print("guards active") | |
| 134 | 추가: """ | |
| 135 | 추가: result = subprocess.run( | |
| 136 | 추가: [sys.executable, "-B", "-O", "-c", script, str(SMOKE.ROOT / "tests/release-packages/ubuntu_smoke.py")], | |
| 137 | 추가: env=dict(os.environ, PYTHONDONTWRITEBYTECODE="1"), cwd=ROOT, | |
| 138 | 추가: capture_output=True, text=True, timeout=10, | |
| 139 | 추가: ) | |
| 140 | 추가: self.assertEqual(result.returncode, 0, result.stderr) | |
| 141 | 추가: self.assertEqual(result.stdout.strip(), "guards active") | |
| 142 | 추가: | |
| 101 | 143 | def test_existing_installation_files_are_blocked(self): |
| 102 | 144 | with ( |
| 103 | 145 | patch.object(SMOKE.subprocess, "run", return_value=subprocess.CompletedProcess([], 1, b"")), |
| @@ -109,6 +109,26 @@ def installed_package(package, home): | ||
| 109 | 109 | raise BaseExceptionGroup("패키지 시험 또는 정리 실패", failures) |
| 110 | 110 | |
| 111 | 111 | |
| 112 | 추가: def ensure_app_running(app): | |
| 113 | 추가: if app.poll() is not None: | |
| 114 | 추가: raise RuntimeError("설치된 앱이 조기에 종료됨") | |
| 115 | 추가: | |
| 116 | 추가: | |
| 117 | 추가: def wait_for_window(app, env, timeout=30): | |
| 118 | 추가: deadline = time.monotonic() + timeout | |
| 119 | 추가: while True: | |
| 120 | 추가: ensure_app_running(app) | |
| 121 | 추가: window = subprocess.run( | |
| 122 | 추가: ["xdotool", "search", "--all", "--pid", str(app.pid), "--name", "Zipelo"], | |
| 123 | 추가: env=env, capture_output=True, text=True, | |
| 124 | 추가: ) | |
| 125 | 추가: if window.returncode == 0: | |
| 126 | 추가: return window | |
| 127 | 추가: if time.monotonic() >= deadline: | |
| 128 | 추가: raise RuntimeError("앱 창 표시 시간 초과") | |
| 129 | 추가: time.sleep(0.2) | |
| 130 | 추가: | |
| 131 | 추가: | |
| 112 | 132 | def main(): |
| 113 | 133 | parser = argparse.ArgumentParser(description=__doc__) |
| 114 | 134 | parser.add_argument("package", type=Path) |
| @@ -147,17 +167,9 @@ def main(): | ||
| 147 | 167 | env.pop("WAYLAND_DISPLAY", None) |
| 148 | 168 | with (runs / "app.stdout").open("wb") as stdout, (runs / "app.stderr").open("wb") as stderr: |
| 149 | 169 | app = subprocess.Popen(["/usr/bin/zipelo", str(archive)], env=env, stdout=stdout, stderr=stderr) |
| 150 | 삭제: deadline = time.monotonic() + 30 | |
| 151 | 삭제: while True: | |
| 152 | 삭제: assert app.poll() is None, "설치된 앱이 조기에 종료됨" | |
| 153 | 삭제: window = subprocess.run(["xdotool", "search", "--all", "--pid", str(app.pid), "--name", "Zipelo"], | |
| 154 | 삭제: env=env, capture_output=True, text=True) | |
| 155 | 삭제: if window.returncode == 0: | |
| 156 | 삭제: break | |
| 157 | 삭제: assert time.monotonic() < deadline, "앱 창 표시 시간 초과" | |
| 158 | 삭제: time.sleep(0.2) | |
| 170 | 추가: window = wait_for_window(app, env) | |
| 159 | 171 | time.sleep(3) |
| 160 | 삭제: assert app.poll() is None | |
| 172 | 추가: ensure_app_running(app) | |
| 161 | 173 | subprocess.run(["import", "-window", window.stdout.splitlines()[0], |
| 162 | 174 | str(runs / "installed-window.png")], env=env, check=True) |
| 163 | 175 | print("PASS installed package, ZIP/7z/TAR.GZ defaults and native X11 window") |