package service import ( "encoding/json" "strings" "testing" "github.com/ShukeBta/MediaStationGo/internal/model" ) func TestDownloadViewsDoNotExposePrivateURL(t *testing.T) { rows := []model.DownloadTask{{ UserID: "u1", Source: "qbittorrent", URL: "https://tracker.example/download?id=1&passkey=private-token", Title: "测试影片", SavePath: "/downloads", Status: "queued", }} tasks, torrents := DownloadViews(rows, nil) data, err := json.Marshal(map[string]any{ "tasks": tasks, "torrents": torrents, }) if err != nil { t.Fatal(err) } body := string(data) if strings.Contains(body, "private-token") || strings.Contains(body, "passkey") || strings.Contains(body, "tracker.example") { t.Fatalf("download views leaked private URL: %s", body) } if !strings.Contains(body, "测试影片") { t.Fatalf("download views should keep public title: %s", body) } } func TestPublicDownloadTitleUsesMagnetDisplayName(t *testing.T) { got := publicDownloadTitle("magnet:?xt=urn:btih:abc&dn=%E6%B5%8B%E8%AF%95%E5%BD%B1%E7%89%87") if got != "测试影片" { t.Fatalf("publicDownloadTitle = %q, want %q", got, "测试影片") } }