mutation_audit_test.go 19 KB

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