mutation_audit_test.go 19 KB

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