(t *testing.T)
| 470 | } |
| 471 | |
| 472 | func TestUpdateTokenMasksKeyInResponse(t *testing.T) { |
| 473 | db := setupTokenControllerTestDB(t) |
| 474 | token := seedToken(t, db, 1, "editable-token", "yzab1234cdef5678") |
| 475 | |
| 476 | body := map[string]any{ |
| 477 | "id": token.Id, |
| 478 | "name": "updated-token", |
| 479 | "expired_time": -1, |
| 480 | "remain_quota": 100, |
| 481 | "unlimited_quota": true, |
| 482 | "model_limits_enabled": false, |
| 483 | "model_limits": "", |
| 484 | "group": "default", |
| 485 | "cross_group_retry": false, |
| 486 | } |
| 487 | |
| 488 | ctx, recorder := newAuthenticatedContext(t, http.MethodPut, "/api/token/", body, 1) |
| 489 | UpdateToken(ctx) |
| 490 | |
| 491 | response := decodeAPIResponse(t, recorder) |
| 492 | if !response.Success { |
| 493 | t.Fatalf("expected success response, got message: %s", response.Message) |
| 494 | } |
| 495 | |
| 496 | var detail tokenResponseItem |
| 497 | if err := common.Unmarshal(response.Data, &detail); err != nil { |
| 498 | t.Fatalf("failed to decode token update response: %v", err) |
| 499 | } |
| 500 | if detail.Key != token.GetMaskedKey() { |
| 501 | t.Fatalf("expected masked update key %q, got %q", token.GetMaskedKey(), detail.Key) |
| 502 | } |
| 503 | if strings.Contains(recorder.Body.String(), token.Key) { |
| 504 | t.Fatalf("update response leaked raw token key: %s", recorder.Body.String()) |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | func TestGetTokenKeyRequiresOwnershipAndReturnsFullKey(t *testing.T) { |
| 509 | db := setupTokenControllerTestDB(t) |
nothing calls this directly
no test coverage detected