File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -470,7 +470,9 @@ class Iam {
470470 return ;
471471 }
472472
473- const availablePermissions = resp . permissions ;
473+ const availablePermissions = Array . isArray ( resp . permissions )
474+ ? resp . permissions
475+ : [ ] ;
474476
475477 const permissionsHash = permissionsArray . reduce (
476478 ( acc : { [ index : string ] : boolean } , permission ) => {
Original file line number Diff line number Diff line change @@ -240,6 +240,28 @@ describe('storage/iam', () => {
240240 ) ;
241241 } ) ;
242242
243+ it ( 'should return false for supplied permissions if user has no permissions' , done => {
244+ const permissions = [ 'storage.bucket.list' , 'storage.bucket.consume' ] ;
245+ const apiResponse = { permissions : undefined } ;
246+
247+ iam . request_ = ( reqOpts : DecorateRequestOptions , callback : Function ) => {
248+ callback ( null , apiResponse ) ;
249+ } ;
250+ iam . testPermissions (
251+ permissions ,
252+ ( err : Error , permissions : Array < { } > , apiResp : { } ) => {
253+ assert . ifError ( err ) ;
254+ assert . deepStrictEqual ( permissions , {
255+ 'storage.bucket.list' : false ,
256+ 'storage.bucket.consume' : false ,
257+ } ) ;
258+ assert . strictEqual ( apiResp , apiResponse ) ;
259+
260+ done ( ) ;
261+ }
262+ ) ;
263+ } ) ;
264+
243265 it ( 'should accept an options object' , done => {
244266 const permissions = [ 'storage.bucket.list' ] ;
245267 const options = {
You can’t perform that action at this time.
0 commit comments