zapretgui/tests/test_bypass_tools.py
loop-uh a420782f0a
All checks were successful
Zapret source guards / validate (push) Successful in 11s
Platform layer: processes and working set behind the interface
Platform.processes (list, strict list, command line, image path, loaded
modules, start time, kill) and Platform.working_set. Windows keeps the
Toolhelp/NT code in platforms/windows (process_probe, process_kill,
processes, working_set; moved from utils/); Linux uses psutil and /proc
(SIGTERM then SIGKILL); stub is safe and empty. Neutral callers (bypass
tools, diagnostics, DNS command, Telegram diagnostics, winws probe, killer
by name) ask the platform. Memory holding of a hidden window is the new
capability WORKING_SET, so the window presence helper is not installed
where it does nothing. Windows API list: 60 files.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-15 14:24:56 -05:00

40 lines
1.7 KiB
Python

from __future__ import annotations
import unittest
from unittest.mock import patch
from platforms import current as current_platform
from utils import bypass_tools
class BypassToolsTests(unittest.TestCase):
def test_tools_are_recognised_by_process_name_in_any_case(self) -> None:
names = ["explorer.exe", "XRAY.EXE", "sing-box.exe", "chrome.exe"]
self.assertEqual(bypass_tools.bypass_tools_among(names), ("Xray", "sing-box"))
def test_two_process_names_of_one_tool_are_named_once(self) -> None:
self.assertEqual(bypass_tools.bypass_tools_among(["ciadpi.exe", "byedpi.exe"]), ("ByeDPI",))
def test_ordinary_processes_and_zapret_itself_are_not_listed(self) -> None:
self.assertEqual(bypass_tools.bypass_tools_among(["winws2.exe", "winws.exe", "svchost.exe", "", None]), ())
def test_every_name_in_the_list_is_a_lowercase_exe(self) -> None:
for name, title in bypass_tools.BYPASS_TOOLS.items():
with self.subTest(name=name):
self.assertEqual(name, name.lower())
self.assertTrue(name.endswith(".exe"))
self.assertTrue(title)
def test_running_tools_come_from_process_list(self) -> None:
records = [(4, "System"), (100, "warp-svc.exe"), (200, "notepad.exe")]
with patch.object(current_platform().processes, "list_processes", return_value=records):
self.assertEqual(bypass_tools.running_bypass_tools(), ("Cloudflare WARP",))
def test_failed_process_list_means_nothing_known(self) -> None:
with patch.object(current_platform().processes, "list_processes", side_effect=OSError("нет доступа")):
self.assertEqual(bypass_tools.running_bypass_tools(), ())
if __name__ == "__main__":
unittest.main()