Skip to content

Commit

Permalink
cmd/submit_test.go: Update test server to use unmodified filename (#1115
Browse files Browse the repository at this point in the history
)

Following RFC 7578, Go 1.17+ strips the directory information in fileHeader.Filename.
This change updates the test server to use Header["Content-Disposition"] for obtaining the unmodified filename
for validating the submitted files directory tree in the request.

This work builds on the PR opened by @QuLogic #1066

Co-authored-by: Erik Schierboom <erik_schierboom@hotmail.com>
  • Loading branch information
nywilken and ErikSchierboom authored Sep 22, 2023
1 parent c763ea5 commit 8f2c7ca
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cmd/submit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"mime"
"net/http"
"net/http/httptest"
"os"
Expand Down Expand Up @@ -561,7 +562,16 @@ func fakeSubmitServer(t *testing.T, submittedFiles map[string]string) *httptest.
if err != nil {
t.Fatal(err)
}
submittedFiles[fileHeader.Filename] = string(body)
// Following RFC 7578, Go 1.17+ strips the directory information in fileHeader.Filename.
// Validating the submitted files directory tree is important so Content-Disposition is used for
// obtaining the unmodified filename.
v := fileHeader.Header.Get("Content-Disposition")
_, dispositionParams, err := mime.ParseMediaType(v)
if err != nil {
t.Fatalf("failed to obtain submitted filename from multipart header: %s", err.Error())
}
filename := dispositionParams["filename"]
submittedFiles[filename] = string(body)
}

fmt.Fprint(w, "{}")
Expand Down

0 comments on commit 8f2c7ca

Please sign in to comment.