@@ -310,6 +310,84 @@ describe("checkAuthorization", () => {
310310 } ) ;
311311 } ) ;
312312
313+ describe ( "Query resource type" , ( ) => {
314+ it ( "should grant access with read:query super scope" , ( ) => {
315+ const entity : AuthorizationEntity = {
316+ type : "PUBLIC_JWT" ,
317+ scopes : [ "read:query" ] ,
318+ } ;
319+ const result = checkAuthorization (
320+ entity ,
321+ "read" ,
322+ { query : "runs" } ,
323+ [ "read:query" , "read:all" , "admin" ]
324+ ) ;
325+ expect ( result . authorized ) . toBe ( true ) ;
326+ } ) ;
327+
328+ it ( "should grant access with table-specific query scope" , ( ) => {
329+ const entity : AuthorizationEntity = {
330+ type : "PUBLIC_JWT" ,
331+ scopes : [ "read:query:runs" ] ,
332+ } ;
333+ const result = checkAuthorization ( entity , "read" , { query : "runs" } ) ;
334+ expect ( result . authorized ) . toBe ( true ) ;
335+ } ) ;
336+
337+ it ( "should deny access to different table with table-specific scope" , ( ) => {
338+ const entity : AuthorizationEntity = {
339+ type : "PUBLIC_JWT" ,
340+ scopes : [ "read:query:runs" ] ,
341+ } ;
342+ const result = checkAuthorization ( entity , "read" , { query : "llm_metrics" } ) ;
343+ expect ( result . authorized ) . toBe ( false ) ;
344+ } ) ;
345+
346+ it ( "should grant access with general read:query scope to any table" , ( ) => {
347+ const entity : AuthorizationEntity = {
348+ type : "PUBLIC_JWT" ,
349+ scopes : [ "read:query" ] ,
350+ } ;
351+
352+ const runsResult = checkAuthorization ( entity , "read" , { query : "runs" } ) ;
353+ expect ( runsResult . authorized ) . toBe ( true ) ;
354+
355+ const metricsResult = checkAuthorization ( entity , "read" , { query : "metrics" } ) ;
356+ expect ( metricsResult . authorized ) . toBe ( true ) ;
357+
358+ const llmResult = checkAuthorization ( entity , "read" , { query : "llm_metrics" } ) ;
359+ expect ( llmResult . authorized ) . toBe ( true ) ;
360+ } ) ;
361+
362+ it ( "should grant access to multiple tables when querying with super scope" , ( ) => {
363+ const entity : AuthorizationEntity = {
364+ type : "PUBLIC_JWT" ,
365+ scopes : [ "read:query" ] ,
366+ } ;
367+ const result = checkAuthorization (
368+ entity ,
369+ "read" ,
370+ { query : [ "runs" , "llm_metrics" ] } ,
371+ [ "read:query" , "read:all" , "admin" ]
372+ ) ;
373+ expect ( result . authorized ) . toBe ( true ) ;
374+ } ) ;
375+
376+ it ( "should grant access to schema with read:query scope" , ( ) => {
377+ const entity : AuthorizationEntity = {
378+ type : "PUBLIC_JWT" ,
379+ scopes : [ "read:query" ] ,
380+ } ;
381+ const result = checkAuthorization (
382+ entity ,
383+ "read" ,
384+ { query : "schema" } ,
385+ [ "read:query" , "read:all" , "admin" ]
386+ ) ;
387+ expect ( result . authorized ) . toBe ( true ) ;
388+ } ) ;
389+ } ) ;
390+
313391 describe ( "Without super scope" , ( ) => {
314392 const entityWithoutSuperPermissions : AuthorizationEntity = {
315393 type : "PUBLIC_JWT" ,
0 commit comments