@@ -398,12 +398,56 @@ func TestActionsArtifactV4DownloadSinglePublicApi(t *testing.T) {
398398
399399 resp = MakeRequest (t , req , http .StatusFound )
400400
401- // confirm artifact can be downloaded and has expected content
402- req = NewRequestWithBody (t , "GET" , resp .Header ().Get ("Location" ), nil ).
401+ blobLocation := resp .Header ().Get ("Location" )
402+
403+ // confirm artifact can be downloaded without token and has expected content
404+ req = NewRequestWithBody (t , "GET" , blobLocation , nil )
405+ resp = MakeRequest (t , req , http .StatusOK )
406+ body := strings .Repeat ("D" , 1024 )
407+ assert .Equal (t , body , resp .Body .String ())
408+
409+ // confirm artifact can not be downloaded without query
410+ req = NewRequestWithBody (t , "GET" , blobLocation , nil )
411+ req .URL .RawQuery = ""
412+ _ = MakeRequest (t , req , http .StatusUnauthorized )
413+ }
414+
415+ func TestActionsArtifactV4DownloadSinglePublicApiPrivateRepo (t * testing.T ) {
416+ defer prepareTestEnvActionsArtifacts (t )()
417+
418+ repo := unittest .AssertExistsAndLoadBean (t , & repo_model.Repository {ID : 2 })
419+ user := unittest .AssertExistsAndLoadBean (t , & user_model.User {ID : repo .OwnerID })
420+ session := loginUser (t , user .Name )
421+ token := getTokenForLoggedInUser (t , session , auth_model .AccessTokenScopeWriteRepository )
422+
423+ // confirm artifact can be listed and found by name
424+ req := NewRequestWithBody (t , "GET" , fmt .Sprintf ("/api/v1/repos/%s/actions/artifacts?name=artifact-v4-download" , repo .FullName ()), nil ).
425+ AddTokenAuth (token )
426+ resp := MakeRequest (t , req , http .StatusOK )
427+ var listResp api.ActionArtifactsResponse
428+ err := json .Unmarshal (resp .Body .Bytes (), & listResp )
429+ assert .NoError (t , err )
430+ assert .Equal (t , int64 (23 ), listResp .Entries [0 ].ID )
431+ assert .NotEmpty (t , listResp .Entries [0 ].ArchiveDownloadURL )
432+ assert .Equal (t , "artifact-v4-download" , listResp .Entries [0 ].Name )
433+
434+ // confirm artifact blob storage url can be retrieved
435+ req = NewRequestWithBody (t , "GET" , listResp .Entries [0 ].ArchiveDownloadURL , nil ).
403436 AddTokenAuth (token )
437+
438+ resp = MakeRequest (t , req , http .StatusFound )
439+
440+ blobLocation := resp .Header ().Get ("Location" )
441+ // confirm artifact can be downloaded without token and has expected content
442+ req = NewRequestWithBody (t , "GET" , blobLocation , nil )
404443 resp = MakeRequest (t , req , http .StatusOK )
405444 body := strings .Repeat ("D" , 1024 )
406445 assert .Equal (t , body , resp .Body .String ())
446+
447+ // confirm artifact can not be downloaded without query
448+ req = NewRequestWithBody (t , "GET" , blobLocation , nil )
449+ req .URL .RawQuery = ""
450+ _ = MakeRequest (t , req , http .StatusUnauthorized )
407451}
408452
409453func TestActionsArtifactV4ListAndGetPublicApi (t * testing.T ) {
@@ -483,7 +527,7 @@ func TestActionsArtifactV4DownloadArtifactCorrectRepoOwnerFound(t *testing.T) {
483527 MakeRequest (t , req , http .StatusFound )
484528}
485529
486- func TestActionsArtifactV4DownloadRawArtifactMismatchedRepoOwnerNotFound (t * testing.T ) {
530+ func TestActionsArtifactV4DownloadRawArtifactMismatchedRepoOwnerMissingSignatureUnauthorized (t * testing.T ) {
487531 defer prepareTestEnvActionsArtifacts (t )()
488532
489533 repo := unittest .AssertExistsAndLoadBean (t , & repo_model.Repository {ID : 1 })
@@ -494,7 +538,21 @@ func TestActionsArtifactV4DownloadRawArtifactMismatchedRepoOwnerNotFound(t *test
494538 // confirm artifacts of wrong owner or repo is not visible
495539 req := NewRequestWithBody (t , "GET" , fmt .Sprintf ("/api/v1/repos/%s/actions/artifacts/%d/zip/raw" , repo .FullName (), 22 ), nil ).
496540 AddTokenAuth (token )
497- MakeRequest (t , req , http .StatusNotFound )
541+ MakeRequest (t , req , http .StatusUnauthorized )
542+ }
543+
544+ func TestActionsArtifactV4DownloadRawArtifactCorrectRepoOwnerMissingSignatureUnauthorized (t * testing.T ) {
545+ defer prepareTestEnvActionsArtifacts (t )()
546+
547+ repo := unittest .AssertExistsAndLoadBean (t , & repo_model.Repository {ID : 4 })
548+ user := unittest .AssertExistsAndLoadBean (t , & user_model.User {ID : repo .OwnerID })
549+ session := loginUser (t , user .Name )
550+ token := getTokenForLoggedInUser (t , session , auth_model .AccessTokenScopeWriteRepository )
551+
552+ // confirm artifacts of wrong owner or repo is not visible
553+ req := NewRequestWithBody (t , "GET" , fmt .Sprintf ("/api/v1/repos/%s/actions/artifacts/%d/zip/raw" , repo .FullName (), 22 ), nil ).
554+ AddTokenAuth (token )
555+ MakeRequest (t , req , http .StatusUnauthorized )
498556}
499557
500558func TestActionsArtifactV4Delete (t * testing.T ) {
0 commit comments