MCPcopy
hub / github.com/appleboy/gin-jwt / TestTokenFromQueryString

Function TestTokenFromQueryString

auth_jwt_test.go:974–1010  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

972}
973
974func TestTokenFromQueryString(t *testing.T) {
975 // the middleware to test
976 authMiddleware, _ := New(&GinJWTMiddleware{
977 Realm: "test zone",
978 Key: key,
979 Timeout: time.Hour,
980 Authenticator: defaultAuthenticator,
981 Unauthorized: func(c *gin.Context, code int, message string) {
982 c.String(code, message)
983 },
984 TokenLookup: "query:token",
985 })
986
987 handler := ginHandler(authMiddleware)
988
989 r := gofight.New()
990
991 userToken, _, _ := authMiddleware.generateAccessToken(jwt.MapClaims{
992 "identity": testAdmin,
993 })
994
995 r.GET("/auth/hello").
996 SetHeader(gofight.H{
997 "Authorization": "Bearer " + userToken,
998 }).
999 Run(handler, func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
1000 assert.Equal(t, http.StatusUnauthorized, r.Code)
1001 })
1002
1003 r.GET("/auth/hello?token="+userToken).
1004 SetHeader(gofight.H{
1005 "Authorization": "Bearer " + userToken,
1006 }).
1007 Run(handler, func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
1008 assert.Equal(t, http.StatusOK, r.Code)
1009 })
1010}
1011
1012func TestTokenFromParamPath(t *testing.T) {
1013 // the middleware to test

Callers

nothing calls this directly

Calls 3

NewFunction · 0.85
ginHandlerFunction · 0.85
generateAccessTokenMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…