@@ -62,6 +62,13 @@ describe('Gateway Api Scopes', () => {
6262 expect ( res . body && res . body . error )
6363 . toStrictEqual ( 'API scope is missing: data' ) ;
6464
65+ res = await request ( app )
66+ . get ( '/cubejs-api/v1/sql' )
67+ . set ( 'Authorization' , AUTH_TOKEN )
68+ . expect ( 403 ) ;
69+ expect ( res . body && res . body . error )
70+ . toStrictEqual ( 'API scope is missing: sql' ) ;
71+
6572 res = await request ( app )
6673 . post ( '/cubejs-api/v1/pre-aggregations/jobs' )
6774 . set ( 'Authorization' , AUTH_TOKEN )
@@ -175,39 +182,47 @@ describe('Gateway Api Scopes', () => {
175182 expect ( res3 . body && res3 . body . error )
176183 . toStrictEqual ( 'API scope is missing: data' ) ;
177184
178- const res4 = await request ( app )
179- . get ( '/cubejs-api/v1/sql ' )
185+ const res6 = await request ( app )
186+ . get ( '/cubejs-api/v1/dry-run ' )
180187 . set ( 'Authorization' , AUTH_TOKEN )
181188 . expect ( 403 ) ;
182189
183- expect ( res4 . body && res4 . body . error )
190+ expect ( res6 . body && res6 . body . error )
184191 . toStrictEqual ( 'API scope is missing: data' ) ;
185192
186- const res5 = await request ( app )
187- . post ( '/cubejs-api/v1/sql ' )
193+ const res7 = await request ( app )
194+ . post ( '/cubejs-api/v1/dry-run ' )
188195 . set ( 'Content-type' , 'application/json' )
189196 . set ( 'Authorization' , AUTH_TOKEN )
190197 . expect ( 403 ) ;
191198
192- expect ( res5 . body && res5 . body . error )
199+ expect ( res7 . body && res7 . body . error )
193200 . toStrictEqual ( 'API scope is missing: data' ) ;
194201
195- const res6 = await request ( app )
196- . get ( '/cubejs-api/v1/dry-run' )
202+ apiGateway . release ( ) ;
203+ } ) ;
204+
205+ test ( 'Sql declined' , async ( ) => {
206+ const { app, apiGateway } = createApiGateway ( {
207+ contextToApiScopes : async ( ) => [ 'graphql' , 'meta' , 'jobs' , 'data' ] ,
208+ } ) ;
209+
210+ const res1 = await request ( app )
211+ . get ( '/cubejs-api/v1/sql' )
197212 . set ( 'Authorization' , AUTH_TOKEN )
198213 . expect ( 403 ) ;
199214
200- expect ( res6 . body && res6 . body . error )
201- . toStrictEqual ( 'API scope is missing: data ' ) ;
215+ expect ( res1 . body && res1 . body . error )
216+ . toStrictEqual ( 'API scope is missing: sql ' ) ;
202217
203- const res7 = await request ( app )
204- . post ( '/cubejs-api/v1/dry-run ' )
218+ const res2 = await request ( app )
219+ . post ( '/cubejs-api/v1/sql ' )
205220 . set ( 'Content-type' , 'application/json' )
206221 . set ( 'Authorization' , AUTH_TOKEN )
207222 . expect ( 403 ) ;
208223
209- expect ( res7 . body && res7 . body . error )
210- . toStrictEqual ( 'API scope is missing: data ' ) ;
224+ expect ( res2 . body && res2 . body . error )
225+ . toStrictEqual ( 'API scope is missing: sql ' ) ;
211226
212227 apiGateway . release ( ) ;
213228 } ) ;
0 commit comments