echo icon indicating copy to clipboard operation
echo copied to clipboard

Testing route with jwt [question]

Open LemonRuss opened this issue 9 years ago • 2 comments

Writing test for echo server with jwt. Getting error

panic: interface conversion: interface {} is nil, not *jwt.Token [recovered]

in user := c.Get("user").(*jwt.Token) When starting the server - all is fine. Seems i should somehow connect JWT middleware in test suite, but i can't get how. I looked here, but still in trouble. https://github.com/labstack/echo/blob/master/middleware/jwt_test.go Can someone give me a clue?

Code from test suit: e := echo.New() req, err := http.NewRequest(echo.GET, "/v1/social", nil) rec := httptest.NewRecorder() c := e.NewContext(req, rec) err := user.Get(c)

LemonRuss avatar Mar 19 '17 17:03 LemonRuss

You need to set JWT in your request, something like below:

req.Header.Set("Authorization", "<JWT>")

vishr avatar Mar 23 '17 16:03 vishr

Thank you, i tried! There was something more. I took "httpexpect" library, it helps.

LemonRuss avatar Mar 23 '17 19:03 LemonRuss