如何调试firestore.rules变量和函数? [英] How to debug firestore.rules variables and functions?

查看:78
本文介绍了如何调试firestore.rules变量和函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试诊断firestore.rules文件中的特定规则时遇到困难.有关上下文,请参见此处的问题.

I am having difficulty trying to diagnose a particular rule in my firestore.rules file. See that question here for context.

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

Is there a way to debug the firestore.rules file and/or functions? I'm using unit testing and the emulators to test my rules, but I would really love to see exactly what values are being evaluated by the rules engine.

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

For instance, here is my firestore.rules file:

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请求所返回的文档(如果有的话)以及返回值是什么.

What I'd love to do is set breakpoints or step through the code. When attempting CRUD operations on a organizations/{orgId}/classes/{classId}/students/{studentId} path I'd love to inspect exactly what values the orgId, classId, and studentId variables are holding, as well as the resource and request parameters. I'd love to inspect exactly which document (if any) is returned by the get request in belongsToCurrentClass and what the return value is.

有人知道这样做吗?如果我能看到正在评估的数据,我想在10秒内回答上面提到的问题.

Does anyone know of any way to do this? I think I'd answer my question referred to above in 10 seconds if I could just see the data being evaluated.

推荐答案

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

There is a local emulator for Cloud Firestore security rules. This is your best (and really only) tool for digging into security rule execution. There is no step-through debugging, but you can see a lot of debug output in the console.

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

这篇关于如何调试firestore.rules变量和函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆