1
0

external_hwid_test.go 996 B

1234567891011121314151617181920212223242526272829303132333435
  1. package sub
  2. import (
  3. "net/http"
  4. "net/http/httptest"
  5. "path/filepath"
  6. "testing"
  7. "github.com/mhsanaei/3x-ui/v3/internal/database/dbtest"
  8. "github.com/mhsanaei/3x-ui/v3/internal/web/service"
  9. )
  10. // #6559: the Master panel must send a stable X-HWID when fetching external
  11. // subscriptions, otherwise an HWID-limited donor answers 404.
  12. func TestFetchSendsStableHwid(t *testing.T) {
  13. dbtest.InitDB(t, filepath.Join(t.TempDir(), "x-ui.db"))
  14. var gotHwid string
  15. srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  16. gotHwid = r.Header.Get("X-HWID")
  17. _, _ = w.Write([]byte("vless://uuid@host:443?security=none#x"))
  18. }))
  19. defer srv.Close()
  20. res := fetchSubscriptionLinks(srv.URL)
  21. if res.err != nil {
  22. t.Fatalf("fetch: %v", res.err)
  23. }
  24. if len(res.links) != 1 {
  25. t.Fatalf("links = %v", res.links)
  26. }
  27. if want := service.ExternalSubscriptionHwid(); gotHwid == "" || gotHwid != want {
  28. t.Fatalf("X-HWID = %q, want the panel's stable %q", gotHwid, want)
  29. }
  30. }