小编Spo*_*e44的帖子

@ firebase / testing-如何在Firestore规则测试中使用auth自定义声明?

我对Firestore Rules的所有测试几乎都不错。但是,我仍然需要测试管理员的一些路径。

我的应用程序中的管理员不是Firebase管理员,而是具有在customClaims中设置如下权限的用户:

claims: {admin: true}

如何使用npm软件包模拟用户customClaims @firebase/testing?我不知道。

谢谢

PS:下面,我正在做什么。

export default class TestApplication {

  public static getFirestoreInstance(auth, projectId: string): firebase.firestore.Firestore {
    return firebase
       .initializeTestApp({projectId, auth})
       .firestore();
  }
}


describe(){
    const defaultAuthUser = {uid: "alice", email: "alice@example.com", "token": {"admin": true};

    before(done => {
        currentProjectId = TestUtils.getRandomId();
        TestApplication.useFirestoreRules(currentProjectId, rules)
          .then(() => done())
          .catch(done);
    });

    it("I should be able to get another user if I'm an admin", () => {
      return firebase.assertSucceeds(
        TestApplication.getFirestoreInstance(defaultAuthUser, currentProjectId)
          .collection(FirebaseReference.USERS_REF)
          .doc(otherUserId)
          .get()
      );
    }).timeout(5000);
}
Run Code Online (Sandbox Code Playgroud)

testing firebase google-cloud-firestore firebase-security-rules

5
推荐指数
2
解决办法
878
查看次数