mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-09-17 12:00:44 +02:00
* s3: drain request body before error response * s3: keep oversized request bodies drainable
25 lines
530 B
Go
25 lines
530 B
Go
package s3api
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestReadRequestBodyLeavesOversizedBodyDrainable(t *testing.T) {
|
|
req := httptest.NewRequest(http.MethodPost, "/", nil)
|
|
req.Body = io.NopCloser(strings.NewReader("abcdef"))
|
|
|
|
body, err := readRequestBody(req, 3)
|
|
remaining, readErr := io.ReadAll(req.Body)
|
|
|
|
assert.ErrorIs(t, err, errRequestBodyTooLarge)
|
|
assert.Nil(t, body)
|
|
assert.NoError(t, readErr)
|
|
assert.Equal(t, "ef", string(remaining))
|
|
}
|