fix: assertFails for storage read/write requests (#5086) #5209
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes Issue 4 of #5086
Discussion
#5086
This PR makes assertFails work properly with the storage emulator.
Most storage permission errors throw errors with the message "(storage/unauthorized)", but assertFails only checks for the string "permission denied". This means that assertFails won't work properly for most storage unit tests.
This fix is a small one that just adds another check if the message contains the string "unauthorized". A better fix would be to ensure that all firebase products throw consistent error message codes when permission is denied, but this solution will at least fix this bug in the unit testing library for storage for the time being.
Testing
'assertFails() if message contains unauthorized'
NOTE: It would be better if the rules-unit-testing library also contained tests for real-world usage (like actually spinning up the emulators and checking assertFails and assertSucceeds for basic actions like reading/writing from firestore, realtiime database, or storage). I think having just a few basic tests for usage would have caught this issue much quicker.