Skip to content

assertFails() of rules-unit-testing is incorrect #3671

@mogaming217

Description

@mogaming217

[REQUIRED] Describe your environment

  • Operating System version: macOS
  • Browser version: none
  • Firebase SDK version: @firebase/rules-unit-testing 1.0.0
  • Firebase Product: firestore

[REQUIRED] Describe the problem

Steps to reproduce:

assertFails() of @firebase/rules-unit-testing says Expected PERMISSION_DENIED but got unexpected error: FirebaseError: [code=permission-denied]: No matching allow statements when assertFails(firestore().collection('tests').doc('a').get()) in the below rules. This throws below error.

{ FirebaseError: No matching allow statements
        at new FirestoreError (/Users/moga/workspace/clones/UhooiPicBook-Firebase/node_modules/@firebase/firestore/src/util/error.ts:166:5)
        at fromRpcStatus (/Users/moga/workspace/clones/UhooiPicBook-Firebase/node_modules/@firebase/firestore/src/remote/serializer.ts:134:10)
        at fromWatchChange (/Users/moga/workspace/clones/UhooiPicBook-Firebase/node_modules/@firebase/firestore/src/remote/serializer.ts:490:33)
        at PersistentListenStream.Object.<anonymous>.PersistentListenStream.onMessage (/Users/moga/workspace/clones/UhooiPicBook-Firebase/node_modules/@firebase/firestore/src/remote/persistent_stream.ts:576:25)
        at /Users/moga/workspace/clones/UhooiPicBook-Firebase/node_modules/@firebase/firestore/src/remote/persistent_stream.ts:456:21
        at /Users/moga/workspace/clones/UhooiPicBook-Firebase/node_modules/@firebase/firestore/src/remote/persistent_stream.ts:509:18
        at /Users/moga/workspace/clones/UhooiPicBook-Firebase/node_modules/@firebase/firestore/src/util/async_queue.ts:367:14
        at process._tickCallback (internal/process/next_tick.js:68:7)
      code: 'permission-denied',
      name: 'FirebaseError',
      toString: [Function] }
rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /tests/{monsterId} {
      allow list: if true;
    }
  }
}

So I fix this problem at this commit. If this would be ok, I'm willing to create pr!

Relevant Code:

import * as firebase from '@firebase/rules-unit-testing'
const firestore = firebase.initializeTestApp({ projectId: 'sample', databaseName: 'db' }).firestore()
describe('test', () => {
  it('this shoud be passed but fails', async () => {
    await firebase.assertFails(firestore().collection('tests').doc('a').get())
  })
})

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions