优化结构
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
||||
systemrouter "kra/internal/server/router"
|
||||
systemworker "kra/internal/worker"
|
||||
"kra/pkg/module"
|
||||
"kra/pkg/mq"
|
||||
platformtask "kra/pkg/task"
|
||||
)
|
||||
|
||||
@@ -28,10 +27,7 @@ func TaskRegistry(catalog module.Catalog) *platformtask.Registry {
|
||||
}
|
||||
|
||||
// Runtime composes HTTP route contributors from the enabled modules.
|
||||
func Runtime(systemRoutes *systemrouter.Routes, systemTasks *systemworker.TaskMethods, registry *platformtask.Registry, catalog module.Catalog, subscriptions mq.SubscriptionRegistrar) (*module.Runtime, error) {
|
||||
func Runtime(systemRoutes *systemrouter.Routes, systemTasks *systemworker.TaskMethods, registry *platformtask.Registry) *module.Runtime {
|
||||
platformtask.Apply(registry, systemTasks)
|
||||
if err := mq.ApplySubscriptions(subscriptions, catalog.SubscriptionContributors()...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return module.NewRuntime(systemRoutes), nil
|
||||
return module.NewRuntime(systemRoutes)
|
||||
}
|
||||
|
||||
@@ -12,10 +12,10 @@ import (
|
||||
)
|
||||
|
||||
type fakeClient struct {
|
||||
subscribed []string
|
||||
unsubscribed []string
|
||||
handlers map[string]platformmq.Handler
|
||||
subscribeErrors map[string]error
|
||||
subscribed []string
|
||||
unsubscribed []string
|
||||
handlers map[string]platformmq.Handler
|
||||
subscribeErrors map[string]error
|
||||
unsubscribeErrors map[string]error
|
||||
}
|
||||
|
||||
|
||||
@@ -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,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)
|
||||
|
||||
Reference in New Issue
Block a user