@@ -228,4 +228,53 @@ describe('public folder capabilities in PostgreSQL', () => {
228228 . where ( eq ( publicShare . id , directShareId ) )
229229 }
230230 } )
231+
232+ it . each ( [
233+ { name : 'deleted' , update : { deletedAt : new Date ( ) } } ,
234+ { name : 'moved out of workspace storage' , update : { context : 'chat' } } ,
235+ {
236+ name : 'moved to another workspace' ,
237+ update : { workspaceId : otherWorkspaceId , folderId : null } ,
238+ } ,
239+ ] ) ( 'denies a direct file that is $name during authorization' , async ( { update } ) => {
240+ try {
241+ await expect (
242+ readPublicSharedFile ( {
243+ token : directToken ,
244+ authorize : async ( ) => {
245+ await db . update ( workspaceFiles ) . set ( update ) . where ( eq ( workspaceFiles . id , fileId ) )
246+ return { authorized : true }
247+ } ,
248+ } )
249+ ) . rejects . toMatchObject ( { status : 404 } )
250+ } finally {
251+ await db
252+ . update ( workspaceFiles )
253+ . set ( { deletedAt : null , context : 'workspace' , workspaceId, folderId : childId } )
254+ . where ( eq ( workspaceFiles . id , fileId ) )
255+ }
256+ } )
257+
258+ it ( 'reads the current direct file metadata and storage key after authorization' , async ( ) => {
259+ const updatedKey = `workspace/${ workspaceId } /${ generateId ( ) } `
260+ try {
261+ const result = await readPublicSharedFile ( {
262+ token : directToken ,
263+ authorize : async ( ) => {
264+ await db
265+ . update ( workspaceFiles )
266+ . set ( { originalName : 'updated.txt' , key : updatedKey } )
267+ . where ( eq ( workspaceFiles . id , fileId ) )
268+ return { authorized : true }
269+ } ,
270+ } )
271+ expect ( result . file . originalName ) . toBe ( 'updated.txt' )
272+ expect ( result . file . key ) . toBe ( updatedKey )
273+ } finally {
274+ await db
275+ . update ( workspaceFiles )
276+ . set ( { originalName : 'nested.txt' , key : `workspace/${ workspaceId } /${ fileId } ` } )
277+ . where ( eq ( workspaceFiles . id , fileId ) )
278+ }
279+ } )
231280} )
0 commit comments