@@ -235,6 +235,71 @@ func TestActionsArtifactV4UploadSingleFileWithPotentialHarmfulBlockID(t *testing
235235 assert .True (t , finalizeResp .Ok )
236236}
237237
238+ func TestActionsArtifactV4UploadSingleFileWithChunksOutOfOrder (t * testing.T ) {
239+ defer tests .PrepareTestEnv (t )()
240+
241+ token , err := actions_service .CreateAuthorizationToken (48 , 792 , 193 )
242+ assert .NoError (t , err )
243+
244+ // acquire artifact upload url
245+ req := NewRequestWithBody (t , "POST" , "/twirp/github.actions.results.api.v1.ArtifactService/CreateArtifact" , toProtoJSON (& actions.CreateArtifactRequest {
246+ Version : 4 ,
247+ Name : "artifactWithChunksOutOfOrder" ,
248+ WorkflowRunBackendId : "792" ,
249+ WorkflowJobRunBackendId : "193" ,
250+ })).AddTokenAuth (token )
251+ resp := MakeRequest (t , req , http .StatusOK )
252+ var uploadResp actions.CreateArtifactResponse
253+ protojson .Unmarshal (resp .Body .Bytes (), & uploadResp )
254+ assert .True (t , uploadResp .Ok )
255+ assert .Contains (t , uploadResp .SignedUploadUrl , "/twirp/github.actions.results.api.v1.ArtifactService/UploadArtifact" )
256+
257+ // get upload urls
258+ idx := strings .Index (uploadResp .SignedUploadUrl , "/twirp/" )
259+ block1Url := uploadResp .SignedUploadUrl [idx :] + "&comp=block&blockid=block1"
260+ block2Url := uploadResp .SignedUploadUrl [idx :] + "&comp=block&blockid=block2"
261+ blockListUrl := uploadResp .SignedUploadUrl [idx :] + "&comp=blocklist"
262+
263+ // upload artifact chunks
264+ bodyb := strings .Repeat ("B" , 1024 )
265+ req = NewRequestWithBody (t , "PUT" , block2Url , strings .NewReader (bodyb ))
266+ MakeRequest (t , req , http .StatusCreated )
267+
268+ bodya := strings .Repeat ("A" , 1024 )
269+ req = NewRequestWithBody (t , "PUT" , block1Url , strings .NewReader (bodya ))
270+ MakeRequest (t , req , http .StatusCreated )
271+
272+ // upload artifact blockList
273+ blockList := & actions.BlockList {
274+ Latest : []string {
275+ "block1" ,
276+ "block2" ,
277+ },
278+ }
279+ rawBlockList , err := xml .Marshal (blockList )
280+ assert .NoError (t , err )
281+ req = NewRequestWithBody (t , "PUT" , blockListUrl , bytes .NewReader (rawBlockList ))
282+ MakeRequest (t , req , http .StatusCreated )
283+
284+ t .Logf ("Create artifact confirm" )
285+
286+ sha := sha256 .Sum256 ([]byte (bodya + bodyb ))
287+
288+ // confirm artifact upload
289+ req = NewRequestWithBody (t , "POST" , "/twirp/github.actions.results.api.v1.ArtifactService/FinalizeArtifact" , toProtoJSON (& actions.FinalizeArtifactRequest {
290+ Name : "artifactWithChunksOutOfOrder" ,
291+ Size : 2048 ,
292+ Hash : wrapperspb .String ("sha256:" + hex .EncodeToString (sha [:])),
293+ WorkflowRunBackendId : "792" ,
294+ WorkflowJobRunBackendId : "193" ,
295+ })).
296+ AddTokenAuth (token )
297+ resp = MakeRequest (t , req , http .StatusOK )
298+ var finalizeResp actions.FinalizeArtifactResponse
299+ protojson .Unmarshal (resp .Body .Bytes (), & finalizeResp )
300+ assert .True (t , finalizeResp .Ok )
301+ }
302+
238303func TestActionsArtifactV4DownloadSingle (t * testing.T ) {
239304 defer tests .PrepareTestEnv (t )()
240305
0 commit comments