Snieder
Snieder

Reputation: 483

Firestore Rules coverage report - Request expression never evaluated

Recently I have been using firebase for my new app. Since you can define your own rules on firestore, I wanted to try that out.

To test these rules I am running the firestore emulator. When I try to authorize some test user I always get a timeout error. Wanting to solve the error by myself I've made some research.

I have found out that it is possible to see the "Firestore Rule Coverage Report" and inside there I've seen this:

Error message of Firestore Rule Coverage Report

But since I am new to firestore I did not know what this is and also after some googling I didn't find out how to solve this problem.

Upvotes: 9

Views: 599

Answers (4)

Bang
Bang

Reputation: 1132

I followed the examples from https://github.com/firebase/quickstart-testing . Bu two examples for security rules, only the example for version 8 at https://github.com/firebase/quickstart-testing/tree/master/unit-test-security-rules is working. Although I am using JS SDK v9, but using the example for version 8 can help me testing my security rules just fine.

Upvotes: 1

Nils Reichardt
Nils Reichardt

Reputation: 3589

My problem was that I executed loadFirestoreRules before every test. I changed it to run loadFirestoreRules only one time for all tests, and now it's working.

Upvotes: 1

D G
D G

Reputation: 598

I suspect the root of the problem is that the expression is throwing an error. If the user isn't authenticated then request.auth will be null (and therefore request.auth.uid will throw a null reference error).

Upvotes: 0

Jesus Iniesta
Jesus Iniesta

Reputation: 12499

Firestore docs are a bit confusing. They state that the URL should be:

http://localhost:8080/emulator/v1/projects/<database_name>:ruleCoverage.html

However, they don't explain what <database_name> should be replaced with your project_id. Yes... reading the URL some might thing is obvious, but is really the argument name that should make it obvious. Plus, in Firestore databases are not created neither accessed by name.

SOLUTION:

<database_name> should be replaced by your project_id (this value is available in the files .firebaserc or google-services.json

So, if your project_id is my-amazing-app, your rulesCoverage url would be: http://localhost:8080/emulator/v1/projects/my-amazing-app:ruleCoverage.html

Upvotes: 2

Related Questions