66 AuthSettingsWriteScope ,
77 DEFAULT_SERVER_SETTINGS ,
88 ProviderDriverKind ,
9+ ProjectId ,
910 ProviderInstanceId ,
1011 SecretProviderId ,
1112 ThreadId ,
@@ -318,30 +319,37 @@ describe("thread context authorization", () => {
318319 ) ;
319320} ) ;
320321
321- it . effect ( "separates host file URLs from readable attachment URLs " , ( ) =>
322+ it . effect ( "separates filesystem reads, attachment reads, and hosted publication " , ( ) =>
322323 Effect . gen ( function * ( ) {
323324 const group = WsRpcGroup . omit (
324325 ...[ ...WsRpcGroup . requests . keys ( ) ] . filter (
325326 (
326327 tag ,
327- ) : tag is Exclude < keyof typeof RPC_REQUIRED_SCOPES , typeof WS_METHODS . assetsCreateUrl > =>
328- tag !== WS_METHODS . assetsCreateUrl ,
328+ ) : tag is Exclude <
329+ keyof typeof RPC_REQUIRED_SCOPES ,
330+ typeof WS_METHODS . assetsCreateUrl | typeof WS_METHODS . pullRequestsUploadAttachment
331+ > => tag !== WS_METHODS . assetsCreateUrl && tag !== WS_METHODS . pullRequestsUploadAttachment ,
329332 ) ,
330333 ) ;
331334 let handled = 0 ;
332- const client = yield * RpcTest . makeClient ( group ) . pipe (
333- Effect . provide (
334- Layer . mergeAll (
335- group . toLayerHandler ( WS_METHODS . assetsCreateUrl , ( ) =>
336- Effect . sync ( ( ) => {
337- handled ++ ;
338- return { relativeUrl : "/api/assets/file" , expiresAt : 1 } ;
339- } ) ,
340- ) ,
341- RpcAuthorization . layer ( [ AuthOrchestrationReadScope ] ) ,
342- ) ,
335+ let published = 0 ;
336+ const handlers = Layer . merge (
337+ group . toLayerHandler ( WS_METHODS . assetsCreateUrl , ( ) =>
338+ Effect . sync ( ( ) => {
339+ handled ++ ;
340+ return { relativeUrl : "/api/assets/file" , expiresAt : 1 } ;
341+ } ) ,
342+ ) ,
343+ group . toLayerHandler ( WS_METHODS . pullRequestsUploadAttachment , ( ) =>
344+ Effect . sync ( ( ) => {
345+ published ++ ;
346+ return { url : "https://github.com/user-attachments/assets/image" } ;
347+ } ) ,
343348 ) ,
344349 ) ;
350+ const client = yield * RpcTest . makeClient ( group ) . pipe (
351+ Effect . provide ( Layer . merge ( handlers , RpcAuthorization . layer ( [ AuthOrchestrationReadScope ] ) ) ) ,
352+ ) ;
345353 yield * client [ WS_METHODS . assetsCreateUrl ] ( {
346354 resource : { _tag : "attachment" , attachmentId : "image" } ,
347355 } ) ;
@@ -358,6 +366,39 @@ it.effect("separates host file URLs from readable attachment URLs", () =>
358366 } ) ;
359367 }
360368 expect ( handled ) . toBe ( 1 ) ;
369+ const attachment = {
370+ projectId : ProjectId . make ( "project" ) ,
371+ repository : "org/repo" ,
372+ number : 1 ,
373+ attachmentId : "pending-00000000-0000-4000-8000-000000000001-png" ,
374+ name : "image.png" ,
375+ mimeType : "image/png" as const ,
376+ sizeBytes : 3 ,
377+ } ;
378+ expect (
379+ yield * client [ WS_METHODS . pullRequestsUploadAttachment ] ( attachment ) . pipe ( Effect . flip ) ,
380+ ) . toMatchObject ( { requiredPermission : AuthSourceControlWriteScope } ) ;
381+ expect ( published ) . toBe ( 0 ) ;
382+ for ( const scopes of [
383+ [ AuthSourceControlWriteScope ] ,
384+ [ AuthSourceControlWriteScope , AuthOrchestrationReadScope ] ,
385+ ] ) {
386+ const publisher = yield * RpcTest . makeClient ( group ) . pipe (
387+ Effect . provide ( Layer . merge ( handlers , RpcAuthorization . layer ( scopes ) ) ) ,
388+ ) ;
389+ const operation = publisher [ WS_METHODS . pullRequestsUploadAttachment ] ( attachment ) ;
390+ if ( ! scopes . includes ( AuthOrchestrationReadScope ) ) {
391+ expect ( yield * operation . pipe ( Effect . flip ) ) . toMatchObject ( {
392+ requiredPermission : AuthOrchestrationReadScope ,
393+ } ) ;
394+ expect ( published ) . toBe ( 0 ) ;
395+ } else {
396+ expect ( yield * operation ) . toEqual ( {
397+ url : "https://github.com/user-attachments/assets/image" ,
398+ } ) ;
399+ expect ( published ) . toBe ( 1 ) ;
400+ }
401+ }
361402 } ) . pipe ( Effect . scoped ) ,
362403) ;
363404
0 commit comments