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

Function TestTokenFromParamPath

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

Source from the content-addressed store, hash-verified

1010}
1011
1012func TestTokenFromParamPath(t *testing.T) {
1013 // the middleware to test
1014 authMiddleware, _ := New(&GinJWTMiddleware{
1015 Realm: "test zone",
1016 Key: key,
1017 Timeout: time.Hour,
1018 Authenticator: defaultAuthenticator,
1019 Unauthorized: func(c *gin.Context, code int, message string) {
1020 c.String(code, message)
1021 },
1022 TokenLookup: "param:token",
1023 })
1024
1025 handler := ginHandler(authMiddleware)
1026
1027 r := gofight.New()
1028
1029 userToken, _, _ := authMiddleware.generateAccessToken(jwt.MapClaims{
1030 "identity": testAdmin,
1031 })
1032
1033 r.GET("/auth/hello").
1034 SetHeader(gofight.H{
1035 "Authorization": "Bearer " + userToken,
1036 }).
1037 Run(handler, func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
1038 assert.Equal(t, http.StatusUnauthorized, r.Code)
1039 })
1040
1041 r.GET("/g/"+userToken+"/hello").
1042 Run(handler, func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
1043 assert.Equal(t, http.StatusOK, r.Code)
1044 })
1045}
1046
1047func TestTokenFromCookieString(t *testing.T) {
1048 // 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…