(t *testing.T, r *gin.Engine)
| 412 | } |
| 413 | |
| 414 | func testTokenPersistenceAcrossRequests(t *testing.T, r *gin.Engine) { |
| 415 | // Login and get refresh token |
| 416 | w := httptest.NewRecorder() |
| 417 | req, _ := http.NewRequestWithContext( |
| 418 | context.Background(), |
| 419 | "POST", |
| 420 | "/login", |
| 421 | strings.NewReader(`{"username":"`+testAdmin+`","password":"`+testAdmin+`"}`), |
| 422 | ) |
| 423 | req.Header.Set("Content-Type", "application/json") |
| 424 | r.ServeHTTP(w, req) |
| 425 | |
| 426 | var loginResp map[string]any |
| 427 | err := parseJSON(w.Body.String(), &loginResp) |
| 428 | require.NoError(t, err) |
| 429 | |
| 430 | refreshToken := loginResp["refresh_token"].(string) |
| 431 | |
| 432 | // Simulate some time passing and multiple refresh requests |
| 433 | for i := 0; i < 3; i++ { |
| 434 | time.Sleep(10 * time.Millisecond) // Small delay to simulate real usage |
| 435 | |
| 436 | w = httptest.NewRecorder() |
| 437 | req, _ = http.NewRequestWithContext( |
| 438 | context.Background(), |
| 439 | "POST", |
| 440 | "/refresh", |
| 441 | strings.NewReader(fmt.Sprintf(`{"refresh_token":"%s"}`, refreshToken)), |
| 442 | ) |
| 443 | req.Header.Set("Content-Type", "application/json") |
| 444 | r.ServeHTTP(w, req) |
| 445 | |
| 446 | assert.Equal(t, 200, w.Code, fmt.Sprintf("refresh %d should succeed", i+1)) |
| 447 | |
| 448 | // Update refresh token for next iteration |
| 449 | var refreshResp map[string]any |
| 450 | err := parseJSON(w.Body.String(), &refreshResp) |
| 451 | require.NoError(t, err, fmt.Sprintf("should parse refresh response %d", i+1)) |
| 452 | refreshToken = refreshResp["refresh_token"].(string) |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | func testRedisStoreOperations(t *testing.T, middleware *GinJWTMiddleware) { |
| 457 | // Verify that Redis store is being used |
no test coverage detected
searching dependent graphs…