MCPcopy
hub / github.com/QuantumNous/new-api / TestUpdateTokenMasksKeyInResponse

Function TestUpdateTokenMasksKeyInResponse

controller/token_test.go:472–506  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

470}
471
472func 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
508func TestGetTokenKeyRequiresOwnershipAndReturnsFullKey(t *testing.T) {
509 db := setupTokenControllerTestDB(t)

Callers

nothing calls this directly

Calls 9

UnmarshalFunction · 0.92
newAuthenticatedContextFunction · 0.85
UpdateTokenFunction · 0.85
decodeAPIResponseFunction · 0.85
GetMaskedKeyMethod · 0.80
ContainsMethod · 0.80
seedTokenFunction · 0.70
StringMethod · 0.45

Tested by

no test coverage detected