(t *testing.T)
| 1010 | } |
| 1011 | |
| 1012 | func 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 | |
| 1047 | func TestTokenFromCookieString(t *testing.T) { |
| 1048 | // the middleware to test |
nothing calls this directly
no test coverage detected
searching dependent graphs…