diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2024-12-03 19:59:48 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-04 11:59:48 +0800 |
commit | 17053e953f697ba21e067f1ad7715b18e07e273b (patch) | |
tree | 0c9e462f5ffc9104208ccfaba578ebf88e650252 /tests/integration | |
parent | c9e582c6b6cbc7beae66d24b05be6e1d338aa81b (diff) | |
download | gitea-17053e953f697ba21e067f1ad7715b18e07e273b.tar.gz gitea-17053e953f697ba21e067f1ad7715b18e07e273b.zip |
Fix delete branch perm checking (#32654)
Diffstat (limited to 'tests/integration')
-rw-r--r-- | tests/integration/pull_merge_test.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/integration/pull_merge_test.go b/tests/integration/pull_merge_test.go index bbd99f7aab..eb3743bc17 100644 --- a/tests/integration/pull_merge_test.go +++ b/tests/integration/pull_merge_test.go @@ -554,6 +554,10 @@ func TestPullRetargetChildOnBranchDelete(t *testing.T) { testPullMerge(t, session, elemBasePR[1], elemBasePR[2], elemBasePR[4], repo_model.MergeStyleMerge, true) + repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: "user2", Name: "repo1"}) + branchBasePR := unittest.AssertExistsAndLoadBean(t, &git_model.Branch{RepoID: repo1.ID, Name: "base-pr"}) + assert.True(t, branchBasePR.IsDeleted) + // Check child PR req := NewRequest(t, "GET", test.RedirectURL(respChildPR)) resp := session.MakeRequest(t, req, http.StatusOK) @@ -584,6 +588,10 @@ func TestPullDontRetargetChildOnWrongRepo(t *testing.T) { testPullMerge(t, session, elemBasePR[1], elemBasePR[2], elemBasePR[4], repo_model.MergeStyleMerge, true) + repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: "user1", Name: "repo1"}) + branchBasePR := unittest.AssertExistsAndLoadBean(t, &git_model.Branch{RepoID: repo1.ID, Name: "base-pr"}) + assert.True(t, branchBasePR.IsDeleted) + // Check child PR req := NewRequest(t, "GET", test.RedirectURL(respChildPR)) resp := session.MakeRequest(t, req, http.StatusOK) @@ -598,6 +606,27 @@ func TestPullDontRetargetChildOnWrongRepo(t *testing.T) { }) } +func TestPullRequestMergedWithNoPermissionDeleteBranch(t *testing.T) { + onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) { + session := loginUser(t, "user4") + testRepoFork(t, session, "user2", "repo1", "user4", "repo1", "") + testEditFileToNewBranch(t, session, "user4", "repo1", "master", "base-pr", "README.md", "Hello, World\n(Edited - TestPullDontRetargetChildOnWrongRepo - base PR)\n") + + respBasePR := testPullCreate(t, session, "user4", "repo1", false, "master", "base-pr", "Base Pull Request") + elemBasePR := strings.Split(test.RedirectURL(respBasePR), "/") + assert.EqualValues(t, "pulls", elemBasePR[3]) + + // user2 has no permission to delete branch of repo user1/repo1 + session2 := loginUser(t, "user2") + testPullMerge(t, session2, elemBasePR[1], elemBasePR[2], elemBasePR[4], repo_model.MergeStyleMerge, true) + + repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: "user4", Name: "repo1"}) + branchBasePR := unittest.AssertExistsAndLoadBean(t, &git_model.Branch{RepoID: repo1.ID, Name: "base-pr"}) + // branch has not been deleted + assert.False(t, branchBasePR.IsDeleted) + }) +} + func TestPullMergeIndexerNotifier(t *testing.T) { onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) { // create a pull request |