test_q3_desktop_security.py python
60 lines 2.2 KB
Raw
sha256:a78e7e5a8740e03315f325d19edeb3aa1b306b3337d04abbaa9a9e0f3bbeb7a1 docs: MuseHub-first before ISR #74 — staging solidify NEXT Human 1 day ago
1 """Security tests for Track Q / Q3 Tauri desktop packaging."""
2
3 from __future__ import annotations
4
5 from pathlib import Path
6
7 from tests.fixtures.desktop import make_desktop_launcher
8 from tests.support import KIT_ROOT
9 from tools.desktop.init_script import build_auth_bootstrap_script
10 from tools.desktop.launcher import build_launch_argv
11 from tools.desktop.manifest import DesktopManifest, validate_desktop_manifest
12
13
14 def test_launch_argv_rejects_shell_metacharacters_in_paths(tmp_path: Path) -> None:
15 weird = tmp_path / "weird;rm -rf"
16 weird.mkdir()
17 argv = build_launch_argv(kit_root_path=KIT_ROOT, repo_root=weird, port=8765)
18 joined = " ".join(argv)
19 assert ";rm" in joined
20 assert "eval" not in joined
21 assert argv[0].endswith("/cli/ok")
22
23
24 def test_init_script_does_not_persist_credentials() -> None:
25 script = build_auth_bootstrap_script(session_credential="secret", csrf_token="csrf")
26 assert "localStorage" not in script
27 assert "sessionStorage" not in script
28 assert "document.cookie" not in script
29
30
31 def test_desktop_launcher_does_not_write_secrets_to_repo(tmp_path: Path) -> None:
32 launcher = make_desktop_launcher(tmp_path)
33 try:
34 banner = launcher.start()
35 repo_text = "\n".join(
36 path.read_text(encoding="utf-8", errors="ignore")
37 for path in tmp_path.rglob("*")
38 if path.is_file()
39 )
40 assert banner.session_credential not in repo_text
41 assert banner.csrf_token not in repo_text
42 finally:
43 launcher.stop()
44
45
46 def test_tauri_lib_keeps_loopback_only_defaults() -> None:
47 lib = (KIT_ROOT / "desktop" / "src-tauri" / "src" / "lib.rs").read_text(encoding="utf-8")
48 launcher_rs = (KIT_ROOT / "desktop" / "src-tauri" / "src" / "launcher.rs").read_text(encoding="utf-8")
49 assert "127.0.0.1" in launcher_rs
50 assert "0.0.0.0" not in launcher_rs
51 assert "ok" in launcher_rs and "app" in launcher_rs
52 assert "WebviewUrl::External" in lib
53
54
55 def test_manifest_has_no_absolute_home_paths() -> None:
56 manifest = DesktopManifest.from_kit_root(KIT_ROOT)
57 for path in (manifest.tauri_conf, manifest.lib_rs, manifest.bundle_script):
58 text = path.read_text(encoding="utf-8")
59 assert "/Users/" not in text
60 assert "password" not in text.lower()
File History 1 commit
sha256:a78e7e5a8740e03315f325d19edeb3aa1b306b3337d04abbaa9a9e0f3bbeb7a1 docs: MuseHub-first before ISR #74 — staging solidify NEXT Human 1 day ago