如何调试firestore.rules变量和函数?

我在尝试诊断firestore.rules文件中的特定规则时遇到困难。有关上下文,请参见that question here

是否可以调试firestore.rules文件和/或功能?我正在使用单元测试和仿真器来测试我的规则,但是我真的很想知道规则引擎正在评估哪些值。

例如,这是我的firestore.rules文件:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /organizations/{orgId} {
      allow read: if isAdmin();
      allow create,update: if isAdmin();

      match /classes/{classId} {
        allow read: if request.auth.uid != null;
        allow create,update: if isAdmin();

        match /students/{studentId} {
          allow read: if isAdmin() || belongsToCurrentClass();
          allow create,update: if isAdmin();
        }
      }
    }
  }
}

function isAdmin() {
  // removed for security
}

function belongsToCurrentClass() {
  // retuns true if the authenticated user is the teacher of the requested class
  return get(/databases/$(database)/documents/organizations/$(orgId)/classes/$(classId)).data.teacherUid == request.auth.uid;
}

我想做的是设置断点或单步执行代码。当尝试在组织/ {orgId} / classes / {classId} / students / {studentId}路径上进行CRUD操作时,我希望检查一下orgId,classId和studentId变量所持有的确切值,以及资源和请求参数。我很想确切地检查belongsToCurrentClass中的get请求所返回的文档(如果有)以及返回值是什么。

有人知道有什么方法吗?如果我能看到正在评估的数据,我想在10秒内回答上面提到的问题。

chen192 回答:如何调试firestore.rules变量和函数?

有一个用于Cloud Firestore安全规则的本地模拟器。这是挖掘安全规则执行的最佳(也是唯一)工具。没有逐步调试功能,但是您可以在控制台中看到很多调试输出。

https://firebase.google.com/docs/rules/emulator-setup

本文链接:https://www.f2er.com/3126166.html

大家都在问