From 72ab59efdb16761ddd23af7d800b9faf376adffe Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Tue, 17 Feb 2026 16:32:26 -0700 Subject: [PATCH] Fix `TestActionsCollaborativeOwner` (#36657) In #32562, I incorrectly assigned mismatched `repo_id` values to the `action_run` and `action_run_job` fixtures used in `TestActionsCollaborativeOwner`. The changes introduced in #36173 will cause the test to fail. This PR removes the incorrect fixtures and switches to using mock workflows to test the relevant functionality. --- models/fixtures/action_run.yml | 21 +-------- models/fixtures/action_run_job.yml | 15 +----- models/fixtures/action_task.yml | 21 +-------- tests/integration/actions_settings_test.go | 54 +++++++++++++++------- 4 files changed, 41 insertions(+), 70 deletions(-) diff --git a/models/fixtures/action_run.yml b/models/fixtures/action_run.yml index 44b131c9612..ac5e8303c35 100644 --- a/models/fixtures/action_run.yml +++ b/models/fixtures/action_run.yml @@ -139,26 +139,7 @@ updated: 1683636626 need_approval: 0 approved_by: 0 -- - id: 804 - title: "use a private action" - repo_id: 60 - owner_id: 40 - workflow_id: "run.yaml" - index: 189 - trigger_user_id: 40 - ref: "refs/heads/master" - commit_sha: "6e64b26de7ba966d01d90ecfaf5c7f14ef203e86" - event: "push" - trigger_event: "push" - is_fork_pull_request: 0 - status: 1 - started: 1683636528 - stopped: 1683636626 - created: 1683636108 - updated: 1683636626 - need_approval: 0 - approved_by: 0 + - id: 805 title: "update actions" diff --git a/models/fixtures/action_run_job.yml b/models/fixtures/action_run_job.yml index c5aeb4931cf..04799b73ca0 100644 --- a/models/fixtures/action_run_job.yml +++ b/models/fixtures/action_run_job.yml @@ -129,20 +129,7 @@ status: 5 started: 1683636528 stopped: 1683636626 -- - id: 205 - run_id: 804 - repo_id: 6 - owner_id: 10 - commit_sha: 6e64b26de7ba966d01d90ecfaf5c7f14ef203e86 - is_fork_pull_request: 0 - name: job_2 - attempt: 1 - job_id: job_2 - task_id: 48 - status: 1 - started: 1683636528 - stopped: 1683636626 + - id: 206 run_id: 805 diff --git a/models/fixtures/action_task.yml b/models/fixtures/action_task.yml index a28ddd0add7..e1bc588dc59 100644 --- a/models/fixtures/action_task.yml +++ b/models/fixtures/action_task.yml @@ -177,26 +177,7 @@ log_length: 0 log_size: 0 log_expired: 0 -- - id: 55 - job_id: 205 - attempt: 1 - runner_id: 1 - status: 6 # 6 is the status code for "running" - started: 1683636528 - stopped: 1683636626 - repo_id: 6 - owner_id: 10 - commit_sha: 6e64b26de7ba966d01d90ecfaf5c7f14ef203e86 - is_fork_pull_request: 0 - token_hash: b8d3962425466b6709b9ac51446f93260c54afe8e7b6d3686e34f991fb8a8953822b0deed86fe41a103f34bc48dbc478422b - token_salt: ERxJGHvg3I - token_last_eight: 182199eb - log_filename: collaborative-owner-test/1a/49.log - log_in_storage: 1 - log_length: 707 - log_size: 90179 - log_expired: 0 + - id: 56 attempt: 1 diff --git a/tests/integration/actions_settings_test.go b/tests/integration/actions_settings_test.go index c87aaa8f038..bf4d8cb7484 100644 --- a/tests/integration/actions_settings_test.go +++ b/tests/integration/actions_settings_test.go @@ -9,8 +9,8 @@ import ( "net/url" "testing" - actions_model "code.gitea.io/gitea/models/actions" auth_model "code.gitea.io/gitea/models/auth" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" @@ -19,30 +19,52 @@ import ( func TestActionsCollaborativeOwner(t *testing.T) { onGiteaRun(t, func(t *testing.T, u *url.URL) { - // user2 is the owner of "reusable_workflow" repo - user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) - user2Session := loginUser(t, user2.Name) + // user2 is the owner of the private "reusable_workflow" repo + user2Session := loginUser(t, "user2") user2Token := getTokenForLoggedInUser(t, user2Session, auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser) - repo := createActionsTestRepo(t, user2Token, "reusable_workflow", true) + apiReusableWorkflowRepo := createActionsTestRepo(t, user2Token, "reusable_workflow", true) + reusableWorkflowRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: apiReusableWorkflowRepo.ID}) - // a private repo(id=6) of user10 will try to clone "reusable_workflow" repo - user10 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 10}) - // task id is 55 and its repo_id=6 - task := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionTask{ID: 55, RepoID: 6}) - taskToken := "674f727a81ed2f195bccab036cccf86a182199eb" - tokenHash := auth_model.HashToken(taskToken, task.TokenSalt) - assert.Equal(t, task.TokenHash, tokenHash) + // user4 is the owner of the private caller repo + user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4}) + user4Session := loginUser(t, user4.Name) + user4Token := getTokenForLoggedInUser(t, user4Session, auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser) + apiCallerRepo := createActionsTestRepo(t, user4Token, "caller_workflow", true) + callerRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: apiCallerRepo.ID}) + // create a mock runner for caller + runner := newMockRunner() + runner.registerAsRepoRunner(t, callerRepo.OwnerName, callerRepo.Name, "mock-runner", []string{"ubuntu-latest"}, false) + + // init the workflow for caller + wfTreePath := ".gitea/workflows/test_collaborative_owner.yml" + wfFileContent := `name: Test Collaborative Owner +on: push +jobs: + job1: + runs-on: ubuntu-latest + steps: + - run: echo 'test collaborative owner' +` + opts := getWorkflowCreateFileOptions(user4, callerRepo.DefaultBranch, "create "+wfTreePath, wfFileContent) + createWorkflowFile(t, user4Token, callerRepo.OwnerName, callerRepo.Name, wfTreePath, opts) + + // fetch the task and get its token + task := runner.fetchTask(t) + taskToken := task.Secrets["GITEA_TOKEN"] + assert.NotEmpty(t, taskToken) + + // prepare for clone dstPath := t.TempDir() - u.Path = fmt.Sprintf("%s/%s.git", repo.Owner.UserName, repo.Name) + u.Path = fmt.Sprintf("%s/%s.git", "user2", "reusable_workflow") u.User = url.UserPassword("gitea-actions", taskToken) // the git clone will fail doGitCloneFail(u)(t) // add user10 to the list of collaborative owners - req := NewRequestWithValues(t, "POST", fmt.Sprintf("/%s/%s/settings/actions/general/collaborative_owner/add", repo.Owner.UserName, repo.Name), map[string]string{ - "collaborative_owner": user10.Name, + req := NewRequestWithValues(t, "POST", fmt.Sprintf("/%s/%s/settings/actions/general/collaborative_owner/add", reusableWorkflowRepo.OwnerName, reusableWorkflowRepo.Name), map[string]string{ + "collaborative_owner": user4.Name, }) user2Session.MakeRequest(t, req, http.StatusOK) @@ -50,7 +72,7 @@ func TestActionsCollaborativeOwner(t *testing.T) { doGitClone(dstPath, u)(t) // remove user10 from the list of collaborative owners - req = NewRequest(t, "POST", fmt.Sprintf("/%s/%s/settings/actions/general/collaborative_owner/delete?id=%d", repo.Owner.UserName, repo.Name, user10.ID)) + req = NewRequest(t, "POST", fmt.Sprintf("/%s/%s/settings/actions/general/collaborative_owner/delete?id=%d", reusableWorkflowRepo.OwnerName, reusableWorkflowRepo.Name, user4.ID)) user2Session.MakeRequest(t, req, http.StatusOK) // the git clone will fail