新增:安全告警邮件展示来源 IP 网络归属(CDN/云厂商/WAF)

- 新增 internal/security/ipinfo:基于 projectdiscovery/cdncheck v1.3.0
  (离线指纹、零外部请求)识别来源 IP 归属,识别失败折叠为展示标签,
  不中断告警链路
- autoban 告警回调注入归属识别;告警邮件新增「网络归属」行,
  命中 CDN/代理网络时提示「封禁可能无法拦截真实来源」
- 新增邮件模板渲染回归测试 internal/mail/mail_alert_test.go
- dev/s3stub:webp(cgo) 本地类型检查桩,替换 s3.go 做全模块编译验证,
  生产 Linux 构建不受影响;dev/overlay.json 指向该桩
- go mod tidy 顺带升级共享依赖(lipgloss/xid/testify 等),
  全模块类型检查与相关包测试通过
This commit is contained in:
tamakyi
2026-09-08 13:25:20 +08:00
parent 35a846ea40
commit e94c2b57ce
12 changed files with 350 additions and 342 deletions
+27
View File
@@ -0,0 +1,27 @@
package ipinfo
import "testing"
// TestLookupInvalidIP 非法输入必须折叠为展示标签且不 panic,proxied 恒为 false。
func TestLookupInvalidIP(t *testing.T) {
for _, in := range []string{"", "not-an-ip", "999.1.1.1", " "} {
label, proxied := Lookup(in)
if proxied {
t.Errorf("Lookup(%q) proxied = true, want false", in)
}
if label == "" {
t.Errorf("Lookup(%q) label is empty, want a fallback label", in)
}
}
}
// TestLookupReturnsLabel 合法 IP 应返回非空标签且不 panic(不锁定具体归属,
// 避免上游签名快照更新导致测试抖动)。
func TestLookupReturnsLabel(t *testing.T) {
for _, in := range []string{"1.1.1.1", "8.8.8.8", "2606:4700:4700::1111"} {
label, _ := Lookup(in)
if label == "" {
t.Errorf("Lookup(%q) label is empty", in)
}
}
}