feat(deps)!: migrate from fiber v2 to fiber v3

BREAKING CHANGE: upgrades the HTTP framework from gofiber/fiber/v2 to gofiber/fiber/v3, and gofiber/websocket/v2 to gofiber/contrib/v3/websocket.

- Handlers now take fiber.Ctx (interface) instead of *fiber.Ctx. - DisableStartupMessage moved from fiber.Config to fiber.ListenConfig on the proxy/api/monitoring Listen calls. - cors AllowOrigins is now []string; c.BodyParser -> c.Bind().Body(). - app.Test takes fiber.TestConfig instead of an int timeout (tests updated). - WebSocket swapped to contrib/v3/websocket (same Conn/New/Config/IsCloseError/IsWebSocketUpgrade API; Conn.Query preserved). - Adopts fasthttp v1.71.0 (pulled by fiber v3), resolving the v1.71 Host-header enforcement that broke the prior pinned-v1.69 workaround.

fix(connpool): the background keep-alive goroutine no longer reads the mutable global cfg (captures HostGraphQL/HealthcheckGraphQL at pool creation). Under v3 timing it raced with parseConfig/test cfg reassignment; go test -race ./... is now clean (0 data races).

test: make the circuit-breaker cache-fallback and request-coalescing integration tests deterministic (cache TTL outlives the retry loop; coalescing asserts against a measured single-request baseline instead of a hard-coded count); drop the flaky timing-ratio assertion in TestTimingAttackResistance (constant-time guarantee comes from subtle.ConstantTimeCompare, not wall-clock timing).

Verified: go build, go vet, golangci-lint (0 issues), go test -race ./... (all packages pass, 0 races), govulncheck (no vulnerabilities). App + dashboard + WebSocket verified live under v3 in single-node and cluster modes.
This commit is contained in:
2026-06-21 13:15:14 +01:00
parent 877325a633
commit 55fc2ae1de
31 changed files with 265 additions and 240 deletions
+10 -37
View File
@@ -11,9 +11,8 @@ import (
"strings"
"sync"
"testing"
"time"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v3"
libpack_cache "github.com/lukaszraczylo/graphql-monitoring-proxy/cache"
libpack_logger "github.com/lukaszraczylo/graphql-monitoring-proxy/logging"
"github.com/stretchr/testify/suite"
@@ -55,9 +54,7 @@ func (suite *APIAuthSecurityTestSuite) SetupTest() {
suite.validAPIKey = "test-secure-api-key-12345"
// Create test Fiber app with authentication
suite.app = fiber.New(fiber.Config{
DisableStartupMessage: true,
})
suite.app = fiber.New(fiber.Config{})
// Setup API routes with authentication middleware
api := suite.app.Group("/api")
@@ -316,7 +313,7 @@ func (suite *APIAuthSecurityTestSuite) TestAPIAuthenticationWithoutConfiguredKey
os.Unsetenv("ADMIN_API_KEY")
// Create new app without configured API key
app := fiber.New(fiber.Config{DisableStartupMessage: true})
app := fiber.New()
api := app.Group("/api")
api.Use(authMiddleware)
api.Post("/user-ban", apiBanUser)
@@ -356,11 +353,7 @@ func (suite *APIAuthSecurityTestSuite) TestTimingAttackResistance() {
"", // Empty
}
timings := make([]time.Duration, len(invalidKeys))
for i, key := range invalidKeys {
start := time.Now()
for _, key := range invalidKeys {
req, err := http.NewRequest("POST", "/api/user-ban",
bytes.NewBuffer([]byte(`{"user_id": "test", "reason": "test"}`)))
suite.NoError(err)
@@ -370,35 +363,15 @@ func (suite *APIAuthSecurityTestSuite) TestTimingAttackResistance() {
resp, err := suite.app.Test(req)
suite.NoError(err)
timings[i] = time.Since(start)
suite.Equal(401, resp.StatusCode,
"All invalid keys should return 401, key: %s", key)
}
// Verify that timing variations are minimal (within reasonable bounds)
// This is a heuristic test - timing attack resistance is primarily
// achieved by the subtle.ConstantTimeCompare function
var minTime, maxTime time.Duration
for i, timing := range timings {
if i == 0 {
minTime = timing
maxTime = timing
} else {
if timing < minTime {
minTime = timing
}
if timing > maxTime {
maxTime = timing
}
}
}
// The timing difference should be reasonable (not orders of magnitude)
// This is mainly to catch obvious timing leaks
timingRatio := float64(maxTime) / float64(minTime)
suite.Less(timingRatio, 10.0,
"Timing difference should be reasonable (max/min < 10x)")
// Timing-attack resistance is guaranteed by subtle.ConstantTimeCompare in
// authMiddleware (verified by code, not by wall-clock measurement). Asserting
// on a max/min wall-clock ratio across full HTTP round-trips is unreliable:
// it is dominated by scheduler/GC noise and produces flaky failures, so we
// intentionally do not assert on the timing ratio.
}
// TestConcurrentAPIAuthentication tests authentication under concurrent load
@@ -616,7 +589,7 @@ func BenchmarkAPIAuthentication(b *testing.B) {
os.Setenv("GMP_ADMIN_API_KEY", validAPIKey)
defer os.Unsetenv("GMP_ADMIN_API_KEY")
app := fiber.New(fiber.Config{DisableStartupMessage: true})
app := fiber.New()
api := app.Group("/api")
api.Use(authMiddleware)
api.Get("/cache-stats", apiCacheStats)