test(defender): 固化处置链宿主基线 + 真机验证协议(docs/19),修越狱聚合回归
P0 验真:真机验证前先把「检测→分级→数据毒化」闭环做成可复现宿主绿灯。 新增: - tests/fixtures/poison_host.c + tests/test_poison_policy.py:poison/policy/ anti_jailbreak 闭环自测 19/19(poison 恒等+坏key+不可逆、policy 分级+去重+ mask一致、jailbreak 反向零误报+400+401),集成进 unittest 套件。 - docs/19_DISPOSITION_CHAIN_DEVICE_VERIFICATION.md:真机验证协议——R(非越狱)/ J(越狱)两组、D1–D7 用例、验收门槛(反向零毒化为开毒化前提)、边界与进度。 修复(接越狱探针进 ig_defender_scan 聚合器时埋下的回归): - test_defender_host.py SOURCES 漏 anti_jailbreak/IGAntiJailbreak.c → 链接缺符号。 - defender_host.c:reasons[] 由 256 扩到 512(400/401 越界漏计);clean 断言排除 越狱文件命中(macOS 自带 Unix userland,按 iOS 标准宿主本身即“越狱”,非真实误报)。 全套 63 项宿主/工具测试通过。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
599e1da5ce
commit
c4c9a6925a
@@ -0,0 +1,56 @@
|
||||
"""处置链宿主自测:poison + policy + anti_jailbreak 闭环(检测→分级→数据毒化)。
|
||||
|
||||
固化此前只在临时目录跑过的闭环为可复现基线,作为真机验证(docs/19)前的宿主绿灯。
|
||||
编译 tests/fixtures/poison_host.c 并运行,退出码 0=全部用例通过。
|
||||
"""
|
||||
from pathlib import Path
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
SOURCES = [
|
||||
'poison/IGPoison.c', 'policy/IGPolicy.c',
|
||||
'anti_jailbreak/IGAntiJailbreak.c', 'syscall/IGSyscall.c',
|
||||
'IGDefender.c', 'anti_hook/IGAntiHook.c', 'anti_hook/IGObjCBaseline.c',
|
||||
'anti_frida/IGAntiInject.c', 'anti_debug/IGAntiDebug.c',
|
||||
'resolve/IGResolve.c', 'dispatch/IGDispatch.c',
|
||||
'dispatch/IGArchiveGuard.c', 'call_bridge/IGFileBridge.c',
|
||||
]
|
||||
|
||||
|
||||
@unittest.skipUnless(sys.platform == 'darwin' and shutil.which('xcrun'), '需要 Xcode/macOS')
|
||||
class PoisonPolicyTests(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.tmp = tempfile.TemporaryDirectory()
|
||||
folder = Path(cls.tmp.name)
|
||||
cls.exe = folder / 'poison-host'
|
||||
cls.env = dict(os.environ)
|
||||
cls.env.pop('DYLD_INSERT_LIBRARIES', None)
|
||||
args = ['xcrun', '--sdk', 'macosx', 'clang', '-O2',
|
||||
'-I', str(ROOT / 'defender/include'), '-I', str(ROOT / 'defender'),
|
||||
str(ROOT / 'tests/fixtures/poison_host.c'),
|
||||
*(str(ROOT / 'defender' / p) for p in SOURCES),
|
||||
'-framework', 'Foundation', '-lobjc', '-o', str(cls.exe)]
|
||||
p = subprocess.run(args, capture_output=True, text=True, env=cls.env)
|
||||
if p.returncode:
|
||||
raise RuntimeError(p.stdout + p.stderr)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
cls.tmp.cleanup()
|
||||
|
||||
def test_chain(self):
|
||||
p = subprocess.run([str(self.exe)], capture_output=True, text=True, env=self.env)
|
||||
# 保留逐例证据到 unittest 日志。
|
||||
print(p.stdout.strip(), flush=True)
|
||||
self.assertEqual(p.returncode, 0, p.stdout + p.stderr)
|
||||
self.assertIn('0 fail', p.stdout)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user