@@ -459,18 +459,34 @@ describe(AuthService.name, () => {
459
459
460
460
mocks . apiKey . getKey . mockResolvedValue ( { ...authApiKey , user : authUser } ) ;
461
461
462
- await expect (
463
- sut . authenticate ( {
464
- headers : { 'x-api-key' : 'auth_token' } ,
465
- queryParams : { } ,
466
- metadata : { adminRoute : false , sharedLinkRoute : false , uri : 'test' , permission : Permission . AssetRead } ,
467
- } ) ,
468
- ) . rejects . toBeInstanceOf ( ForbiddenException ) ;
462
+ const result = sut . authenticate ( {
463
+ headers : { 'x-api-key' : 'auth_token' } ,
464
+ queryParams : { } ,
465
+ metadata : { adminRoute : false , sharedLinkRoute : false , uri : 'test' , permission : Permission . AssetRead } ,
466
+ } ) ;
467
+
468
+ await expect ( result ) . rejects . toBeInstanceOf ( ForbiddenException ) ;
469
+ await expect ( result ) . rejects . toThrow ( 'Missing required permission: asset.read' ) ;
470
+ } ) ;
471
+
472
+ it ( 'should default to requiring the all permission when omitted' , async ( ) => {
473
+ const authUser = factory . authUser ( ) ;
474
+ const authApiKey = factory . authApiKey ( { permissions : [ Permission . AssetRead ] } ) ;
475
+
476
+ mocks . apiKey . getKey . mockResolvedValue ( { ...authApiKey , user : authUser } ) ;
477
+
478
+ const result = sut . authenticate ( {
479
+ headers : { 'x-api-key' : 'auth_token' } ,
480
+ queryParams : { } ,
481
+ metadata : { adminRoute : false , sharedLinkRoute : false , uri : 'test' } ,
482
+ } ) ;
483
+ await expect ( result ) . rejects . toBeInstanceOf ( ForbiddenException ) ;
484
+ await expect ( result ) . rejects . toThrow ( 'Missing required permission: all' ) ;
469
485
} ) ;
470
486
471
487
it ( 'should return an auth dto' , async ( ) => {
472
488
const authUser = factory . authUser ( ) ;
473
- const authApiKey = factory . authApiKey ( { permissions : [ ] } ) ;
489
+ const authApiKey = factory . authApiKey ( { permissions : [ Permission . All ] } ) ;
474
490
475
491
mocks . apiKey . getKey . mockResolvedValue ( { ...authApiKey , user : authUser } ) ;
476
492
0 commit comments