@@ -30,11 +30,9 @@ class ApiGatewayOpenAPI extends ApiGateway {
3030 public async shutdownSQLServer ( ) : Promise < void > {
3131 try {
3232 await this . sqlServer . shutdown ( 'fast' ) ;
33- } catch ( error ) {
34- console . log ( `Error while shutting down server: ${ error } ` ) ;
33+ } finally {
34+ this . isRunning = null ;
3535 }
36-
37- this . isRunning = null ;
3836 }
3937}
4038
@@ -110,10 +108,15 @@ describe('test authorization with native gateway', () => {
110108 } ) ;
111109
112110 afterAll ( async ( ) => {
113- await apiGateway . shutdownSQLServer ( ) ;
111+ try {
112+ await apiGateway . shutdownSQLServer ( ) ;
113+ } catch ( error ) {
114+ // TODO: Figure out, why ApiGatewayServer cannot shutdown!?
115+ console . log ( `Error while shutting down server: ${ error } ` ) ;
116+ }
114117 } ) ;
115118
116- it ( 'default authorization' , async ( ) => {
119+ it ( 'default authorization - success ' , async ( ) => {
117120 const token = generateAuthToken ( { uid : 5 , } ) ;
118121
119122 await request ( app )
@@ -128,6 +131,35 @@ describe('test authorization with native gateway', () => {
128131
129132 await apiGateway . shutdownSQLServer ( ) ;
130133 } ) ;
134+
135+ it ( 'default authorization - wrong secret' , async ( ) => {
136+ const badToken = generateAuthToken ( { uid : 5 , } , { } , 'bad' ) ;
137+
138+ await request ( app )
139+ . get ( '/cubejs-api/v2/stream' )
140+ . set ( 'Authorization' , `${ badToken } ` )
141+ . expect ( 403 ) ;
142+
143+ // No bad logs
144+ expect ( loggerMock . mock . calls . length ) . toEqual ( 0 ) ;
145+ // We should not call js handler, request should go into rust code
146+ expect ( handlerMock . mock . calls . length ) . toEqual ( 0 ) ;
147+
148+ await apiGateway . shutdownSQLServer ( ) ;
149+ } ) ;
150+
151+ it ( 'default authorization - missing auth header' , async ( ) => {
152+ await request ( app )
153+ . get ( '/cubejs-api/v2/stream' )
154+ . expect ( 403 ) ;
155+
156+ // No bad logs
157+ expect ( loggerMock . mock . calls . length ) . toEqual ( 0 ) ;
158+ // We should not call js handler, request should go into rust code
159+ expect ( handlerMock . mock . calls . length ) . toEqual ( 0 ) ;
160+
161+ await apiGateway . shutdownSQLServer ( ) ;
162+ } ) ;
131163} ) ;
132164
133165describe ( 'test authorization' , ( ) => {
0 commit comments