🩹 Fix: panic unsupported context type, expected fiber.Ctx or context.Context

pull/3340/head
JIeJaitt 2025-03-13 15:02:35 +08:00
parent 675f2b274e
commit 64a7782d13
2 changed files with 2 additions and 16 deletions

View File

@ -208,7 +208,7 @@ func TokenFromContext(c any) string {
return token
}
default:
log.Errorf("Unsupported context type: %T. Expected fiber.Ctx or context.Context", c)
panic("unsupported context type, expected fiber.Ctx or context.Context")
}
return ""
}

View File

@ -1569,7 +1569,7 @@ func Test_CSRF_FromContextMethods_Invalid(t *testing.T) {
}
// Test_CSRF_GoContext Test for getting token and handler from Go standard context
func Test_CSRF_GoContext(t *testing.T) {
func Test_CSRF_Context(t *testing.T) {
t.Parallel()
app := fiber.New()
@ -1599,20 +1599,6 @@ func Test_CSRF_GoContext(t *testing.T) {
require.Equal(t, fiber.StatusOK, resp.StatusCode)
}
// Test_CSRF_UnsupportedContext Test for passing in unsupported context types
func Test_CSRF_UnsupportedContext(t *testing.T) {
t.Parallel()
// Using unsupported context types
invalidCtx := "not a context"
token := TokenFromContext(invalidCtx)
require.Empty(t, token)
handler := HandlerFromContext(invalidCtx)
require.Nil(t, handler)
}
// Test_CSRF_ServiceLayer Testing the use of Go standard contexts in the service layer
func Test_CSRF_ServiceLayer(t *testing.T) {
t.Parallel()