优化结构

This commit is contained in:
Yvan
2026-08-22 11:26:58 +08:00
parent 54f76bd913
commit d987244d0e
8 changed files with 53 additions and 43 deletions
@@ -122,3 +122,25 @@ func TestAccessLogOmitsPaymentIntegrationConfigBody(t *testing.T) {
t.Fatalf("payment configuration summary missing: %s", logText)
}
}
func TestAccessLogRedactsWebSocketQueryToken(t *testing.T) {
gin.SetMode(gin.TestMode)
var logs bytes.Buffer
logger := slog.New(slog.NewTextHandler(&logs, &slog.HandlerOptions{Level: slog.LevelInfo}))
runtime := conf.NewRuntime(nil, &conf.AdminBackend{})
engine := gin.New()
engine.Use(AccessLog(runtime, logger, "test"))
engine.GET("/ws", func(c *gin.Context) { c.Status(http.StatusSwitchingProtocols) })
request := httptest.NewRequest(http.MethodGet, "/ws?token=jwt-secret&room=orders", nil)
response := httptest.NewRecorder()
engine.ServeHTTP(response, request)
logText := logs.String()
if strings.Contains(logText, "jwt-secret") {
t.Fatalf("websocket token leaked into access log: %s", logText)
}
if !strings.Contains(logText, "token=%2A%2A%2A") || !strings.Contains(logText, "room=orders") {
t.Fatalf("redacted query missing expected fields: %s", logText)
}
}
+1 -3
View File
@@ -1,8 +1,6 @@
package server
import (
"github.com/google/wire"
)
import "github.com/google/wire"
// ProviderSet is server providers.
var ProviderSet = wire.NewSet(NewGinEngineWithRuntime, NewGinServer)