@@ -300,9 +300,10 @@ describe('Search OAuth installation', () => {
300300 } )
301301} )
302302
303- it ( 'rejects a shared-app callback if the global configuration was disabled or rotated' , async ( ) => {
303+ it ( 'rejects a shared-app callback if organization access was disabled or configuration rotated' , async ( ) => {
304304 m . consume . mockResolvedValue ( { ...attempt , sharedApp : { id : 'ASHARED' , revision : 'app-rev' } } )
305305 await expect ( complete ( ) ) . rejects . toThrow ( 'configuration changed' )
306+ expect ( m . shared ) . toHaveBeenCalledWith ( 'org1' )
306307 expect ( m . exchange ) . not . toHaveBeenCalled ( )
307308 m . shared . mockResolvedValue ( { id : 'ASHARED' , revision : 'new-rev' } )
308309 await expect ( complete ( ) ) . rejects . toThrow ( )
@@ -327,6 +328,24 @@ describe('shared app completion', () => {
327328 } )
328329 } )
329330
331+ it ( 'only offers and starts shared OAuth for the enabled organization' , async ( ) => {
332+ m . shared . mockImplementation ( async ( orgId ) => ( orgId === 'org1' ? sharedApp : null ) )
333+ const details = { name : 'Sim Search' , description : 'Search with sources' }
334+ await expect (
335+ prepareSlackSearchSetup . execute ( { principal, input : { ...details , organizationId : 'org1' } } )
336+ ) . resolves . toHaveProperty ( 'sharedAppId' , 'A1' )
337+ await expect (
338+ prepareSlackSearchSetup . execute ( { principal, input : { ...details , organizationId : 'org2' } } )
339+ ) . resolves . toHaveProperty ( 'sharedAppId' , null )
340+ await expect (
341+ startSlackSearchSetup . execute ( {
342+ principal,
343+ input : { ...details , organizationId : 'org2' , mode : 'shared' } ,
344+ } )
345+ ) . rejects . toThrow ( 'unavailable' )
346+ expect ( m . store ) . not . toHaveBeenCalled ( )
347+ } )
348+
330349 it ( 'starts shared OAuth without storing deployment secrets in the attempt' , async ( ) => {
331350 const result = await startSlackSearchSetup . execute ( {
332351 principal,
@@ -338,6 +357,7 @@ describe('shared app completion', () => {
338357 } ,
339358 } )
340359 expect ( new URL ( result . authorizationUrl ) . searchParams . get ( 'client_id' ) ) . toBe ( 'client' )
360+ expect ( m . shared ) . toHaveBeenCalledWith ( 'org1' )
341361 const stored = m . store . mock . calls [ 0 ] [ 0 ]
342362 expect ( stored . sharedApp ) . toEqual ( { id : 'A1' , revision : 'shared-revision' } )
343363 expect ( stored ) . not . toHaveProperty ( 'encryptedClientSecret' )
@@ -468,6 +488,7 @@ describe('shared app completion', () => {
468488 queueTransitionRows ( )
469489 m . shared . mockResolvedValueOnce ( sharedApp ) . mockResolvedValueOnce ( null )
470490 await expect ( complete ( ) ) . rejects . toThrow ( 'configuration changed' )
491+ expect ( m . shared . mock . calls ) . toEqual ( [ [ 'org1' ] , [ 'org1' ] ] )
471492 expect ( m . update ) . not . toHaveBeenCalled ( )
472493 expect ( m . values ) . not . toHaveBeenCalled ( )
473494 } )
0 commit comments