1
0

mutation_audit_test.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. package sub
  2. import (
  3. "encoding/base64"
  4. "encoding/json"
  5. "path/filepath"
  6. "strings"
  7. "testing"
  8. "time"
  9. "github.com/mhsanaei/3x-ui/v3/internal/database"
  10. "github.com/mhsanaei/3x-ui/v3/internal/database/model"
  11. "github.com/mhsanaei/3x-ui/v3/internal/xray"
  12. )
  13. // initMutDB spins up a real temp SQLite DB for tests that exercise DB-backed
  14. // query helpers, mirroring the house pattern in service_sharelink/dedup tests.
  15. func initMutDB(t *testing.T) {
  16. t.Helper()
  17. dbDir := t.TempDir()
  18. t.Setenv("XUI_DB_FOLDER", dbDir)
  19. if err := database.InitDB(filepath.Join(dbDir, "x-ui.db")); err != nil {
  20. t.Fatalf("InitDB: %v", err)
  21. }
  22. t.Cleanup(func() { _ = database.CloseDB() })
  23. }
  24. func externalLinkEnabled(v bool) *bool {
  25. return &v
  26. }
  27. // --- json_service.go:40 — rules are merged into routing only when non-empty ---
  28. func TestSubJsonService_CustomRulesPrepended(t *testing.T) {
  29. rules := `[{"type":"field","domain":["geosite:ads"],"outboundTag":"block"}]`
  30. svc := NewSubJsonService("", rules, "", nil)
  31. routing, ok := svc.configJson["routing"].(map[string]any)
  32. if !ok {
  33. t.Fatalf("routing missing: %#v", svc.configJson["routing"])
  34. }
  35. got, _ := routing["rules"].([]any)
  36. // default.json ships exactly 1 rule; the custom rule must be prepended.
  37. if len(got) != 2 {
  38. t.Fatalf("rules len = %d, want 2 (custom prepended to default)", len(got))
  39. }
  40. first, _ := got[0].(map[string]any)
  41. if domains, _ := first["domain"].([]any); len(domains) != 1 || domains[0] != "geosite:ads" {
  42. t.Fatalf("custom rule must come first, got %#v", got[0])
  43. }
  44. }
  45. func TestSubJsonService_EmptyRulesLeavesDefault(t *testing.T) {
  46. svc := NewSubJsonService("", "", "", nil)
  47. routing, _ := svc.configJson["routing"].(map[string]any)
  48. got, _ := routing["rules"].([]any)
  49. if len(got) != 1 {
  50. t.Fatalf("rules len = %d, want 1 (no custom rules → default untouched)", len(got))
  51. }
  52. }
  53. // --- json_service.go:331,356,408 — mux is attached only when configured ---
  54. func TestSubJsonService_MuxAttachedWhenConfigured(t *testing.T) {
  55. const mux = `{"enabled":true,"concurrency":8}`
  56. client := model.Client{ID: "uuid-1", Password: "p4ss"}
  57. cases := []struct {
  58. name string
  59. raw []byte
  60. wantMux bool
  61. protocol model.Protocol
  62. }{
  63. {"vmess mux", NewSubJsonService(mux, "", "", nil).genVnext(&model.Inbound{Protocol: model.VMESS, Settings: `{}`}, nil, client, mux), true, model.VMESS},
  64. {"vless mux", NewSubJsonService(mux, "", "", nil).genVless(&SubService{}, &model.Inbound{Protocol: model.VLESS, Settings: `{}`}, nil, client, mux), true, model.VLESS},
  65. {"server mux", NewSubJsonService(mux, "", "", nil).genServer(&SubService{}, &model.Inbound{Protocol: model.Trojan, Settings: `{}`}, nil, client, mux), true, model.Trojan},
  66. {"vmess no mux", NewSubJsonService("", "", "", nil).genVnext(&model.Inbound{Protocol: model.VMESS, Settings: `{}`}, nil, client, ""), false, model.VMESS},
  67. {"vless no mux", NewSubJsonService("", "", "", nil).genVless(&SubService{}, &model.Inbound{Protocol: model.VLESS, Settings: `{}`}, nil, client, ""), false, model.VLESS},
  68. {"server no mux", NewSubJsonService("", "", "", nil).genServer(&SubService{}, &model.Inbound{Protocol: model.Trojan, Settings: `{}`}, nil, client, ""), false, model.Trojan},
  69. }
  70. for _, tc := range cases {
  71. t.Run(tc.name, func(t *testing.T) {
  72. var ob map[string]any
  73. if err := json.Unmarshal(tc.raw, &ob); err != nil {
  74. t.Fatalf("unmarshal outbound: %v", err)
  75. }
  76. m, has := ob["mux"]
  77. if tc.wantMux {
  78. if !has {
  79. t.Fatalf("mux must be set when configured, outbound = %#v", ob)
  80. }
  81. mm, _ := m.(map[string]any)
  82. if mm["enabled"] != true || mm["concurrency"] != float64(8) {
  83. t.Fatalf("mux payload wrong: %#v", m)
  84. }
  85. } else if has {
  86. t.Fatalf("mux must be omitted when empty, outbound = %#v", ob)
  87. }
  88. })
  89. }
  90. }
  91. // --- applyGlobalFinalMask — a non-empty finalMask that merges to nothing must
  92. // not add the finalmask key (the `len(merged) > 0` guard). ---
  93. func TestSubJsonService_FinalMaskMergingToEmptyNotAdded(t *testing.T) {
  94. // finalMask is non-empty (passes the len(fm)==0 early return) but its only
  95. // key is an empty tcp slice, which mergeFinalMask drops → merged is empty,
  96. // so applyGlobalFinalMask must NOT set finalmask.
  97. svc := NewSubJsonService("", "", `{"tcp":[]}`, nil)
  98. stream := svc.streamData(`{"network":"tcp","security":"none","tcpSettings":{"header":{"type":"none"}}}`, "")
  99. if _, ok := stream["finalmask"]; ok {
  100. t.Fatalf("finalMask merging to empty must not add a finalmask key: %#v", stream["finalmask"])
  101. }
  102. // Sanity: a finalMask that DOES merge to something still gets set, so the
  103. // guard is the only distinguishing factor.
  104. svc2 := NewSubJsonService("", "", `{"tcp":[{"type":"fragment"}]}`, nil)
  105. stream2 := svc2.streamData(`{"network":"tcp","security":"none","tcpSettings":{"header":{"type":"none"}}}`, "")
  106. if _, ok := stream2["finalmask"]; !ok {
  107. t.Fatal("non-empty finalMask must be set")
  108. }
  109. }
  110. // --- mergeFinalMask — an empty extra tcp slice must not clobber the base ---
  111. func TestMergeFinalMask_EmptyExtraTcpKeepsBase(t *testing.T) {
  112. base := map[string]any{"tcp": []any{map[string]any{"type": "keep"}}}
  113. extra := map[string]any{"tcp": []any{}} // empty → must be ignored
  114. merged := mergeFinalMask(base, extra)
  115. tcp, _ := merged["tcp"].([]any)
  116. if len(tcp) != 1 {
  117. t.Fatalf("tcp len = %d, want 1 (empty extra must not drop or append)", len(tcp))
  118. }
  119. if first, _ := tcp[0].(map[string]any); first["type"] != "keep" {
  120. t.Fatalf("base tcp mask lost: %#v", tcp)
  121. }
  122. // Sanity: a non-empty extra DOES append, so the guard is the only thing
  123. // distinguishing the two paths.
  124. extra2 := map[string]any{"tcp": []any{map[string]any{"type": "add"}}}
  125. merged2 := mergeFinalMask(base, extra2)
  126. if tcp2, _ := merged2["tcp"].([]any); len(tcp2) != 2 {
  127. t.Fatalf("non-empty extra must append: len = %d, want 2", len(tcp2))
  128. }
  129. }
  130. // --- service.go:69-77 — configuredPublicHost priority: subDomain > webDomain > "" ---
  131. func TestConfiguredPublicHost_Priority(t *testing.T) {
  132. initMutDB(t)
  133. db := database.GetDB()
  134. set := func(key, val string) {
  135. if err := db.Save(&model.Setting{Key: key, Value: val}).Error; err != nil {
  136. t.Fatalf("save %s: %v", key, err)
  137. }
  138. }
  139. s := &SubService{}
  140. // Both empty → "".
  141. if got := s.configuredPublicHost(); got != "" {
  142. t.Fatalf("no domains configured: got %q, want empty", got)
  143. }
  144. // Only webDomain → webDomain wins (exercises the second branch, service.go:73).
  145. set("webDomain", "web.example.com")
  146. if got := s.configuredPublicHost(); got != "web.example.com" {
  147. t.Fatalf("webDomain fallback: got %q, want web.example.com", got)
  148. }
  149. // subDomain set → subDomain takes precedence over webDomain (service.go:70).
  150. set("subDomain", "sub.example.com")
  151. if got := s.configuredPublicHost(); got != "sub.example.com" {
  152. t.Fatalf("subDomain priority: got %q, want sub.example.com", got)
  153. }
  154. }
  155. // --- service.go:248 — AggregateTrafficByEmails tracks the MAX LastOnline ---
  156. func TestAggregateTrafficByEmails_LastOnlineIsMax(t *testing.T) {
  157. initMutDB(t)
  158. db := database.GetDB()
  159. rows := []xray.ClientTraffic{
  160. {Email: "a@x", Up: 10, Down: 20, LastOnline: 100},
  161. {Email: "b@x", Up: 1, Down: 2, LastOnline: 500}, // the max
  162. {Email: "c@x", Up: 3, Down: 4, LastOnline: 300},
  163. }
  164. for i := range rows {
  165. if err := db.Create(&rows[i]).Error; err != nil {
  166. t.Fatalf("seed traffic: %v", err)
  167. }
  168. }
  169. s := &SubService{}
  170. agg, lastOnline := s.AggregateTrafficByEmails([]string{"a@x", "b@x", "c@x"})
  171. if lastOnline != 500 {
  172. t.Fatalf("lastOnline = %d, want 500 (max across rows)", lastOnline)
  173. }
  174. // Up/Down must still sum so a mutant can't pass by zeroing everything.
  175. if agg.Up != 14 || agg.Down != 26 {
  176. t.Fatalf("agg up/down = %d/%d, want 14/26", agg.Up, agg.Down)
  177. }
  178. }
  179. // --- service.go:329 — projectThroughFallbackMaster returns false for nil ---
  180. func TestProjectThroughFallbackMaster_Nil(t *testing.T) {
  181. s := &SubService{}
  182. if s.projectThroughFallbackMaster(nil) {
  183. t.Fatal("nil inbound must yield false (no projection, no DB hit)")
  184. }
  185. }
  186. // --- service.go:555 — empty client flow must not emit a flow param even when allowed ---
  187. func TestGenVlessLink_NoFlowWhenClientFlowEmpty(t *testing.T) {
  188. // tcp+reality is a flow-allowed combo; with an empty client flow the
  189. // len(...)>0 guard (service.go:555) must keep `flow` out of the link.
  190. stream := `{
  191. "network":"tcp","security":"reality",
  192. "tcpSettings":{"header":{"type":"none"}},
  193. "realitySettings":{"serverNames":["r.example.com"],"shortIds":["ab"],"settings":{"publicKey":"PBK","fingerprint":"chrome"}}
  194. }`
  195. inbound := &model.Inbound{
  196. Listen: "203.0.113.1",
  197. Port: 443,
  198. Protocol: model.VLESS,
  199. Remark: "noflow",
  200. Settings: `{"clients":[{"id":"11111111-2222-4333-8444-555555555555","email":"user"}],"encryption":"none"}`,
  201. StreamSettings: stream,
  202. }
  203. s := &SubService{}
  204. if link := s.genVlessLink(inbound, "user"); strings.Contains(link, "flow=") {
  205. t.Fatalf("empty client flow must not produce a flow param, got %q", link)
  206. }
  207. }
  208. // --- service.go:906-913 — applyPathAndHostParams host source ---
  209. func TestApplyPathAndHostParams(t *testing.T) {
  210. // Direct host wins (service.go:908 true branch).
  211. params := map[string]string{}
  212. applyPathAndHostParams(map[string]any{"path": "/p", "host": "direct.example.com"}, params)
  213. if params["path"] != "/p" {
  214. t.Fatalf("path = %q, want /p", params["path"])
  215. }
  216. if params["host"] != "direct.example.com" {
  217. t.Fatalf("direct host = %q, want direct.example.com", params["host"])
  218. }
  219. // No direct host → fall back to headers.Host (service.go:908 false branch).
  220. params = map[string]string{}
  221. applyPathAndHostParams(map[string]any{
  222. "path": "/p",
  223. "headers": map[string]any{"Host": "via-header.example.com"},
  224. }, params)
  225. if params["host"] != "via-header.example.com" {
  226. t.Fatalf("header host fallback = %q, want via-header.example.com", params["host"])
  227. }
  228. // Empty-string host must NOT shadow the header fallback (len(host) > 0 guard).
  229. params = map[string]string{}
  230. applyPathAndHostParams(map[string]any{
  231. "path": "/p",
  232. "host": "",
  233. "headers": map[string]any{"Host": "via-header.example.com"},
  234. }, params)
  235. if params["host"] != "via-header.example.com" {
  236. t.Fatalf("empty host must defer to headers, got %q", params["host"])
  237. }
  238. }
  239. // --- external_config.go:39,42,55,58 — getClientExternalLinksBySubId ---
  240. func TestGetClientExternalLinksBySubId(t *testing.T) {
  241. initMutDB(t)
  242. db := database.GetDB()
  243. s := &SubService{}
  244. // No client rows for the subId → nil, no error (service.go path :42).
  245. out, err := s.getClientExternalLinksBySubId("missing")
  246. if err != nil {
  247. t.Fatalf("missing subId err = %v, want nil", err)
  248. }
  249. if out != nil {
  250. t.Fatalf("missing subId = %#v, want nil", out)
  251. }
  252. // A client with NO external-link rows → nil (the rows-empty guard :58).
  253. bare := &model.ClientRecord{Email: "bare@x", SubID: "sub-bare", UUID: "u", Enable: true}
  254. if err := db.Create(bare).Error; err != nil {
  255. t.Fatalf("seed bare client: %v", err)
  256. }
  257. out, err = s.getClientExternalLinksBySubId("sub-bare")
  258. if err != nil {
  259. t.Fatalf("bare subId err = %v", err)
  260. }
  261. if out != nil {
  262. t.Fatalf("client with no links = %#v, want nil", out)
  263. }
  264. // A client with two link rows: ordering by sort_index and email/enable
  265. // attribution from the owning client (the loop copies rec.Email/rec.Enable).
  266. rec := &model.ClientRecord{Email: "owner@x", SubID: "sub-ok", UUID: "u2", Enable: true}
  267. if err := db.Create(rec).Error; err != nil {
  268. t.Fatalf("seed client: %v", err)
  269. }
  270. if err := db.Create(&model.ClientExternalLink{ClientId: rec.Id, Kind: model.ExternalLinkKindLink, Value: "trojan://b", Remark: "second", SortIndex: 5}).Error; err != nil {
  271. t.Fatalf("seed link b: %v", err)
  272. }
  273. if err := db.Create(&model.ClientExternalLink{ClientId: rec.Id, Kind: model.ExternalLinkKindLink, Value: "trojan://a", Remark: "first", SortIndex: 1}).Error; err != nil {
  274. t.Fatalf("seed link a: %v", err)
  275. }
  276. if err := db.Create(&model.ClientExternalLink{ClientId: rec.Id, Kind: model.ExternalLinkKindLink, Value: "trojan://disabled", Remark: "disabled", Enable: externalLinkEnabled(false), SortIndex: 3}).Error; err != nil {
  277. t.Fatalf("seed disabled link: %v", err)
  278. }
  279. if err := db.Create(&model.ClientExternalLink{ClientId: rec.Id, Kind: model.ExternalLinkKindLink, Value: "trojan://expired", Remark: "expired", ExpiryTime: time.Now().Add(-time.Hour).UnixMilli(), SortIndex: 4}).Error; err != nil {
  280. t.Fatalf("seed expired link: %v", err)
  281. }
  282. out, err = s.getClientExternalLinksBySubId("sub-ok")
  283. if err != nil {
  284. t.Fatalf("ok subId err = %v", err)
  285. }
  286. if len(out) != 2 {
  287. t.Fatalf("entries = %d, want 2", len(out))
  288. }
  289. // sort_index ASC: the SortIndex=1 row comes first.
  290. if out[0].Value != "trojan://a" || out[1].Value != "trojan://b" {
  291. t.Fatalf("ordering wrong: %#v", out)
  292. }
  293. // Email + Enable must be copied from the owning client, not the link row
  294. // (which carries neither field). The enabled owner → Enable true.
  295. if out[0].Email != "owner@x" || out[0].Enable != true {
  296. t.Fatalf("attribution wrong: email=%q enable=%v", out[0].Email, out[0].Enable)
  297. }
  298. // A DISABLED client must produce entries with Enable=false, proving the
  299. // value is read from the client row (Enable has a gorm default:true, so
  300. // flip it with a raw UPDATE that bypasses the default).
  301. dis := &model.ClientRecord{Email: "off@x", SubID: "sub-off", UUID: "u3", Enable: true}
  302. if err := db.Create(dis).Error; err != nil {
  303. t.Fatalf("seed disabled client: %v", err)
  304. }
  305. if err := db.Model(&model.ClientRecord{}).Where("id = ?", dis.Id).Update("enable", false).Error; err != nil {
  306. t.Fatalf("disable client: %v", err)
  307. }
  308. if err := db.Create(&model.ClientExternalLink{ClientId: dis.Id, Kind: model.ExternalLinkKindLink, Value: "trojan://c", SortIndex: 1}).Error; err != nil {
  309. t.Fatalf("seed link c: %v", err)
  310. }
  311. offOut, err := s.getClientExternalLinksBySubId("sub-off")
  312. if err != nil {
  313. t.Fatalf("off subId err = %v", err)
  314. }
  315. if len(offOut) != 1 {
  316. t.Fatalf("disabled client entries = %d, want 1", len(offOut))
  317. }
  318. if offOut[0].Email != "off@x" || offOut[0].Enable != false {
  319. t.Fatalf("disabled attribution wrong: email=%q enable=%v", offOut[0].Email, offOut[0].Enable)
  320. }
  321. }
  322. // --- external_config.go:102 — applyRemarkToLink appends a fragment when none exists ---
  323. func TestApplyRemarkToLink_NoFragmentAppends(t *testing.T) {
  324. link := "trojan://[email protected]:8443?security=tls"
  325. out := applyRemarkToLink(link, "DE-Node")
  326. if out != link+"#DE-Node" {
  327. t.Fatalf("no-fragment link must get the remark appended, got %q", out)
  328. }
  329. }
  330. // --- external_config.go:111 — applyVmessRemark falls back to RawURLEncoding ---
  331. func TestApplyVmessRemark_RawURLEncodingFallback(t *testing.T) {
  332. // The "aa?" ps forces a URL-safe char (_) in the RawURL encoding, so
  333. // base64.StdEncoding.DecodeString fails and the RawURLEncoding fallback
  334. // path (external_config.go:111) must take over. (ps is overwritten below,
  335. // so its value is irrelevant to the assertions.)
  336. payload := map[string]any{"v": "2", "ps": "aa?", "add": "1.2.3.4", "port": "443", "id": "uuid"}
  337. b, _ := json.Marshal(payload)
  338. link := "vmess://" + base64.RawURLEncoding.EncodeToString(b)
  339. // Guard the premise: this link must NOT be std-decodable, else the fallback
  340. // branch is never reached and the test is meaningless.
  341. if _, err := base64.StdEncoding.DecodeString(padBase64Sub(strings.TrimPrefix(link, "vmess://"))); err == nil {
  342. t.Fatal("test premise broken: link is std-base64 decodable, fallback not exercised")
  343. }
  344. out := applyRemarkToLink(link, "NL-Node")
  345. if out == link {
  346. t.Fatalf("raw-url-encoded vmess remark was not applied (fallback decode broken): %q", out)
  347. }
  348. // The result re-encodes with StdEncoding; decode and verify ps + credentials.
  349. raw, err := base64.StdEncoding.DecodeString(strings.TrimPrefix(out, "vmess://"))
  350. if err != nil {
  351. t.Fatalf("decode out: %v", err)
  352. }
  353. var got map[string]any
  354. if err := json.Unmarshal(raw, &got); err != nil {
  355. t.Fatalf("unmarshal: %v", err)
  356. }
  357. if got["ps"] != "NL-Node" {
  358. t.Fatalf("ps = %v, want NL-Node", got["ps"])
  359. }
  360. if got["id"] != "uuid" {
  361. t.Fatalf("credentials lost via fallback path: %#v", got)
  362. }
  363. }
  364. // --- external_config.go:130 — padBase64Sub pads to a multiple of 4 ---
  365. func TestPadBase64Sub(t *testing.T) {
  366. cases := map[string]string{
  367. "": "",
  368. "a": "a===",
  369. "ab": "ab==",
  370. "abc": "abc=",
  371. "abcd": "abcd",
  372. }
  373. for in, want := range cases {
  374. if got := padBase64Sub(in); got != want {
  375. t.Fatalf("padBase64Sub(%q) = %q, want %q", in, got, want)
  376. }
  377. if len(padBase64Sub(in))%4 != 0 {
  378. t.Fatalf("padBase64Sub(%q) length not a multiple of 4", in)
  379. }
  380. }
  381. }
  382. // --- external_subscription.go:122 — base64 body decode strips embedded whitespace ---
  383. func TestDecodeSubscriptionBody_StripsWhitespaceInBase64(t *testing.T) {
  384. plain := "vless://[email protected]:443#one\ntrojan://[email protected]:8443#two\n"
  385. encoded := base64.StdEncoding.EncodeToString([]byte(plain))
  386. // Inject whitespace into the base64 token; tryDecodeBase64Body must strip it
  387. // (external_subscription.go:122) so decoding still succeeds.
  388. half := len(encoded) / 2
  389. dirty := encoded[:half] + "\n \t" + encoded[half:]
  390. links := decodeSubscriptionBody([]byte(dirty))
  391. if len(links) != 2 || links[0] != "vless://[email protected]:443#one" || links[1] != "trojan://[email protected]:8443#two" {
  392. t.Fatalf("whitespace-laden base64 body decoded wrong: %#v", links)
  393. }
  394. }
  395. // --- clash_service.go:123 — duplicate proxy names disambiguate as base-N ---
  396. func TestEnsureUniqueProxyNames_SuffixSequence(t *testing.T) {
  397. proxies := []map[string]any{
  398. {"name": "node"},
  399. {"name": "node"},
  400. {"name": "node"},
  401. }
  402. ensureUniqueProxyNames(proxies)
  403. if proxies[0]["name"] != "node" {
  404. t.Fatalf("first occurrence must keep base name, got %v", proxies[0]["name"])
  405. }
  406. if proxies[1]["name"] != "node-2" {
  407. t.Fatalf("second duplicate = %v, want node-2", proxies[1]["name"])
  408. }
  409. if proxies[2]["name"] != "node-3" {
  410. t.Fatalf("third duplicate = %v, want node-3", proxies[2]["name"])
  411. }
  412. }
  413. // --- clash_service.go:422,447 — empty transport opts must NOT add the *-opts key ---
  414. func TestApplyTransport_EmptyOptsOmitted(t *testing.T) {
  415. svc := &SubClashService{}
  416. // httpupgrade with no path/host → opts empty → no http-upgrade-opts key (clash:422).
  417. huProxy := map[string]any{}
  418. if !svc.applyTransport(huProxy, "httpupgrade", map[string]any{"httpupgradeSettings": map[string]any{}}) {
  419. t.Fatal("httpupgrade must still be buildable")
  420. }
  421. if huProxy["network"] != "httpupgrade" {
  422. t.Fatalf("network = %v, want httpupgrade", huProxy["network"])
  423. }
  424. if _, ok := huProxy["http-upgrade-opts"]; ok {
  425. t.Fatalf("empty opts must not set http-upgrade-opts: %#v", huProxy["http-upgrade-opts"])
  426. }
  427. // xhttp with no path/host/mode → opts empty → no xhttp-opts key (clash:447).
  428. xhProxy := map[string]any{}
  429. if !svc.applyTransport(xhProxy, "xhttp", map[string]any{"xhttpSettings": map[string]any{}}) {
  430. t.Fatal("xhttp must still be buildable")
  431. }
  432. if xhProxy["network"] != "xhttp" {
  433. t.Fatalf("network = %v, want xhttp", xhProxy["network"])
  434. }
  435. if _, ok := xhProxy["xhttp-opts"]; ok {
  436. t.Fatalf("empty opts must not set xhttp-opts: %#v", xhProxy["xhttp-opts"])
  437. }
  438. }