Skip to content

Commit

Permalink
fix review comments/hints
Browse files Browse the repository at this point in the history
  • Loading branch information
ReneWerner87 committed Feb 27, 2024
1 parent 639f552 commit 4c9e76d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
3 changes: 1 addition & 2 deletions .github/scripts/sync_docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion middleware/cors/cors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions middleware/healthcheck/healthcheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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/")
Expand Down
19 changes: 16 additions & 3 deletions middleware/session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand All @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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 := ""

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4c9e76d

Please sign in to comment.