3
votes

I want to verify that Firebase Storage rules are working as expected with automated Node.js tests.

One can access Firebase Storage buckets with the Firebase Admin API or a service account, as indicated in Upload files to Firebase Storage using Node.js.

The problem is that using the Admin API or a service account circumvents the storage rules.

There is no apparent way to access Firebase Storage as a given Firebase user, as the Firebase Node.js API does not include a firebase.storage function.

In short, how can one access Firebase Storage from Node.js as a given Firebase user/uid?

1
The doc of the node.js API to access Storage is here: cloud.google.com/nodejs/docs/reference/storage/1.7.x. If I am not mistaking you can authenticate through cloud.google.com/docs/authentication/…. Note also the acl class that may help you with your tests.Renaud Tarnec
Thanks @RenaudTarnec, that's helpful. An ideal answer would indicate how to get the OAuth credentials for a Firebase user for authentication as that user per cloud.google.com/docs/authentication/end-user.Brian M. Hunt
I do agree... Since I was not sure that I could exactly/precisely describe how to authenticate I wrote a comment and not an answer :-)Renaud Tarnec

1 Answers

5
votes

As far as I know there is currently no way to accomplish what you want.

There is a storage() service in the Firebase Admin SDK for Node.js, but as you've discovered this gives full administrative access to your bucket.

While the Admin SDK for the Realtime Database can be initialized to access the database as a specific user, this feature is not available for the Storage service.

What you want to do sounds quite reasonable though, so I recommend that you file a feature request. In the meantime, the best I can think of is running those unit tests in a browser, so that you can authenticate with the regular JavaScript client SDK.