@@ -7,14 +7,21 @@ import (
77 "bytes"
88 "crypto/sha256"
99 "encoding/hex"
10+ "encoding/json"
1011 "encoding/xml"
12+ "fmt"
1113 "io"
1214 "net/http"
1315 "strings"
1416 "testing"
1517 "time"
1618
19+ auth_model "code.gitea.io/gitea/models/auth"
20+ repo_model "code.gitea.io/gitea/models/repo"
21+ "code.gitea.io/gitea/models/unittest"
22+ user_model "code.gitea.io/gitea/models/user"
1723 "code.gitea.io/gitea/modules/storage"
24+ api "code.gitea.io/gitea/modules/structs"
1825 "code.gitea.io/gitea/routers/api/actions"
1926 actions_service "code.gitea.io/gitea/services/actions"
2027
@@ -334,6 +341,93 @@ func TestActionsArtifactV4DownloadSingle(t *testing.T) {
334341 assert .Equal (t , body , resp .Body .String ())
335342}
336343
344+ func TestActionsArtifactV4RunDownloadSinglePublicApi (t * testing.T ) {
345+ defer prepareTestEnvActionsArtifacts (t )()
346+
347+ repo := unittest .AssertExistsAndLoadBean (t , & repo_model.Repository {ID : 4 })
348+ user := unittest .AssertExistsAndLoadBean (t , & user_model.User {ID : repo .OwnerID })
349+ session := loginUser (t , user .Name )
350+ token := getTokenForLoggedInUser (t , session , auth_model .AccessTokenScopeWriteRepository )
351+
352+ // confirm artifact upload via rest api
353+ req := NewRequestWithBody (t , "GET" , fmt .Sprintf ("/api/v1/repos/%s/actions/run/792/artifacts?name=artifact-v4-download" , repo .FullName ()), nil ).
354+ AddTokenAuth (token )
355+ resp := MakeRequest (t , req , http .StatusOK )
356+ var listResp api.ActionArtifactsResponse
357+ err := json .Unmarshal (resp .Body .Bytes (), & listResp )
358+ assert .NoError (t , err )
359+ assert .NotEmpty (t , listResp .Entries [0 ].ArchiveDownloadURL )
360+ assert .Equal (t , "artifact-v4-download" , listResp .Entries [0 ].Name )
361+
362+ req = NewRequestWithBody (t , "GET" , listResp .Entries [0 ].ArchiveDownloadURL , nil ).
363+ AddTokenAuth (token )
364+
365+ resp = MakeRequest (t , req , http .StatusOK )
366+ body := strings .Repeat ("D" , 1024 )
367+ assert .Equal (t , body , resp .Body .String ())
368+ }
369+
370+ func TestActionsArtifactV4DownloadSinglePublicApi (t * testing.T ) {
371+ defer prepareTestEnvActionsArtifacts (t )()
372+
373+ repo := unittest .AssertExistsAndLoadBean (t , & repo_model.Repository {ID : 4 })
374+ user := unittest .AssertExistsAndLoadBean (t , & user_model.User {ID : repo .OwnerID })
375+ session := loginUser (t , user .Name )
376+ token := getTokenForLoggedInUser (t , session , auth_model .AccessTokenScopeWriteRepository )
377+
378+ // confirm artifact upload via rest api
379+ req := NewRequestWithBody (t , "GET" , fmt .Sprintf ("/api/v1/repos/%s/actions/artifacts?name=artifact-v4-download" , repo .FullName ()), nil ).
380+ AddTokenAuth (token )
381+ resp := MakeRequest (t , req , http .StatusOK )
382+ var listResp api.ActionArtifactsResponse
383+ err := json .Unmarshal (resp .Body .Bytes (), & listResp )
384+ assert .NoError (t , err )
385+ assert .NotEmpty (t , listResp .Entries [0 ].ArchiveDownloadURL )
386+ assert .Equal (t , "artifact-v4-download" , listResp .Entries [0 ].Name )
387+
388+ req = NewRequestWithBody (t , "GET" , listResp .Entries [0 ].ArchiveDownloadURL , nil ).
389+ AddTokenAuth (token )
390+
391+ resp = MakeRequest (t , req , http .StatusOK )
392+ body := strings .Repeat ("D" , 1024 )
393+ assert .Equal (t , body , resp .Body .String ())
394+ }
395+
396+ func TestActionsArtifactV4ListAndGetPublicApi (t * testing.T ) {
397+ defer prepareTestEnvActionsArtifacts (t )()
398+
399+ repo := unittest .AssertExistsAndLoadBean (t , & repo_model.Repository {ID : 4 })
400+ user := unittest .AssertExistsAndLoadBean (t , & user_model.User {ID : repo .OwnerID })
401+ session := loginUser (t , user .Name )
402+ token := getTokenForLoggedInUser (t , session , auth_model .AccessTokenScopeWriteRepository )
403+
404+ // confirm artifact upload via rest api
405+ req := NewRequestWithBody (t , "GET" , fmt .Sprintf ("/api/v1/repos/%s/actions/artifacts" , repo .FullName ()), nil ).
406+ AddTokenAuth (token )
407+ resp := MakeRequest (t , req , http .StatusOK )
408+ var listResp api.ActionArtifactsResponse
409+ err := json .Unmarshal (resp .Body .Bytes (), & listResp )
410+ assert .NoError (t , err )
411+
412+ for _ , artifact := range listResp .Entries {
413+ assert .Contains (t , fmt .Sprintf ("/api/v1/repos/%s/actions/artifacts/%d" , repo .FullName (), artifact .ID ), artifact .URL )
414+ assert .Contains (t , fmt .Sprintf ("/api/v1/repos/%s/actions/artifacts/%d/zip" , repo .FullName (), artifact .ID ), artifact .ArchiveDownloadURL )
415+ req = NewRequestWithBody (t , "GET" , listResp .Entries [0 ].URL , nil ).
416+ AddTokenAuth (token )
417+
418+ resp = MakeRequest (t , req , http .StatusOK )
419+ var artifactResp api.ActionArtifact
420+ err := json .Unmarshal (resp .Body .Bytes (), & artifactResp )
421+ assert .NoError (t , err )
422+
423+ assert .Equal (t , artifact .ID , artifactResp .ID )
424+ assert .Equal (t , artifact .Name , artifactResp .Name )
425+ assert .Equal (t , artifact .SizeInBytes , artifactResp .SizeInBytes )
426+ assert .Equal (t , artifact .URL , artifactResp .URL )
427+ assert .Equal (t , artifact .ArchiveDownloadURL , artifactResp .ArchiveDownloadURL )
428+ }
429+ }
430+
337431func TestActionsArtifactV4Delete (t * testing.T ) {
338432 defer prepareTestEnvActionsArtifacts (t )()
339433
0 commit comments