| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- package admin
- import (
- "bytes"
- "encoding/json"
- "net/http"
- "net/http/httptest"
- "testing"
- "github.com/gin-gonic/gin"
- "github.com/stretchr/testify/require"
- )
- func TestAccountHandler_Create_AnthropicAPIKeyPassthroughExtraForwarded(t *testing.T) {
- gin.SetMode(gin.TestMode)
- adminSvc := newStubAdminService()
- handler := NewAccountHandler(
- adminSvc,
- nil,
- nil,
- nil,
- nil,
- nil,
- nil,
- nil,
- nil,
- nil,
- nil,
- nil,
- nil,
- nil,
- )
- router := gin.New()
- router.POST("/api/v1/admin/accounts", handler.Create)
- body := map[string]any{
- "name": "anthropic-key-1",
- "platform": "anthropic",
- "type": "apikey",
- "credentials": map[string]any{
- "api_key": "sk-ant-xxx",
- "base_url": "https://api.anthropic.com",
- },
- "extra": map[string]any{
- "anthropic_passthrough": true,
- },
- "concurrency": 1,
- "priority": 1,
- }
- raw, err := json.Marshal(body)
- require.NoError(t, err)
- rec := httptest.NewRecorder()
- req := httptest.NewRequest(http.MethodPost, "/api/v1/admin/accounts", bytes.NewReader(raw))
- req.Header.Set("Content-Type", "application/json")
- router.ServeHTTP(rec, req)
- require.Equal(t, http.StatusOK, rec.Code)
- require.Len(t, adminSvc.createdAccounts, 1)
- created := adminSvc.createdAccounts[0]
- require.Equal(t, "anthropic", created.Platform)
- require.Equal(t, "apikey", created.Type)
- require.NotNil(t, created.Extra)
- require.Equal(t, true, created.Extra["anthropic_passthrough"])
- }
|