7d8e82c69f
Ship the Ops backstage 对象存储 page (browse / upload / move / delete / folder ops) backed by a new object-storage service + handler, with the shared storage client extended with List/Stat/Copy/Usage/DownloadURL so both MinIO and Aliyun providers cover the new surface. Add ForcePathStyle to the object-storage config and treat r2/s3/custom_s3 as external providers so Cloudflare R2 and other S3-compatibles can share the MinIO client path without spinning up the bundled MinIO. Also add CSV import/export + template download to the site-domain mappings page, raise gin MaxMultipartMemory to 8 MiB for the new multipart endpoints, register Ops swagger routes, and extend the descriptions-parity test to cover the ops router. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
50 lines
1.1 KiB
Go
50 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) {
|
|
t.Parallel()
|
|
|
|
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) {
|
|
t.Parallel()
|
|
|
|
gin.SetMode(gin.TestMode)
|
|
|
|
_, err := NewEngine(config.ServerConfig{
|
|
TrustedProxies: []string{"not-a-cidr"},
|
|
})
|
|
require.Error(t, err)
|
|
}
|