|
@@ -6189,26 +6189,32 @@ func TestAddWebFoldersMock(t *testing.T) {
|
|
|
form.Set("mapped_path", mappedPath)
|
|
|
form.Set("name", folderName)
|
|
|
form.Set("description", folderDesc)
|
|
|
- req, err := http.NewRequest(http.MethodPost, webFolderPath, strings.NewReader(form.Encode()))
|
|
|
+ b, contentType, err := getMultipartFormData(form, "", "")
|
|
|
assert.NoError(t, err)
|
|
|
+ req, err := http.NewRequest(http.MethodPost, webFolderPath, &b)
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
setJWTCookieForReq(req, webToken)
|
|
|
- req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
rr := executeRequest(req)
|
|
|
checkResponseCode(t, http.StatusForbidden, rr)
|
|
|
assert.Contains(t, rr.Body.String(), "unable to verify form token")
|
|
|
|
|
|
form.Set(csrfFormToken, csrfToken)
|
|
|
- req, err = http.NewRequest(http.MethodPost, webFolderPath, strings.NewReader(form.Encode()))
|
|
|
+ b, contentType, err = getMultipartFormData(form, "", "")
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req, err = http.NewRequest(http.MethodPost, webFolderPath, &b)
|
|
|
assert.NoError(t, err)
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
setJWTCookieForReq(req, webToken)
|
|
|
- req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
rr = executeRequest(req)
|
|
|
checkResponseCode(t, http.StatusSeeOther, rr)
|
|
|
// adding the same folder will fail since the name must be unique
|
|
|
- req, err = http.NewRequest(http.MethodPost, webFolderPath, strings.NewReader(form.Encode()))
|
|
|
+ b, contentType, err = getMultipartFormData(form, "", "")
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req, err = http.NewRequest(http.MethodPost, webFolderPath, &b)
|
|
|
assert.NoError(t, err)
|
|
|
setJWTCookieForReq(req, webToken)
|
|
|
- req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
rr = executeRequest(req)
|
|
|
checkResponseCode(t, http.StatusOK, rr)
|
|
|
// invalid form
|
|
@@ -6277,18 +6283,22 @@ func TestS3WebFolderMock(t *testing.T) {
|
|
|
form.Set("s3_upload_part_size", strconv.Itoa(S3UploadPartSize))
|
|
|
form.Set("s3_upload_concurrency", "a")
|
|
|
form.Set(csrfFormToken, csrfToken)
|
|
|
- req, err := http.NewRequest(http.MethodPost, webFolderPath, strings.NewReader(form.Encode()))
|
|
|
+ b, contentType, err := getMultipartFormData(form, "", "")
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req, err := http.NewRequest(http.MethodPost, webFolderPath, &b)
|
|
|
assert.NoError(t, err)
|
|
|
setJWTCookieForReq(req, webToken)
|
|
|
- req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
rr := executeRequest(req)
|
|
|
checkResponseCode(t, http.StatusOK, rr)
|
|
|
|
|
|
form.Set("s3_upload_concurrency", strconv.Itoa(S3UploadConcurrency))
|
|
|
- req, err = http.NewRequest(http.MethodPost, webFolderPath, strings.NewReader(form.Encode()))
|
|
|
+ b, contentType, err = getMultipartFormData(form, "", "")
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req, err = http.NewRequest(http.MethodPost, webFolderPath, &b)
|
|
|
assert.NoError(t, err)
|
|
|
setJWTCookieForReq(req, webToken)
|
|
|
- req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
rr = executeRequest(req)
|
|
|
checkResponseCode(t, http.StatusSeeOther, rr)
|
|
|
|
|
@@ -6315,18 +6325,22 @@ func TestS3WebFolderMock(t *testing.T) {
|
|
|
// update
|
|
|
S3UploadConcurrency = 10
|
|
|
form.Set("s3_upload_concurrency", "b")
|
|
|
- req, err = http.NewRequest(http.MethodPost, path.Join(webFolderPath, folderName), strings.NewReader(form.Encode()))
|
|
|
+ b, contentType, err = getMultipartFormData(form, "", "")
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req, err = http.NewRequest(http.MethodPost, path.Join(webFolderPath, folderName), &b)
|
|
|
assert.NoError(t, err)
|
|
|
setJWTCookieForReq(req, webToken)
|
|
|
- req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
rr = executeRequest(req)
|
|
|
checkResponseCode(t, http.StatusOK, rr)
|
|
|
|
|
|
form.Set("s3_upload_concurrency", strconv.Itoa(S3UploadConcurrency))
|
|
|
- req, err = http.NewRequest(http.MethodPost, path.Join(webFolderPath, folderName), strings.NewReader(form.Encode()))
|
|
|
+ b, contentType, err = getMultipartFormData(form, "", "")
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req, err = http.NewRequest(http.MethodPost, path.Join(webFolderPath, folderName), &b)
|
|
|
assert.NoError(t, err)
|
|
|
setJWTCookieForReq(req, webToken)
|
|
|
- req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
rr = executeRequest(req)
|
|
|
checkResponseCode(t, http.StatusSeeOther, rr)
|
|
|
|
|
@@ -6380,19 +6394,23 @@ func TestUpdateWebFolderMock(t *testing.T) {
|
|
|
form.Set("name", folderName)
|
|
|
form.Set("description", folderDesc)
|
|
|
form.Set(csrfFormToken, "")
|
|
|
- req, err := http.NewRequest(http.MethodPost, path.Join(webFolderPath, folderName), strings.NewReader(form.Encode()))
|
|
|
+ b, contentType, err := getMultipartFormData(form, "", "")
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req, err := http.NewRequest(http.MethodPost, path.Join(webFolderPath, folderName), &b)
|
|
|
assert.NoError(t, err)
|
|
|
setJWTCookieForReq(req, webToken)
|
|
|
- req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
rr := executeRequest(req)
|
|
|
checkResponseCode(t, http.StatusForbidden, rr)
|
|
|
assert.Contains(t, rr.Body.String(), "unable to verify form token")
|
|
|
|
|
|
form.Set(csrfFormToken, csrfToken)
|
|
|
- req, err = http.NewRequest(http.MethodPost, path.Join(webFolderPath, folderName), strings.NewReader(form.Encode()))
|
|
|
+ b, contentType, err = getMultipartFormData(form, "", "")
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req, err = http.NewRequest(http.MethodPost, path.Join(webFolderPath, folderName), &b)
|
|
|
assert.NoError(t, err)
|
|
|
setJWTCookieForReq(req, webToken)
|
|
|
- req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
rr = executeRequest(req)
|
|
|
checkResponseCode(t, http.StatusSeeOther, rr)
|
|
|
|
|
@@ -6407,26 +6425,32 @@ func TestUpdateWebFolderMock(t *testing.T) {
|
|
|
assert.Equal(t, folderDesc, folder.Description)
|
|
|
|
|
|
// parse form error
|
|
|
- req, err = http.NewRequest(http.MethodPost, path.Join(webFolderPath, folderName)+"??a=a%B3%A2%G3", strings.NewReader(form.Encode()))
|
|
|
+ b, contentType, err = getMultipartFormData(form, "", "")
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req, err = http.NewRequest(http.MethodPost, path.Join(webFolderPath, folderName)+"??a=a%B3%A2%G3", &b)
|
|
|
assert.NoError(t, err)
|
|
|
setJWTCookieForReq(req, webToken)
|
|
|
- req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
rr = executeRequest(req)
|
|
|
checkResponseCode(t, http.StatusOK, rr)
|
|
|
assert.Contains(t, rr.Body.String(), "invalid URL escape")
|
|
|
|
|
|
- req, err = http.NewRequest(http.MethodPost, path.Join(webFolderPath, folderName+"1"), strings.NewReader(form.Encode()))
|
|
|
+ b, contentType, err = getMultipartFormData(form, "", "")
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req, err = http.NewRequest(http.MethodPost, path.Join(webFolderPath, folderName+"1"), &b)
|
|
|
assert.NoError(t, err)
|
|
|
setJWTCookieForReq(req, webToken)
|
|
|
- req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
rr = executeRequest(req)
|
|
|
checkResponseCode(t, http.StatusNotFound, rr)
|
|
|
|
|
|
form.Set("mapped_path", "arelative/path")
|
|
|
- req, err = http.NewRequest(http.MethodPost, path.Join(webFolderPath, folderName), strings.NewReader(form.Encode()))
|
|
|
+ b, contentType, err = getMultipartFormData(form, "", "")
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req, err = http.NewRequest(http.MethodPost, path.Join(webFolderPath, folderName), &b)
|
|
|
assert.NoError(t, err)
|
|
|
setJWTCookieForReq(req, webToken)
|
|
|
- req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
rr = executeRequest(req)
|
|
|
checkResponseCode(t, http.StatusOK, rr)
|
|
|
|