Files
HomeAgent/internal/plugin/proc/shm_security_test.go
JianFeeeee 7a328679da feat(proc): Cleaner 跨进程修复(tool/input/output) + 共享内存安全模式 + plan §13
- Cleaner 协议统一为 cleaner.invoke(scope,name,text),覆盖工具/输入/输出三类
- 新增 ShmSecurityMode (safe/debug/full),Linux 审计探针,Windows crypto nonce
- plan.md 追加 §13 步骤分组
2026-09-10 10:21:50 +08:00

64 lines
1.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package proc
import (
"testing"
)
func TestShmSecurityMode_DefaultsToSafe(t *testing.T) {
if ShmSecurityModeOf() != ShmModeSafe {
t.Fatalf("默认应为 safe实际 %q", ShmSecurityModeOf())
}
}
func TestShmAudit_ZeroPluginsNoMapping(t *testing.T) {
h, err := NewHost()
if err != nil {
t.Fatalf("NewHost: %v", err)
}
defer h.Close()
a, ok := h.AuditShmMappings(0)
if !ok {
// 非 Linux 平台无探针,本测试断言"平台探针不误报"
t.Logf("平台无探针ok=false跳过")
return
}
// 无子进程时实际映射数应为 0
if a.ActualMappings != 0 {
t.Fatalf("无子进程时应无映射,实际 %d", a.ActualMappings)
}
if a.Delta != 0 {
t.Fatalf("Delta 应为 0实际 %d", a.Delta)
}
}
// 子进程挂载共享段后Linux 探针应能看到对应映射。
func TestShmAudit_SeesChildMapping(t *testing.T) {
bin := buildTestPlugin(t, "stageplugin.go")
core := newFakeCore()
host, err := NewHost()
if err != nil {
t.Fatalf("NewHost: %v", err)
}
defer host.Close()
p := New("audit", bin, t.TempDir(), nil, host, nil)
if err := p.Start(core); err != nil {
t.Fatalf("Start: %v", err)
}
defer p.Close()
a, ok := host.AuditShmMappings(1)
if !ok {
t.Logf("平台无探针ok=false跳过")
return
}
// 至少应看到 1 个儿童映射
if a.ActualMappings < 1 {
t.Fatalf("子进程应映射共享段,实际映射数 %d", a.ActualMappings)
}
// 期望 1、实际 ≥1 → delta 不应为负且不应报警delta>0 才告警)
_ = a
}