This commit is contained in:
Yvan
2026-09-04 10:51:45 +08:00
parent d94e2ed225
commit af1e194396
17 changed files with 1015 additions and 61 deletions
+33
View File
@@ -71,4 +71,37 @@ func TestWebSocketRouteRequiresAndAcceptsLoginToken(t *testing.T) {
}
}
func TestWebSocketRouteSupportsRouterPrefix(t *testing.T) {
store := runtimeconfig.NewStore()
raw, err := json.Marshal(map[string]any{"path": "/ws"})
if err != nil {
t.Fatal(err)
}
store.Set(runtimeconfig.Config{Kind: "websocket", Provider: websocketintegration.ProviderMelody, Enabled: true, Values: raw})
ws, cleanup, err := websocketintegration.New(store)
if err != nil {
t.Fatal(err)
}
defer cleanup()
auth := &websocketAuthStub{claims: &system.AuthClaims{ID: 7}}
runtime := config.NewStore(&config.Config{Admin: &config.Admin{RouterPrefix: "/admin"}})
engine := NewGinEngineWithRuntime(runtime, nil, auth, nil, nil, nil, "test", nil, ws)
httpServer := httptest.NewServer(engine)
defer httpServer.Close()
wsURL := "ws" + strings.TrimPrefix(httpServer.URL, "http") + "/admin/ws?token=login-token"
connection, response, err := gorillawebsocket.DefaultDialer.Dial(wsURL, nil)
if response != nil && response.Body != nil {
_ = response.Body.Close()
}
if err != nil {
t.Fatalf("prefixed websocket handshake failed: %v", err)
}
if connection == nil {
t.Fatal("prefixed websocket handshake returned nil connection")
}
_ = connection.Close()
}
var _ platformws.Hub = (*websocketintegration.Server)(nil)