@@ -10,52 +10,47 @@ import (
1010 "strconv"
1111 "testing"
1212
13- repo_model "code.gitea.io/gitea/models/repo "
13+ auth_model "code.gitea.io/gitea/models/auth "
1414 "code.gitea.io/gitea/models/unittest"
1515 user_model "code.gitea.io/gitea/models/user"
16- "code.gitea.io/gitea/modules/json"
17-
18- "github.com/stretchr/testify/assert"
1916)
2017
2118func TestActionsCollaborativeOwner (t * testing.T ) {
2219 onGiteaRun (t , func (t * testing.T , u * url.URL ) {
23- // actionRepo is a private repo and its owner is org3
24- actionRepo := unittest .AssertExistsAndLoadBean (t , & repo_model.Repository {ID : 3 })
25-
26- // user2 is an admin of org3
20+ // user2 is the owner of "reusable_workflow" repo
2721 user2 := unittest .AssertExistsAndLoadBean (t , & user_model.User {ID : 2 })
28- // a private repo(id=6) of user10 will try to clone actionRepo
22+ user2Session := loginUser (t , user2 .Name )
23+ user2Token := getTokenForLoggedInUser (t , user2Session , auth_model .AccessTokenScopeWriteRepository , auth_model .AccessTokenScopeWriteUser )
24+ repo := createActionsTestRepo (t , user2Token , "reusable_workflow" , true )
25+
26+ // a private repo(id=6) of user10 will try to clone "reusable_workflow" repo
2927 user10 := unittest .AssertExistsAndLoadBean (t , & user_model.User {ID : 10 })
28+ // task id is 55 and its repo_id=6
29+ taskToken := "674f727a81ed2f195bccab036cccf86a182199eb"
3030
31- taskToken := "674f727a81ed2f195bccab036cccf86a182199eb" // task id is 49
32- u .Path = fmt .Sprintf ("%s/%s.git" , actionRepo . OwnerName , actionRepo .Name )
33- u .User = url .UserPassword (taskToken , "" )
31+ dstPath := t . TempDir ()
32+ u .Path = fmt .Sprintf ("%s/%s.git" , repo . Owner . UserName , repo .Name )
33+ u .User = url .UserPassword ("gitea-actions" , taskToken )
3434
35- // now user10 is not a collaborative owner, so the git clone will fail
35+ // the git clone will fail
3636 doGitCloneFail (u )(t )
3737
3838 // add user10 to the list of collaborative owners
39- user2Session := loginUser (t , user2 .Name )
40- user2CSRF := GetUserCSRFToken (t , user2Session )
41- req := NewRequestWithValues (t , "POST" , fmt .Sprintf ("/%s/%s/settings/actions/general/collaborative_owner/add" , actionRepo .OwnerName , actionRepo .Name ), map [string ]string {
42- "_csrf" : user2CSRF ,
39+ req := NewRequestWithValues (t , "POST" , fmt .Sprintf ("/%s/%s/settings/actions/general/collaborative_owner/add" , repo .Owner .UserName , repo .Name ), map [string ]string {
40+ "_csrf" : GetUserCSRFToken (t , user2Session ),
4341 "collaborative_owner" : user10 .Name ,
4442 })
4543 user2Session .MakeRequest (t , req , http .StatusSeeOther )
4644
4745 // the git clone will be successful
48- doGitClone (t . TempDir () , u )(t )
46+ doGitClone (dstPath , u )(t )
4947
5048 // remove user10 from the list of collaborative owners
51- req = NewRequestWithValues (t , "POST" , fmt .Sprintf ("/%s/%s/settings/actions/general/collaborative_owner/delete" , actionRepo . OwnerName , actionRepo .Name ), map [string ]string {
52- "_csrf" : user2CSRF ,
49+ req = NewRequestWithValues (t , "POST" , fmt .Sprintf ("/%s/%s/settings/actions/general/collaborative_owner/delete" , repo . Owner . UserName , repo .Name ), map [string ]string {
50+ "_csrf" : GetUserCSRFToken ( t , user2Session ) ,
5351 "id" : strconv .FormatInt (user10 .ID , 10 ),
5452 })
55- resp := user2Session .MakeRequest (t , req , http .StatusOK )
56- res := make (map [string ]string )
57- assert .NoError (t , json .NewDecoder (resp .Body ).Decode (& res ))
58- assert .Equal (t , fmt .Sprintf ("/%s/%s/settings/actions/general" , actionRepo .OwnerName , actionRepo .Name ), res ["redirect" ])
53+ user2Session .MakeRequest (t , req , http .StatusOK )
5954
6055 // the git clone will fail
6156 doGitCloneFail (u )(t )
0 commit comments