Files
geo/server/internal/shared/bootstrap/http_test.go
T
root 347cea1296 feat(llm): add configurable request/token rate limiting for LLM client
Introduce process-local and Redis-backed global rate limiting for the
shared LLM client, plus a dedicated generation consumer prefetch knob.

- Add request (RPM) and token (TPM) rate limits with burst controls,
  process or global scope, and fail-closed/process-degraded failover
- Wire the LLM client through NewWithRedis so limits can be shared
  across replicas via a Redis token bucket
- Add generation_consumer_prefetch to tune RabbitMQ generation
  consumers independently of the default prefetch
- Bump generation worker_concurrency to 24 and promote golang.org/x/time
  to a direct dependency
- Drop t.Parallel() from a few middleware/bootstrap tests

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-10 00:14:40 +08:00

46 lines
1.1 KiB
Go

package bootstrap
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/require"
"github.com/geo-platform/tenant-api/internal/shared/config"
)
func TestNewEngineUsesForwardedClientIPFromTrustedProxy(t *testing.T) {
gin.SetMode(gin.TestMode)
engine, err := NewEngine(config.ServerConfig{
TrustedProxies: []string{"10.42.0.0/16"},
})
require.NoError(t, err)
require.Equal(t, int64(MaxMultipartMemory), engine.MaxMultipartMemory)
engine.GET("/ip", func(c *gin.Context) {
c.String(http.StatusOK, c.ClientIP())
})
req := httptest.NewRequest(http.MethodGet, "/ip", nil)
req.RemoteAddr = "10.42.0.128:51234"
req.Header.Set("X-Forwarded-For", "106.14.89.27")
resp := httptest.NewRecorder()
engine.ServeHTTP(resp, req)
require.Equal(t, http.StatusOK, resp.Code)
require.Equal(t, "106.14.89.27", resp.Body.String())
}
func TestNewEngineRejectsInvalidTrustedProxy(t *testing.T) {
gin.SetMode(gin.TestMode)
_, err := NewEngine(config.ServerConfig{
TrustedProxies: []string{"not-a-cidr"},
})
require.Error(t, err)
}