team-ljyzipelo

공개

시험 도구 경로와 창 탐색 보호 수정

작성자
코노모리 카논
작성 시각
커밋
7f37d2ac64b64333aa2eea2a15ccf2c741bf8b68
부모
07e5d2b
이 시점의 파일 보기

변경된 파일 5개

+133-14
수정tests/ci/run_rust.py+6-3
@@ -98,10 +98,13 @@ def command(manifest, phase):
9898
9999def prepare_fixtures(root):
100100 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)
101106 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)
105108 info = path.lstat()
106109 if (
107110 not stat.S_ISDIR(info.st_mode)
수정tests/ci/setup_windows.sh+17-1
@@ -10,8 +10,24 @@ if [[ ! "$job" =~ ^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$ ]]; then
1010 exit 2
1111fi
1212ci_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추가: )"
1330mkdir -p "$ci_tools/downloads" "$ci_tools/mingw"
14삭제: ci_tools="$(cd "$ci_tools" && pwd)"
1531
1632# 도구를 프로젝트 안에 풀며 시스템 패키지는 설치하지 않음.
1733(
수정tests/ci/test_runner.py+46-0
@@ -47,6 +47,52 @@ class RunnerTests(unittest.TestCase):
4747 self.assertFalse((outside / "task").exists())
4848 self.assertFalse((outside / "work").exists())
4949
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추가:
5096 def test_output_paths_reject_symlinks_outside_job(self):
5197 with tempfile.TemporaryDirectory(dir=TEST_WORK) as directory:
5298 work = Path(directory)
수정tests/release-packages/test_ubuntu_lifecycle.py+42-0
@@ -98,6 +98,48 @@ with patch.object(module.subprocess, "run", return_value=subprocess.CompletedPro
9898 self.assertEqual(result.returncode, 0, result.stderr)
9999 self.assertEqual(result.stdout.strip(), "blocked")
100100
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추가:
101143 def test_existing_installation_files_are_blocked(self):
102144 with (
103145 patch.object(SMOKE.subprocess, "run", return_value=subprocess.CompletedProcess([], 1, b"")),
수정tests/release-packages/ubuntu_smoke.py+22-10
@@ -109,6 +109,26 @@ def installed_package(package, home):
109109 raise BaseExceptionGroup("패키지 시험 또는 정리 실패", failures)
110110
111111
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추가:
112132def main():
113133 parser = argparse.ArgumentParser(description=__doc__)
114134 parser.add_argument("package", type=Path)
@@ -147,17 +167,9 @@ def main():
147167 env.pop("WAYLAND_DISPLAY", None)
148168 with (runs / "app.stdout").open("wb") as stdout, (runs / "app.stderr").open("wb") as stderr:
149169 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)
159171 time.sleep(3)
160삭제: assert app.poll() is None
172추가: ensure_app_running(app)
161173 subprocess.run(["import", "-window", window.stdout.splitlines()[0],
162174 str(runs / "installed-window.png")], env=env, check=True)
163175 print("PASS installed package, ZIP/7z/TAR.GZ defaults and native X11 window")