storage: Use request.Form and avoid mux matching (#13858)

request.Form uses less memory allocation and avoids gorilla mux matching
with weird characters in parameters such as '\n'

- Remove Queries() to avoid matching
- Ensure r.ParseForm is called to populate fields
- Add a unit test for object names with '\n'
This commit is contained in:
Anis Elleuch
2021-12-09 17:38:46 +01:00
committed by GitHub
parent 239bbad7ab
commit 84c690cb07
3 changed files with 101 additions and 134 deletions

View File

@@ -23,6 +23,7 @@ import (
"net/http/httptest"
"os"
"reflect"
"runtime"
"testing"
"github.com/gorilla/mux"
@@ -312,18 +313,24 @@ func testStorageAPIAppendFile(t *testing.T, storage StorageAPI) {
}
testCases := []struct {
volumeName string
objectName string
data []byte
expectErr bool
volumeName string
objectName string
data []byte
expectErr bool
ignoreIfWindows bool
}{
{"foo", "myobject", []byte("foo"), false},
{"foo", "myobject", []byte{}, false},
{"foo", "myobject", []byte("foo"), false, false},
{"foo", "myobject", []byte{}, false, false},
// volume not found error.
{"bar", "myobject", []byte{}, true},
{"bar", "myobject", []byte{}, true, false},
// Weird '\n' in object name
{"foo", "newline\n", []byte{}, false, true},
}
for i, testCase := range testCases {
if testCase.ignoreIfWindows && runtime.GOOS == "windows" {
continue
}
err := storage.AppendFile(context.Background(), testCase.volumeName, testCase.objectName, testCase.data)
expectErr := (err != nil)