mirror of https://github.com/gofiber/fiber.git
🩹 Fix: panic unsupported context type, expected fiber.Ctx or context.Context
parent
675f2b274e
commit
64a7782d13
|
@ -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 ""
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue