(t *testing.T)
| 1252 | } |
| 1253 | |
| 1254 | func TestExpiredField(t *testing.T) { |
| 1255 | // the middleware to test |
| 1256 | authMiddleware, _ := New(&GinJWTMiddleware{ |
| 1257 | Realm: "test zone", |
| 1258 | Key: key, |
| 1259 | Timeout: time.Hour, |
| 1260 | Authenticator: defaultAuthenticator, |
| 1261 | }) |
| 1262 | |
| 1263 | handler := ginHandler(authMiddleware) |
| 1264 | |
| 1265 | r := gofight.New() |
| 1266 | |
| 1267 | token := jwt.New(jwt.GetSigningMethod("HS256")) |
| 1268 | claims := token.Claims.(jwt.MapClaims) |
| 1269 | claims["identity"] = testAdmin |
| 1270 | claims["orig_iat"] = 0 |
| 1271 | tokenString, _ := token.SignedString(key) |
| 1272 | |
| 1273 | r.GET("/auth/hello"). |
| 1274 | SetHeader(gofight.H{ |
| 1275 | "Authorization": "Bearer " + tokenString, |
| 1276 | }). |
| 1277 | Run(handler, func(r gofight.HTTPResponse, rq gofight.HTTPRequest) { |
| 1278 | message := gjson.Get(r.Body.String(), "message") |
| 1279 | |
| 1280 | assert.Equal(t, ErrMissingExpField.Error(), message.String()) |
| 1281 | assert.Equal(t, http.StatusBadRequest, r.Code) |
| 1282 | }) |
| 1283 | |
| 1284 | // wrong format |
| 1285 | claims["exp"] = "wrongFormatForExpiry" |
| 1286 | tokenString, _ = token.SignedString(key) |
| 1287 | |
| 1288 | r.GET("/auth/hello"). |
| 1289 | SetHeader(gofight.H{ |
| 1290 | "Authorization": "Bearer " + tokenString, |
| 1291 | }). |
| 1292 | Run(handler, func(r gofight.HTTPResponse, rq gofight.HTTPRequest) { |
| 1293 | message := gjson.Get(r.Body.String(), "message") |
| 1294 | |
| 1295 | assert.Equal(t, ErrWrongFormatOfExp.Error(), strings.ToLower(message.String())) |
| 1296 | assert.Equal(t, http.StatusBadRequest, r.Code) |
| 1297 | }) |
| 1298 | } |
| 1299 | |
| 1300 | func TestExpiredFieldRequiredParserOption(t *testing.T) { |
| 1301 | // the middleware to test |
nothing calls this directly
no test coverage detected
searching dependent graphs…