package sub import ( "encoding/base64" "net/http" "net/http/httptest" "strings" "testing" "github.com/gin-gonic/gin" ) // The JSON and Clash subscription formats were removed: their endpoints must // answer 404, while the link-format endpoint keeps serving the exact raw // base64 link list. func TestRemovedFormatEndpointsReturn404(t *testing.T) { seedSubDB(t) seedSubInbound(t, "s1", "gone", 4499, 1, `{"network":"tcp","security":"none"}`) gin.SetMode(gin.TestMode) router := newSubscriptionTestRouter() for _, path := range []string{"/json/s1", "/clash/s1"} { req := httptest.NewRequest(http.MethodGet, "http://sub.example.com"+path, nil) resp := httptest.NewRecorder() router.ServeHTTP(resp, req) if resp.Code != http.StatusNotFound { t.Fatalf("GET %s status = %d, want 404", path, resp.Code) } } req := httptest.NewRequest(http.MethodGet, "http://sub.example.com/sub/s1", nil) resp := httptest.NewRecorder() router.ServeHTTP(resp, req) if resp.Code != http.StatusOK { t.Fatalf("GET /sub/s1 status = %d, want 200; body=%s", resp.Code, resp.Body.String()) } decoded, err := base64.StdEncoding.DecodeString(resp.Body.String()) if err != nil { t.Fatalf("link response is not base64: %v", err) } if !strings.Contains(string(decoded), "vless://") { t.Fatalf("link output changed, decoded body lacks a VLESS link: %s", decoded) } }