@@ -219,7 +219,25 @@ func TestAPIUpdateBranch(t *testing.T) {
219219 resp = testAPIUpdateBranch (t , "user40" , "user2" , "repo1" , "protected-branch" , "new-branch-name" , http .StatusForbidden )
220220 assert .Contains (t , resp .Body .String (), "User must be a repo or site admin to rename default or protected branches." )
221221 })
222- t .Run ("RenameBranchNormalScenario" , func (t * testing.T ) {
222+ t .Run ("UpdateBranchWithGlobedBasedProtectionRulesAndAdminAccess" , func (t * testing.T ) {
223+ // don't allow branch that falls under glob-based protection rules to be renamed
224+ token := getUserToken (t , "user2" , auth_model .AccessTokenScopeWriteRepository )
225+ req := NewRequestWithJSON (t , "POST" , "/api/v1/repos/user2/repo1/branch_protections" , & api.BranchProtection {
226+ RuleName : "protected/**" ,
227+ EnablePush : true ,
228+ }).AddTokenAuth (token )
229+ MakeRequest (t , req , http .StatusCreated )
230+
231+ from := "protected/1"
232+ req = NewRequestWithJSON (t , "POST" , "/api/v1/repos/user2/repo1/branches" , & api.CreateBranchRepoOption {
233+ BranchName : from ,
234+ }).AddTokenAuth (token )
235+ MakeRequest (t , req , http .StatusCreated )
236+
237+ resp := testAPIUpdateBranch (t , "user2" , "user2" , "repo1" , from , "new-branch-name" , http .StatusForbidden )
238+ assert .Contains (t , resp .Body .String (), "Branch is protected by glob-based protection rules." )
239+ })
240+ t .Run ("UpdateBranchNormalScenario" , func (t * testing.T ) {
223241 testAPIUpdateBranch (t , "user2" , "user2" , "repo1" , "branch2" , "new-branch-name" , http .StatusNoContent )
224242 })
225243 })
0 commit comments