@@ -299,6 +299,45 @@ describe('test authorization', () => {
299299 expectSecurityContext ( handlerMock . mock . calls [ 0 ] [ 0 ] . context . authInfo ) ;
300300 } ) ;
301301
302+ test ( 'custom checkAuth with CubejsHandlerError fail in playground' , async ( ) => {
303+ const loggerMock = jest . fn ( ( ) => {
304+ //
305+ } ) ;
306+
307+ const expectSecurityContext = ( securityContext ) => {
308+ expect ( securityContext . uid ) . toEqual ( 5 ) ;
309+ expect ( securityContext . iat ) . toBeDefined ( ) ;
310+ expect ( securityContext . exp ) . toBeDefined ( ) ;
311+ } ;
312+
313+ const handlerMock = jest . fn ( ( req , res ) => {
314+ expectSecurityContext ( req . context . securityContext ) ;
315+ expectSecurityContext ( req . context . authInfo ) ;
316+
317+ res . status ( 200 ) . end ( ) ;
318+ } ) ;
319+
320+ const playgroundAuthSecret = 'playgroundSecret' ;
321+
322+ const token = generateAuthToken ( { uid : 5 , } , { } ) ;
323+
324+ const { app } = createApiGateway ( handlerMock , loggerMock , {
325+ playgroundAuthSecret,
326+ checkAuth : async ( req : Request , auth ?: string ) => {
327+ throw new CubejsHandlerError ( 409 , 'Error' , 'Custom error' ) ;
328+ }
329+ } ) ;
330+
331+ const res = await request ( app )
332+ . get ( '/test-auth-fake' )
333+ . set ( 'Authorization' , `Authorization: ${ token } ` )
334+ . expect ( 409 ) ;
335+
336+ expect ( res . body ) . toMatchObject ( {
337+ error : 'Custom error'
338+ } ) ;
339+ } ) ;
340+
302341 test ( 'custom checkAuth with deprecated authInfo' , async ( ) => {
303342 const loggerMock = jest . fn ( ( ) => {
304343 //
0 commit comments