Skip to content

Commit

Permalink
fix: artifacts.(*ArtifactServer).GetInputArtifactByUID ensure valid r…
Browse files Browse the repository at this point in the history
…equest path (#7730)

Signed-off-by: Paco Guzmán <[email protected]>
  • Loading branch information
pacoguzman authored Feb 3, 2022
1 parent 8acaa33 commit 70715ec
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
7 changes: 5 additions & 2 deletions server/artifacts/artifact_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,11 @@ func (a *ArtifactServer) GetInputArtifactByUID(w http.ResponseWriter, r *http.Re
}

func (a *ArtifactServer) getArtifactByUID(w http.ResponseWriter, r *http.Request, isInput bool) {
requestPath := strings.SplitN(r.URL.Path, "/", 6)

requestPath := strings.SplitN(r.URL.Path, "/", 5)
if len(requestPath) != 5 {
a.serverInternalError(errors.New("request path is not valid"), w)
return
}
uid := requestPath[2]
nodeId := requestPath[3]
artifactName := requestPath[4]
Expand Down
17 changes: 17 additions & 0 deletions server/artifacts/artifact_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,20 @@ func TestArtifactServer_GetOutputArtifactByUID(t *testing.T) {
s.GetOutputArtifactByUID(w, r)
assert.Equal(t, 401, w.StatusCode)
}

func TestArtifactServer_GetArtifactByUIDInvalidRequestPath(t *testing.T) {
s := newServer()
r := &http.Request{}
// missing my-artifact part to have a valid URL
r.URL = mustParse("/input-artifacts/my-uuid/my-node")
w := &testhttp.TestResponseWriter{}
s.GetInputArtifactByUID(w, r)
// make sure there is no index out of bounds error
assert.Equal(t, 500, w.StatusCode)
assert.Equal(t, "request path is not valid", w.Output)

w = &testhttp.TestResponseWriter{}
s.GetOutputArtifactByUID(w, r)
assert.Equal(t, 500, w.StatusCode)
assert.Equal(t, "request path is not valid", w.Output)
}

0 comments on commit 70715ec

Please sign in to comment.