@@ -365,7 +365,7 @@ func doBranchProtectPRMerge(baseCtx *APITestContext, dstPath string) func(t *tes
365365 t .Run ("PushProtectedBranch" , doGitPushTestRepository (dstPath , "origin" , "protected" ))
366366
367367 ctx := NewAPITestContext (t , baseCtx .Username , baseCtx .Reponame )
368- t .Run ("ProtectProtectedBranchNoWhitelist" , doProtectBranch (ctx , "protected" , "" ))
368+ t .Run ("ProtectProtectedBranchNoWhitelist" , doProtectBranch (ctx , "protected" , "" , "" ))
369369 t .Run ("GenerateCommit" , func (t * testing.T ) {
370370 _ ,
err := generateCommitWithNewData (
littleSize ,
dstPath ,
"[email protected] " ,
"User Two" ,
"branch-data-file-" )
371371 assert .NoError (t , err )
@@ -391,7 +391,15 @@ func doBranchProtectPRMerge(baseCtx *APITestContext, dstPath string) func(t *tes
391391 t .Run ("MergePR2" , doAPIMergePullRequest (ctx , baseCtx .Username , baseCtx .Reponame , pr2 .Index ))
392392 t .Run ("MergePR" , doAPIMergePullRequest (ctx , baseCtx .Username , baseCtx .Reponame , pr .Index ))
393393 t .Run ("PullProtected" , doGitPull (dstPath , "origin" , "protected" ))
394- t .Run ("ProtectProtectedBranchWhitelist" , doProtectBranch (ctx , "protected" , baseCtx .Username ))
394+
395+ t .Run ("ProtectProtectedBranchUnprotectedFilePaths" , doProtectBranch (ctx , "protected" , "" , "unprotected-file-*" ))
396+ t .Run ("GenerateCommit" , func (t * testing.T ) {
397+ _ ,
err := generateCommitWithNewData (
littleSize ,
dstPath ,
"[email protected] " ,
"User Two" ,
"unprotected-file-" )
398+ assert .NoError (t , err )
399+ })
400+ t .Run ("PushUnprotectedFilesToProtectedBranch" , doGitPushTestRepository (dstPath , "origin" , "protected" ))
401+
402+ t .Run ("ProtectProtectedBranchWhitelist" , doProtectBranch (ctx , "protected" , baseCtx .Username , "" ))
395403
396404 t .Run ("CheckoutMaster" , doGitCheckoutBranch (dstPath , "master" ))
397405 t .Run ("CreateBranchForced" , doGitCreateBranch (dstPath , "toforce" ))
@@ -406,28 +414,30 @@ func doBranchProtectPRMerge(baseCtx *APITestContext, dstPath string) func(t *tes
406414 }
407415}
408416
409- func doProtectBranch (ctx APITestContext , branch string , userToWhitelist string ) func (t * testing.T ) {
417+ func doProtectBranch (ctx APITestContext , branch string , userToWhitelist string , unprotectedFilePatterns string ) func (t * testing.T ) {
410418 // We are going to just use the owner to set the protection.
411419 return func (t * testing.T ) {
412420 csrf := GetCSRF (t , ctx .Session , fmt .Sprintf ("/%s/%s/settings/branches" , url .PathEscape (ctx .Username ), url .PathEscape (ctx .Reponame )))
413421
414422 if userToWhitelist == "" {
415423 // Change branch to protected
416424 req := NewRequestWithValues (t , "POST" , fmt .Sprintf ("/%s/%s/settings/branches/%s" , url .PathEscape (ctx .Username ), url .PathEscape (ctx .Reponame ), url .PathEscape (branch )), map [string ]string {
417- "_csrf" : csrf ,
418- "protected" : "on" ,
425+ "_csrf" : csrf ,
426+ "protected" : "on" ,
427+ "unprotected_file_patterns" : unprotectedFilePatterns ,
419428 })
420429 ctx .Session .MakeRequest (t , req , http .StatusFound )
421430 } else {
422431 user , err := models .GetUserByName (userToWhitelist )
423432 assert .NoError (t , err )
424433 // Change branch to protected
425434 req := NewRequestWithValues (t , "POST" , fmt .Sprintf ("/%s/%s/settings/branches/%s" , url .PathEscape (ctx .Username ), url .PathEscape (ctx .Reponame ), url .PathEscape (branch )), map [string ]string {
426- "_csrf" : csrf ,
427- "protected" : "on" ,
428- "enable_push" : "whitelist" ,
429- "enable_whitelist" : "on" ,
430- "whitelist_users" : strconv .FormatInt (user .ID , 10 ),
435+ "_csrf" : csrf ,
436+ "protected" : "on" ,
437+ "enable_push" : "whitelist" ,
438+ "enable_whitelist" : "on" ,
439+ "whitelist_users" : strconv .FormatInt (user .ID , 10 ),
440+ "unprotected_file_patterns" : unprotectedFilePatterns ,
431441 })
432442 ctx .Session .MakeRequest (t , req , http .StatusFound )
433443 }
0 commit comments