diff --git a/.github/scripts/sync_docs.sh b/.github/scripts/sync_docs.sh index 0c7c6c9167..4898039680 100755 --- a/.github/scripts/sync_docs.sh +++ b/.github/scripts/sync_docs.sh @@ -26,8 +26,7 @@ if [ "$EVENT" == "push" ]; then fi # Handle release event -el -if [ "$EVENT" == "release" ]; then +elif [ "$EVENT" == "release" ]; then major_version="${TAG_NAME%%.*}" # Form new version name diff --git a/middleware/cors/cors.go b/middleware/cors/cors.go index 99f483550d..de96c1a689 100644 --- a/middleware/cors/cors.go +++ b/middleware/cors/cors.go @@ -197,7 +197,7 @@ func New(config ...Config) fiber.Handler { c.Set(fiber.HeaderAccessControlAllowOrigin, allowOrigin) c.Set(fiber.HeaderAccessControlAllowCredentials, "true") } else if allowOrigin == "*" { - log.Warn("[CORS] 'AllowCredentials' is true, but 'AllowOrigins' cannot be set to '*'.") + log.Warn("[CORS] 'AllowCredentials' is true. Ensure 'AllowOrigins' is not set to '*' in the configuration.") } } else { // For non-credential requests, it's safe to set to '*' or specific origins diff --git a/middleware/healthcheck/healthcheck_test.go b/middleware/healthcheck/healthcheck_test.go index d3ec7bedac..409b985a60 100644 --- a/middleware/healthcheck/healthcheck_test.go +++ b/middleware/healthcheck/healthcheck_test.go @@ -56,6 +56,7 @@ func Test_HealthCheck_Group_Default(t *testing.T) { v3Group := app.Group("/v3/") v3Group.Group("/todos/", New(Config{ReadinessEndpoint: "/readyz/", LivenessEndpoint: "/livez/"})) + // Testing health check endpoints in versioned API groups shouldGiveOK(t, app, "/v1/readyz") shouldGiveOK(t, app, "/v1/livez") shouldGiveOK(t, app, "/v1/readyz/") @@ -139,6 +140,7 @@ func Test_HealthCheck_Custom(t *testing.T) { ReadinessEndpoint: "/ready", })) + // Setup custom liveness and readiness probes to simulate application health status // Live should return 200 with GET request shouldGiveOK(t, app, "/live") // Live should return 404 with POST request @@ -182,6 +184,7 @@ func Test_HealthCheck_Custom_Nested(t *testing.T) { ReadinessEndpoint: "/probe/ready", })) + // Testing custom health check endpoints with nested paths shouldGiveOK(t, app, "/probe/live") shouldGiveStatus(t, app, "/probe/ready", fiber.StatusServiceUnavailable) shouldGiveOK(t, app, "/probe/live/") diff --git a/middleware/session/session_test.go b/middleware/session/session_test.go index f9166cabe4..ab2741b95e 100644 --- a/middleware/session/session_test.go +++ b/middleware/session/session_test.go @@ -22,6 +22,7 @@ func Test_Session(t *testing.T) { // fiber context ctx := app.AcquireCtx(&fasthttp.RequestCtx{}) + defer app.ReleaseCtx(ctx) // set session ctx.Request().Header.SetCookie(store.sessionName, "123") @@ -80,7 +81,9 @@ func Test_Session(t *testing.T) { // when we use the original session for the second time // the session be should be same if the session is not expired + app.ReleaseCtx(ctx) ctx = app.AcquireCtx(&fasthttp.RequestCtx{}) + defer app.ReleaseCtx(ctx) // request the server with the old session ctx.Request().Header.SetCookie(store.sessionName, id) @@ -102,6 +105,7 @@ func Test_Session_Types(t *testing.T) { // fiber context ctx := app.AcquireCtx(&fasthttp.RequestCtx{}) + defer app.ReleaseCtx(ctx) // set cookie ctx.Request().Header.SetCookie(store.sessionName, "123") @@ -266,6 +270,7 @@ func Test_Session_Store_Reset(t *testing.T) { app := fiber.New() // fiber context ctx := app.AcquireCtx(&fasthttp.RequestCtx{}) + defer app.ReleaseCtx(ctx) // get session sess, err := store.Get(ctx) @@ -321,6 +326,7 @@ func Test_Session_Save(t *testing.T) { app := fiber.New() // fiber context ctx := app.AcquireCtx(&fasthttp.RequestCtx{}) + defer app.ReleaseCtx(ctx) // get session sess, err := store.Get(ctx) @@ -348,6 +354,7 @@ func Test_Session_Save_Expiration(t *testing.T) { app := fiber.New() // fiber context ctx := app.AcquireCtx(&fasthttp.RequestCtx{}) + defer app.ReleaseCtx(ctx) // get session sess, err := store.Get(ctx) @@ -390,6 +397,7 @@ func Test_Session_Destroy(t *testing.T) { app := fiber.New() // fiber context ctx := app.AcquireCtx(&fasthttp.RequestCtx{}) + defer app.ReleaseCtx(ctx) // get session sess, err := store.Get(ctx) @@ -411,6 +419,7 @@ func Test_Session_Destroy(t *testing.T) { app := fiber.New() // fiber context ctx := app.AcquireCtx(&fasthttp.RequestCtx{}) + defer app.ReleaseCtx(ctx) // get session sess, err := store.Get(ctx) @@ -450,6 +459,7 @@ func Test_Session_Cookie(t *testing.T) { app := fiber.New() // fiber context ctx := app.AcquireCtx(&fasthttp.RequestCtx{}) + defer app.ReleaseCtx(ctx) // get session sess, err := store.Get(ctx) @@ -468,6 +478,7 @@ func Test_Session_Cookie_In_Response(t *testing.T) { // fiber context ctx := app.AcquireCtx(&fasthttp.RequestCtx{}) + defer app.ReleaseCtx(ctx) // get session sess, err := store.Get(ctx) @@ -493,6 +504,7 @@ func Test_Session_Deletes_Single_Key(t *testing.T) { app := fiber.New() ctx := app.AcquireCtx(&fasthttp.RequestCtx{}) + defer app.ReleaseCtx(ctx) sess, err := store.Get(ctx) require.NoError(t, err) @@ -521,11 +533,11 @@ func Test_Session_Reset(t *testing.T) { // session store store := New() - // fiber context - ctx := app.AcquireCtx(&fasthttp.RequestCtx{}) - t.Run("reset session data and id, and set fresh to be true", func(t *testing.T) { t.Parallel() + // fiber context + ctx := app.AcquireCtx(&fasthttp.RequestCtx{}) + defer app.ReleaseCtx(ctx) // a random session uuid originalSessionUUIDString := "" @@ -591,6 +603,7 @@ func Test_Session_Regenerate(t *testing.T) { originalSessionUUIDString := "" // fiber context ctx := app.AcquireCtx(&fasthttp.RequestCtx{}) + defer app.ReleaseCtx(ctx) // now the session is in the storage freshSession, err := store.Get(ctx) diff --git a/router.go b/router.go index f77b240a66..4347c7ba9f 100644 --- a/router.go +++ b/router.go @@ -210,12 +210,12 @@ func (app *App) requestHandler(rctx *fasthttp.RequestCtx) { if app.newCtxFunc != nil { c, ok = app.AcquireCtx(rctx).(CustomCtx) if !ok { - panic(errors.New("failed to type-assert to CustomCtx")) + panic(errors.New("requestHandler: failed to type-assert to CustomCtx")) } } else { c, ok = app.AcquireCtx(rctx).(*DefaultCtx) if !ok { - panic(errors.New("failed to type-assert to *DefaultCtx")) + panic(errors.New("requestHandler: failed to type-assert to *DefaultCtx")) } } c.Reset(rctx)