package comm import ( "strconv" "testing" ) // 这个测试守的是一条安全底线:服务端专用类别(实名认证等,凭据是云账号主 AK/SK) // 绝不能被 resolveThirdSvcs 下发给客户端。改动 IsServerOnlySvc 时必须让它继续通过。 func TestIsServerOnlySvc(t *testing.T) { idv := strconv.Itoa(int(SvcCatIdVerify)) mcp := strconv.Itoa(int(SvcCatMCP)) cases := []struct { categories string want bool why string }{ {idv, true, "纯身份证校验类别"}, {mcp + "," + idv, true, "混在其它类别里也要拦住"}, {idv + "," + mcp, true, "顺序无关"}, {" " + idv + " ", true, "带空白也要识别"}, {mcp, false, "MCP 是给客户端用的,照常下发"}, {"1,2,3", false, "普通 STT/TTS/MT 照常下发"}, {"", false, "空类别不拦"}, {"abc", false, "非数字忽略、不误判"}, } for _, c := range cases { if got := IsServerOnlySvc(c.categories); got != c.want { t.Errorf("IsServerOnlySvc(%q) = %v, want %v (%s)", c.categories, got, c.want, c.why) } } } func TestCategoriesHas(t *testing.T) { if !CategoriesHas("1,11,3", SvcCatIdVerify) { t.Error("应识别出含 SvcCatIdVerify") } // 不能被子串匹配骗到:类别 1 不等于类别 11 if CategoriesHas("11", 1) { t.Error("类别 11 被误判为含类别 1(子串匹配 bug)") } }