Skip to content
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

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

Closed
mogaming217 opened this issue Aug 23, 2020 · 2 comments · Fixed by #3676
Closed

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

mogaming217 opened this issue Aug 23, 2020 · 2 comments · Fixed by #3676
Assignees
Labels
testing-sdk testing with emulator

Comments

@mogaming217
Copy link
Contributor

mogaming217 commented Aug 23, 2020

[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())
  })
})
@yuchenshi
Copy link
Member

@mogaming217 Thanks for the issue. Yes, we'd appreciate a pull request.

@yuchenshi
Copy link
Member

This is now fixed on master thanks to @mogaming217 and it should go out with the next patch release soon.

This was referenced Aug 25, 2020
@firebase firebase locked and limited conversation to collaborators Sep 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
testing-sdk testing with emulator
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants