summaryrefslogtreecommitdiff
path: root/workhorse/internal/upload/uploads_test.go
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-10-28 18:14:18 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-10-28 18:14:18 +0000
commitb267f3a3acf3fe4cf2a9bb254d7abeb3b2823b21 (patch)
treea1c30c9a460a1c990311d47aae72d00368e1a1c1 /workhorse/internal/upload/uploads_test.go
parent03cd4f8da4f848c7dfd0c0b88b4c095f69e56bb0 (diff)
downloadgitlab-ce-b267f3a3acf3fe4cf2a9bb254d7abeb3b2823b21.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'workhorse/internal/upload/uploads_test.go')
-rw-r--r--workhorse/internal/upload/uploads_test.go43
1 files changed, 33 insertions, 10 deletions
diff --git a/workhorse/internal/upload/uploads_test.go b/workhorse/internal/upload/uploads_test.go
index 29acf849e05..e82dcdcbc69 100644
--- a/workhorse/internal/upload/uploads_test.go
+++ b/workhorse/internal/upload/uploads_test.go
@@ -18,7 +18,6 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitlab/workhorse/internal/api"
- "gitlab.com/gitlab-org/gitlab/workhorse/internal/filestore"
"gitlab.com/gitlab-org/gitlab/workhorse/internal/helper"
"gitlab.com/gitlab-org/gitlab/workhorse/internal/objectstore/test"
"gitlab.com/gitlab-org/gitlab/workhorse/internal/proxy"
@@ -28,11 +27,7 @@ import (
var nilHandler = http.HandlerFunc(func(http.ResponseWriter, *http.Request) {})
-type testFormProcessor struct{}
-
-func (a *testFormProcessor) ProcessFile(ctx context.Context, formName string, file *filestore.FileHandler, writer *multipart.Writer) error {
- return nil
-}
+type testFormProcessor struct{ SavedFileTracker }
func (a *testFormProcessor) ProcessField(ctx context.Context, formName string, writer *multipart.Writer) error {
if formName != "token" && !strings.HasPrefix(formName, "file.") && !strings.HasPrefix(formName, "other.") {
@@ -45,10 +40,6 @@ func (a *testFormProcessor) Finalize(ctx context.Context) error {
return nil
}
-func (a *testFormProcessor) Name() string {
- return ""
-}
-
func TestUploadTempPathRequirement(t *testing.T) {
apiResponse := &api.Response{}
preparer := &DefaultPreparer{}
@@ -259,6 +250,38 @@ func TestUploadProcessingField(t *testing.T) {
require.Equal(t, 500, response.Code)
}
+func TestUploadingMultipleFiles(t *testing.T) {
+ testhelper.ConfigureSecret()
+
+ tempPath, err := ioutil.TempDir("", "uploads")
+ require.NoError(t, err)
+ defer os.RemoveAll(tempPath)
+
+ var buffer bytes.Buffer
+
+ writer := multipart.NewWriter(&buffer)
+ _, err = writer.CreateFormFile("file", "my.file")
+ require.NoError(t, err)
+ _, err = writer.CreateFormFile("file", "my.file")
+ require.NoError(t, err)
+ require.NoError(t, writer.Close())
+
+ httpRequest, err := http.NewRequest("PUT", "/url/path", &buffer)
+ require.NoError(t, err)
+ httpRequest.Header.Set("Content-Type", writer.FormDataContentType())
+
+ response := httptest.NewRecorder()
+ apiResponse := &api.Response{TempPath: tempPath}
+ preparer := &DefaultPreparer{}
+ opts, _, err := preparer.Prepare(apiResponse)
+ require.NoError(t, err)
+
+ HandleFileUploads(response, httpRequest, nilHandler, apiResponse, &testFormProcessor{}, opts)
+
+ require.Equal(t, 400, response.Code)
+ require.Equal(t, "Uploading multiple files is not allowed\n", response.Body.String())
+}
+
func TestUploadProcessingFile(t *testing.T) {
tempPath, err := ioutil.TempDir("", "uploads")
require.NoError(t, err)