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

Error message improvement for testing security rules #2577

Open
rdinkel opened this issue Aug 26, 2020 · 8 comments
Open

Error message improvement for testing security rules #2577

rdinkel opened this issue Aug 26, 2020 · 8 comments

Comments

@rdinkel
Copy link

rdinkel commented Aug 26, 2020

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: "abc@example.com"};

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)

@yuchenshi
Copy link
Member

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

@rdinkel rdinkel closed this as completed Aug 29, 2020
@yuchenshi
Copy link
Member

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

@yuchenshi yuchenshi reopened this Aug 31, 2020
@bofeiw
Copy link

bofeiw commented Feb 9, 2021

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

@trullock
Copy link

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

@BossBele
Copy link

+1

2 similar comments
@AlaeddineMessadi
Copy link

+1

@aezur
Copy link

aezur commented Jan 22, 2022

+1

@jaredforth
Copy link

jaredforth commented May 14, 2024

+1 This would be very helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants