Skip to content

fix: assertFails for storage read/write requests (#5086) #5209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/rules-unit-testing/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,9 @@ export function assertFails(pr: Promise<any>): any {
errCode === 'permission-denied' ||
errCode === 'permission_denied' ||
errMessage.indexOf('permission_denied') >= 0 ||
errMessage.indexOf('permission denied') >= 0;
errMessage.indexOf('permission denied') >= 0 ||
// Storage permission errors contain message: (storage/unauthorized)
errMessage.indexOf('unauthorized') >= 0;

if (!isPermissionDenied) {
return Promise.reject(
Expand Down
25 changes: 25 additions & 0 deletions packages/rules-unit-testing/test/database.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,31 @@ describe('Testing Module Tests', function () {
.catch(() => {});
});

it('assertFails() if message contains unauthorized', async function () {
const success = Promise.resolve('success');
const permissionDenied = Promise.reject({
message: 'User does not have permission to access \'file\'. (storage/unauthorized)'
});
const otherFailure = Promise.reject('failure');
await firebase
.assertFails(success)
.then(() => {
throw new Error('Expected success to fail.');
})
.catch(() => {});

await firebase.assertFails(permissionDenied).catch(() => {
throw new Error('Expected permissionDenied to succeed.');
});

await firebase
.assertFails(otherFailure)
.then(() => {
throw new Error('Expected otherFailure to fail.');
})
.catch(() => {});
});

it('discoverEmulators() finds all running emulators', async () => {
const options = await firebase.discoverEmulators();

Expand Down