firebase-tools icon indicating copy to clipboard operation
firebase-tools copied to clipboard

Error message improvement for testing security rules

Open rdinkel opened this issue 5 years ago • 8 comments

Environment info

  • Operating System version: Fedora 32
  • Browser version: Firefox 79
  • Firebase SDK version: 0.20.11
  • Firebase: 8.9.0
  • Firebase Product: Firestore, Emulator
  • node: v14.8.0
  • npm: 6.14.7

Test case

package.json

{
  "name": "security_rules",
  "version": "1.0.0",
  "description": "Unit testing for security rules",
  "main": "test.js",
  "scripts": {
    "test": "mocha --exit"
  },
  "author": "me",
  "license": "ISC",
  "devDependencies": {
    "@firebase/testing": "^0.20.11",
    "mocha": "^8.1.1"
  }
}

firestore_rules.json

rules_version = '1';
service cloud.firestore {
  match /databases/{database}/documents {
      match /{document=**} {
        allow read: if false;
        allow write: if false;
      }
}

test,js

const assert = require('assert');
const firebase = require("@firebase/testing");

const PROJECT_ID = "asd";
const myId = "user_abc";
const theirId = "user_xyz";
const myAuth = {uid: myId, email: "[email protected]"};

function getFireStore(myAuth){
    return firebase.initializeTestApp({projectId: PROJECT_ID, auth: myAuth}).firestore();
}

function getFireStoreAdmin(){
    return firebase.initializeAdminApp({projectId: PROJECT_ID}).firestore();
}

beforeEach(async() => {
    await firebase.clearFirestoreData({projectId: PROJECT_ID});
});

describe("asd app", () => {

    it("get doc from firestore", async() => {
        const db = getFireStore(null);
        const testDoc = db.collection("readonly").doc("testDoc");
        await firebase.assertSucceeds(testDoc.get());
    });
})

Steps to reproduce

firebase emulators:start

npm test

Expected behavior

A clear error message what is wrong. Something like FirebaseError: PERMISSION_DENIED because security rules returned false for 'get' @ L5

Actual behavior

Running Security Rule Test fails with following unclear error:

FirebaseError: false for 'get' @ L5 at new FirestoreError (node_modules/@firebase/firestore/dist/index.node.cjs.js:1205:28) at fromRpcStatus (node_modules/@firebase/firestore/dist/index.node.cjs.js:5240:12) at fromWatchChange (node_modules/@firebase/firestore/dist/index.node.cjs.js:5476:35) at PersistentListenStream.onMessage (node_modules/@firebase/firestore/dist/index.node.cjs.js:15743:27) at /home/roman/projects/asd/test/security_rules/node_modules/@firebase/firestore/dist/index.node.cjs.js:15676:30 at /home/roman/projects/asd/test/security_rules/node_modules/@firebase/firestore/dist/index.node.cjs.js:15712:28 at /home/roman/projects/asd/test/security_rules/node_modules/@firebase/firestore/dist/index.node.cjs.js:14143:20 at processTicksAndRejections (internal/process/task_queues.js:93:5)

rdinkel avatar Aug 26 '20 21:08 rdinkel

Thanks for filing the feature request. I've tracked this internally as b/166499006 for further triaging.

yuchenshi avatar Aug 26 '20 21:08 yuchenshi

Re-opening to make it easier for others to find and subscribe to this feature request.

yuchenshi avatar Aug 31 '20 17:08 yuchenshi

This will save new users a lot of time like me, who spent quite some time figuring why that error message was occuring.

bofeiw avatar Feb 09 '21 05:02 bofeiw

+1 for this, just spent ages trying to understand what false for get meant..

trullock avatar Feb 15 '21 20:02 trullock

+1

BossBele avatar Apr 29 '21 11:04 BossBele

+1

AlaeddineMessadi avatar Jan 20 '22 18:01 AlaeddineMessadi

+1

aezur avatar Jan 22 '22 15:01 aezur

+1 This would be very helpful

jaredforth avatar May 14 '24 18:05 jaredforth