Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/artifacts/artifacts_v4.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (r *artifactV4Routes) parseProtbufBody(ctx *ArtifactContext, req protorefle
ctx.Error(http.StatusInternalServerError, "Error decode request body")
return false
}
err = protojson.Unmarshal(body, req)
err = protojson.UnmarshalOptions{DiscardUnknown: true}.Unmarshal(body, req)
if err != nil {
log.Errorf("Error decode request body: %v", err)
ctx.Error(http.StatusInternalServerError, "Error decode request body")
Expand Down
18 changes: 18 additions & 0 deletions pkg/artifacts/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,24 @@ func runTestJobFile(ctx context.Context, t *testing.T, tjfi TestJobFileInfo) {
})
}

func TestCreateArtifactV4UnknownField(t *testing.T) {
assert := assert.New(t)

var memfs = fstest.MapFS(map[string]*fstest.MapFile{})

router := httprouter.New()
RoutesV4(router, "artifact/server/path", writeMapFS{memfs}, memfs)

// Simulate upload-artifact@v7 sending an unknown field (mime_type)
body := `{"workflow_run_backend_id":"1","workflow_job_run_backend_id":"2","name":"test-artifact","version":4,"mime_type":"application/zip"}`
req, _ := http.NewRequest("POST", "http://localhost"+path.Join(ArtifactV4RouteBase, "CreateArtifact"), strings.NewReader(body))
rr := httptest.NewRecorder()

router.ServeHTTP(rr, req)

assert.Equal(http.StatusOK, rr.Code, "CreateArtifact should succeed even with unknown fields like mime_type")
}

func TestMkdirFsImplSafeResolve(t *testing.T) {
baseDir := "/foo/bar"

Expand Down