@@ -24,12 +24,14 @@ const CURRENT_REVIEW_LABEL = "codex-security-review-current";
2424
2525function pullRequest ( {
2626 authorAssociation = "CONTRIBUTOR" ,
27+ authorLogin = "pr-author" ,
2728 baseSha = OLD_BASE_SHA ,
2829 headSha = HEAD_SHA ,
2930 labels = [ ] ,
3031} = { } ) {
3132 return {
3233 author_association : authorAssociation ,
34+ user : { login : authorLogin } ,
3335 state : "open" ,
3436 base : {
3537 ref : "main" ,
@@ -46,6 +48,7 @@ function pullRequest({
4648}
4749
4850function harness ( {
51+ authorPermission = "read" ,
4952 pull = pullRequest ( ) ,
5053 comments = [ ] ,
5154 files = [ ] ,
@@ -63,6 +66,7 @@ function harness({
6366 const notices = [ ] ;
6467 const info = [ ] ;
6568 const warnings = [ ] ;
69+ const permissionChecks = [ ] ;
6670 const listComments = async ( ) => storedComments ;
6771 const listFiles = async ( ) => files ;
6872 let labelExists = false ;
@@ -122,6 +126,12 @@ function harness({
122126 get : async ( ) => ( { data : pull } ) ,
123127 listFiles,
124128 } ,
129+ repos : {
130+ getCollaboratorPermissionLevel : async ( input ) => {
131+ permissionChecks . push ( input ) ;
132+ return { data : { permission : authorPermission } } ;
133+ } ,
134+ } ,
125135 } ,
126136 } ;
127137 const core = {
@@ -150,6 +160,7 @@ function harness({
150160 info,
151161 notices,
152162 outputs,
163+ permissionChecks,
153164 removeLabelCalls,
154165 removedLabels,
155166 storedComments,
@@ -231,24 +242,31 @@ test("prepare binds a member command to the named head SHA", async () => {
231242 ) ;
232243} ) ;
233244
234- test ( "pull request authorization uses the live author association" , async ( ) => {
235- const member = harness ( {
236- pull : pullRequest ( { authorAssociation : "MEMBER" } ) ,
237- } ) ;
238- member . context . eventName = "pull_request_target" ;
239- member . context . payload . pull_request = {
240- number : 6816 ,
241- head : { sha : HEAD_SHA } ,
242- author_association : "CONTRIBUTOR" ,
243- } ;
244-
245- await prepare ( member ) ;
246-
247- assert . equal ( member . outputs . get ( "authorized" ) , "true" ) ;
248- assert . deepEqual ( member . failures , [ ] ) ;
245+ test ( "pull request authorization uses live repository write access" , async ( ) => {
246+ for ( const authorPermission of [ "write" , "admin" ] ) {
247+ const trusted = harness ( {
248+ authorPermission,
249+ pull : pullRequest ( { authorAssociation : "CONTRIBUTOR" } ) ,
250+ } ) ;
251+ trusted . context . eventName = "pull_request_target" ;
252+ trusted . context . payload . pull_request = {
253+ number : 6816 ,
254+ head : { sha : HEAD_SHA } ,
255+ author_association : "CONTRIBUTOR" ,
256+ } ;
257+
258+ await prepare ( trusted ) ;
259+
260+ assert . equal ( trusted . outputs . get ( "authorized" ) , "true" ) ;
261+ assert . deepEqual ( trusted . failures , [ ] ) ;
262+ assert . deepEqual ( trusted . permissionChecks , [
263+ { owner : "block" , repo : "buzz" , username : "pr-author" } ,
264+ ] ) ;
265+ }
249266
250267 const external = harness ( {
251- pull : pullRequest ( { authorAssociation : "CONTRIBUTOR" } ) ,
268+ authorPermission : "read" ,
269+ pull : pullRequest ( { authorAssociation : "MEMBER" } ) ,
252270 } ) ;
253271 external . context . eventName = "pull_request_target" ;
254272 external . context . payload . pull_request = {
@@ -261,7 +279,7 @@ test("pull request authorization uses the live author association", async () =>
261279
262280 assert . equal ( external . outputs . get ( "authorized" ) , undefined ) ;
263281 assert . deepEqual ( external . failures , [ ] ) ;
264- assert . match ( external . info . at ( - 1 ) , / r e q u i r e s a u t h o r i z a t i o n / ) ;
282+ assert . match ( external . info . at ( - 1 ) , / d o e s n o t h a v e w r i t e a c c e s s / ) ;
265283} ) ;
266284
267285test ( "PR mutation jobs use pull request write permission" , ( ) => {
@@ -498,8 +516,9 @@ test("base reconciliation does not create comments on unreviewed PRs", async ()
498516 assert . equal ( state . updated . length , 0 ) ;
499517} ) ;
500518
501- test ( "pull request updates invalidate member reviews without adding placeholders" , async ( ) => {
519+ test ( "pull request updates invalidate trusted reviews without adding placeholders" , async ( ) => {
502520 const reviewed = harness ( {
521+ authorPermission : "write" ,
503522 pull : pullRequest ( {
504523 authorAssociation : "MEMBER" ,
505524 headSha : OTHER_HEAD_SHA ,
@@ -529,6 +548,7 @@ test("pull request updates invalidate member reviews without adding placeholders
529548 assert . equal ( reviewed . removedLabels . length , 1 ) ;
530549
531550 const unreviewed = harness ( {
551+ authorPermission : "write" ,
532552 pull : pullRequest ( { authorAssociation : "OWNER" } ) ,
533553 } ) ;
534554 unreviewed . context . eventName = "pull_request_target" ;
@@ -544,6 +564,7 @@ test("pull request updates invalidate member reviews without adding placeholders
544564 assert . equal ( unreviewed . removeLabelCalls . length , 0 ) ;
545565
546566 const external = harness ( {
567+ authorPermission : "read" ,
547568 pull : pullRequest ( { authorAssociation : "CONTRIBUTOR" } ) ,
548569 } ) ;
549570 external . context . eventName = "pull_request_target" ;
0 commit comments