title: Firebase Permission denied Error on Firebase emulator
body: <p>I am referencing this <a href="https://www.youtube.com/watch?v=8rRr9GnynR0" rel="nofollow noreferrer">tutorial</a> for Firestore security rules. I have extracted the code from the repository and it matches that of the video.
  I changed the <code>setup</code> code to run the <code>firestore.rules</code> instead of <code>firestore-test.rules</code>, and tried running <code>firebase emulators:start</code> and <code>jest ./spec</code> following the same directory structure, I fail the tests of <code>"should allow delete when user is admin"</code> and <code>"should not allow delete for normal user"</code> and the reason it is failing is due to the write rule in the wildcard. Does anyone know what is wrong?</p>
  
  <p><strong>collections.spec.js</strong></p>
  
  <pre><code>const { setup, teardown } = require("./helpers");
  
  
  describe("General Safety Rules", () =&gt; {
    afterEach(async () =&gt; {
      await teardown();
    });
  
    test("should deny a read to the posts collection", async () =&gt; {
      const db = await setup();
      const postsRef = db.collection("posts");
      await expect(postsRef.get()).toDeny();
    });
  
    test("should deny a write to users even when logged in", async () =&gt; {
      const db = await setup({
        uid: "danefilled"
      });
  
      const usersRef = db.collection("users");
      await expect(usersRef.add({ data: "something" })).toDeny();
    });
  });
  
  describe("Posts Rules", () =&gt; {
    afterEach(async () =&gt; {
      await teardown();
    });
  
    test("should allow update when user owns post", async () =&gt; {
      const mockData = {
        "posts/id1": {
          userId: "danefilled"
        },
        "posts/id2": {
          userId: "not_filledstacks"
        }
      };
  
      const mockUser = {
        uid: "danefilled"
      };
  
      const db = await setup(mockUser, mockData);
  
      const postsRef = db.collection("posts");
  
      await expect(
        postsRef.doc("id1").update({ updated: "new_value" })
      ).toAllow();
  
      await expect(postsRef.doc("id2").update({ updated: "new_value" })).toDeny();
    });
  
    test("should allow delete when user owns post", async () =&gt; {
      const mockData = {
        "posts/id1": {
          userId: "danefilled"
        },
        "posts/id2": {
          userId: "not_filledstacks"
        }
      };
  
      const mockUser = {
        uid: "danefilled"
      };
  
      const db = await setup(mockUser, mockData);
  
      const postsRef = db.collection("posts");
  
      await expect(postsRef.doc("id1").delete()).toAllow();
  
      await expect(postsRef.doc("id2").delete()).toDeny();
    });
  
    test("should allow delete when user is admin", async () =&gt; {
      const mockData = {
        "users/filledstacks": {
          userRole: "Admin"
        },
        "posts/id1": {
          userId: "not_matching1"
        },
        "posts/id2": {
          userId: "not_matching2"
        }
      };
  
      const mockUser = {
        uid: "filledstacks"
      };
  
      const db = await setup(mockUser, mockData);
  
      const postsRef = db.collection("posts");
  
      await expect(postsRef.doc("id1").delete()).toAllow();
    });
  
    test("should not allow delete for normal user", async () =&gt; {
      const mockData = {
        "users/filledstacks": {
          userRole: "User"
        },
        "posts/id1": {
          userId: "not_matching1"
        },
        "posts/id2": {
          userId: "not_matching2"
        }
      };
  
      const mockUser = {
        uid: "filledstacks"
      };
  
      const db = await setup(mockUser, mockData);
  
      const postsRef = db.collection("posts");
  
      await expect(postsRef.doc("id1").delete()).toDeny();
    });
  
    test("should allow adding a post when logged in", async () =&gt; {
      const db = await setup({
        uid: "userId"
      });
  
      const postsRef = db.collection("posts");
      await expect(postsRef.add({ title: "new_post" })).toAllow();
    });
  
    test("should deny adding a post when not logged in", async () =&gt; {
      const db = await setup();
      const postsRef = db.collection("posts");
      await expect(postsRef.add({ title: "new post" })).toDeny();
    });
  });
  </code></pre>
  
  <p><strong>firestore.rules</strong></p>
  
  <pre><code>rules_version = '2';
  service cloud.firestore {
    match /databases/{database}/documents {
  
  
  
      // lock down the db
      match /{document=**} {
        allow read: if false;
        allow write: if false;
      }
  
      match /posts/{postId} {
        allow update: if userOwnsPost();
        allow delete: if userOwnsPost() || userIsAdmin();
        allow create: if loggedIn();
      }
  
      function loggedIn() {
        return request.auth.uid != null;
      }
  
      function userIsAdmin() {
        return getUserData().userRole == 'Admin';
      }
  
      function getUserData() {
        return get(/databases/$(database)/documents/users/$(request.auth.uid)).data
      }
  
      function userOwnsPost() {
        return resource.data.userId == request.auth.uid;
      }
    }
  }
  </code></pre>
  
  <p><strong>Error trace from terminal</strong></p>
  
  <pre><code>FirebaseError: 7 PERMISSION_DENIED: 
  false for 'create' @ L10
  
  
    ● Posts Rules › should not allow delete for normal user
  
  FirebaseError: 7 PERMISSION_DENIED: 
  false for 'create' @ L10
  
    at new FirestoreError (/Users/../../../../../../../../../Resources/rules/node_modules/@firebase/firestore/src/util/error.ts:166:5)
    at ClientDuplexStream.&lt;anonymous&gt; (/Users/../../../../../../../../../Resources/rules/node_modules/@firebase/firestore/src/platform_node/grpc_connection.ts:240:13)
    at ClientDuplexStream._emitStatusIfDone (/Users/../../../../../../../../../Resources/rules/node_modules/grpc/src/client.js:234:12)
    at ClientDuplexStream._receiveStatus (/Users/../../../../../../../../../Resources/rules/node_modules/grpc/src/client.js:211:8)
    at Object.onReceiveStatus (/Users/../../../../../../../../../Resources/rules/node_modules/grpc/src/client_interceptors.js:1311:15)
    at InterceptingListener._callNext (/Users/../../../../../../../../../Resources/rules/node_modules/grpc/src/client_interceptors.js:568:42)
    at InterceptingListener.onReceiveStatus (/Users/../../../../../../../../../Resources/rules/node_modules/grpc/src/client_interceptors.js:618:8)
    at /Users/../../../../../../../../../Resources/rules/node_modules/grpc/src/client_interceptors.js:1127:18
  </code></pre>