firebase / quickstart-testing

Samples demonstrating how to test your Firebase app
Apache License 2.0
335 stars 93 forks source link

Request.auth != null always returns false when unit testing Firestore security rules using authenticatedContext #242

Closed angelocordero closed 2 years ago

angelocordero commented 2 years ago

This is the test code that fails

const alice = await testEnv.authenticatedContext('alice');
await assertFails(await getDoc(doc(await alice.firestore(), '/users/abc_123')));

Here is my security rules

  match /users/{userID} {
        allow read: if
          request.auth != null &&  // This is in line 7
          request.auth.uid == userID && 
          request.auth.uid == resource.data.userID;
      allow delete: if false;
    }

This is the log of the test that fails

Users tests
       should not allow users to read other user's data:
     FirebaseError: 
false for 'get' @ L7

Checking the request data using the firebase emulator suite, the request has an auth value. It is not null. request.auth != null SHOULD return true but it always return false no matter what.

 ➜ firebase --version
10.7.2

any ideas what could be the cause of this issue?