api_key_auth_cache_version_test.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package service
  2. import "testing"
  3. func TestAPIKeyService_RejectsV10AuthSnapshotWithoutModelAllowlist(t *testing.T) {
  4. groupID := int64(9)
  5. svc := &APIKeyService{}
  6. apiKey, ok, err := svc.applyAuthCacheEntry("k-legacy-models-list", &APIKeyAuthCacheEntry{
  7. Snapshot: &APIKeyAuthSnapshot{
  8. Version: 10,
  9. APIKeyID: 1,
  10. UserID: 2,
  11. GroupID: &groupID,
  12. Status: StatusActive,
  13. User: APIKeyAuthUserSnapshot{
  14. ID: 2,
  15. Status: StatusActive,
  16. Role: RoleUser,
  17. Balance: 10,
  18. Concurrency: 3,
  19. },
  20. Group: &APIKeyAuthGroupSnapshot{
  21. ID: groupID,
  22. Name: "openai",
  23. Platform: PlatformOpenAI,
  24. Status: StatusActive,
  25. SubscriptionType: SubscriptionTypeStandard,
  26. RateMultiplier: 1,
  27. },
  28. },
  29. })
  30. if err != nil {
  31. t.Fatalf("expected stale snapshot to be ignored without error, got %v", err)
  32. }
  33. if ok {
  34. t.Fatalf("expected v10 auth snapshot to be rejected after model_allowlist was added")
  35. }
  36. if apiKey != nil {
  37. t.Fatalf("expected no API key from stale snapshot, got %#v", apiKey)
  38. }
  39. }
  40. func TestAPIKeyService_RejectsV15AuthSnapshotWithoutReasoningEffortPolicy(t *testing.T) {
  41. svc := &APIKeyService{}
  42. apiKey, ok, err := svc.applyAuthCacheEntry("k-legacy-reasoning-mappings", &APIKeyAuthCacheEntry{
  43. Snapshot: &APIKeyAuthSnapshot{Version: 15},
  44. })
  45. if err != nil {
  46. t.Fatalf("expected stale snapshot to be ignored without error, got %v", err)
  47. }
  48. if ok {
  49. t.Fatal("expected v15 auth snapshot to be rejected after reasoning effort policy was added")
  50. }
  51. if apiKey != nil {
  52. t.Fatalf("expected no API key from stale snapshot, got %#v", apiKey)
  53. }
  54. }