Commit 75a39b0b authored by Markus Koller's avatar Markus Koller Committed by Alessio Caiazza

Always set internally used upload fields

The `path` and `remote_*` fields are not always set in Workhorse
depending on the storage type, but still picked up in Rails.

To avoid injecting any client params with the same name, we just set
these fields to empty strings.
parent 3f55999a
......@@ -60,18 +60,10 @@ func (fh *FileHandler) GitLabFinalizeFields(prefix string) map[string]string {
return fmt.Sprintf("%s.%s", prefix, field)
}
if fh.Name != "" {
data[key("name")] = fh.Name
}
if fh.LocalPath != "" {
data[key("path")] = fh.LocalPath
}
if fh.RemoteURL != "" {
data[key("remote_url")] = fh.RemoteURL
}
if fh.RemoteID != "" {
data[key("remote_id")] = fh.RemoteID
}
data[key("name")] = fh.Name
data[key("path")] = fh.LocalPath
data[key("remote_url")] = fh.RemoteURL
data[key("remote_id")] = fh.RemoteID
data[key("size")] = strconv.FormatInt(fh.Size, 10)
for hashName, hash := range fh.hashes {
data[key(hashName)] = hash
......
......@@ -135,6 +135,14 @@ func TestUploadHandlerRewritingMultiPartData(t *testing.T) {
t.Error("Expected to the file to be in tempPath")
}
if r.FormValue("file.remote_url") != "" {
t.Error("Expected to receive empty remote_url")
}
if r.FormValue("file.remote_id") != "" {
t.Error("Expected to receive empty remote_id")
}
if r.FormValue("file.size") != "4" {
t.Error("Expected to receive the file size")
}
......@@ -152,8 +160,8 @@ func TestUploadHandlerRewritingMultiPartData(t *testing.T) {
}
}
if valueCnt := len(r.MultipartForm.Value); valueCnt != 8 {
t.Fatal("Expected to receive exactly 8 values but got", valueCnt)
if valueCnt := len(r.MultipartForm.Value); valueCnt != 10 {
t.Fatal("Expected to receive exactly 10 values but got", valueCnt)
}
w.WriteHeader(202)
......
......@@ -83,7 +83,7 @@ func uploadTestServer(t *testing.T, extraTests func(r *http.Request)) *httptest.
if err != nil {
t.Fatal(err)
}
nValues := 7 // file name, path, size, md5, sha1, sha256, sha512 for just the upload (no metadata because we are not POSTing a valid zip file)
nValues := 9 // file name, path, remote_url, remote_id, size, md5, sha1, sha256, sha512 for just the upload (no metadata because we are not POSTing a valid zip file)
if len(r.MultipartForm.Value) != nValues {
t.Errorf("Expected to receive exactly %d values", nValues)
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment