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

Function TestGetTokenMasksKeyInResponse

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

Source from the content-addressed store, hash-verified

445}
446
447func TestGetTokenMasksKeyInResponse(t *testing.T) {
448 db := setupTokenControllerTestDB(t)
449 token := seedToken(t, db, 1, "detail-token", "qrst1234uvwx5678")
450
451 ctx, recorder := newAuthenticatedContext(t, http.MethodGet, "/api/token/"+strconv.Itoa(token.Id), nil, 1)
452 ctx.Params = gin.Params{{Key: "id", Value: strconv.Itoa(token.Id)}}
453 GetToken(ctx)
454
455 response := decodeAPIResponse(t, recorder)
456 if !response.Success {
457 t.Fatalf("expected success response, got message: %s", response.Message)
458 }
459
460 var detail tokenResponseItem
461 if err := common.Unmarshal(response.Data, &detail); err != nil {
462 t.Fatalf("failed to decode token detail response: %v", err)
463 }
464 if detail.Key != token.GetMaskedKey() {
465 t.Fatalf("expected masked detail key %q, got %q", token.GetMaskedKey(), detail.Key)
466 }
467 if strings.Contains(recorder.Body.String(), token.Key) {
468 t.Fatalf("detail response leaked raw token key: %s", recorder.Body.String())
469 }
470}
471
472func TestUpdateTokenMasksKeyInResponse(t *testing.T) {
473 db := setupTokenControllerTestDB(t)

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected