- 前端: 所有界面显示、i18n 文本、组件中的品牌名称 - 后端: 服务层、设置默认值、邮件模板、安装向导 - 数据库: 迁移脚本注释 - 保持功能完全一致,仅更改品牌名称 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package handler
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/Wei-Shaw/sub2api/internal/server/middleware"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestRequestBodyLimitTooLarge(t *testing.T) {
|
|
gin.SetMode(gin.TestMode)
|
|
|
|
limit := int64(16)
|
|
router := gin.New()
|
|
router.Use(middleware.RequestBodyLimit(limit))
|
|
router.POST("/test", func(c *gin.Context) {
|
|
_, err := io.ReadAll(c.Request.Body)
|
|
if err != nil {
|
|
if maxErr, ok := extractMaxBytesError(err); ok {
|
|
c.JSON(http.StatusRequestEntityTooLarge, gin.H{
|
|
"error": buildBodyTooLargeMessage(maxErr.Limit),
|
|
})
|
|
return
|
|
}
|
|
c.JSON(http.StatusBadRequest, gin.H{
|
|
"error": "read_failed",
|
|
})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"ok": true})
|
|
})
|
|
|
|
payload := bytes.Repeat([]byte("a"), int(limit+1))
|
|
req := httptest.NewRequest(http.MethodPost, "/test", bytes.NewReader(payload))
|
|
recorder := httptest.NewRecorder()
|
|
router.ServeHTTP(recorder, req)
|
|
|
|
require.Equal(t, http.StatusRequestEntityTooLarge, recorder.Code)
|
|
require.Contains(t, recorder.Body.String(), buildBodyTooLargeMessage(limit))
|
|
}
|