firebase - Can debug logging be added to firestore rules functions?
问题描述
Given that the firestore rules structure allows for functions, is there some way to add debug logs to those rule-functions ? .. in order to verify that the function you expect, is in fact being called.
I see that with the simulator it shows a red X at the line in the rules sturcture, where access is denied for a given simulation-request. However, am curious for verification in production mode so it can be communicated to parties concerned about the rules integrity.
In the example below, I was thinking it might be implemented with that commented-out line:
console.log('ENTER: isAccessOn()');
However this does not work. Asking here in case there's any option for something like this in the platform.. or if not, if there's a suggestion for how to make such verifications with a production deployment. Thanks
service cloud.firestore {
match /databases/{database}/documents {
// block client access
function isAccessOn() {
// console.log('ENTER: isAccessOn()');
return false;
}
match /{document=**} {
allow read, write: if isAccessOn();
}
}
}
解决方案
没有办法在生产中的安全规则中记录任何内容。如果您想验证您的规则是否按预期工作,您应该为它们编写一些集成测试并运行您的测试以确保根据您的规范拒绝或允许访问。
具体来说,您可能希望使用 Firebase CLI 研究本地规则模拟,这是 CLI 的全新功能。您可以使用带有debug()函数的模拟器进行简单的日志记录。
推荐阅读
- typescript - 将二进制字符串转换为打字稿中的标志
- wordpress - 如何使用 ACF 将其创建到 Wordpress 短代码中
- botframework - 在 Botframework 中为 Actions on Google 创建自定义适配器
- amazon-web-services - WEB页面上的AWS开/关切换器
- awk - 比较两个文件的列
- python-3.x - 如何将数据类型更改为 float64 以便 sklearn 可以处理数据大于 np.float32 的数据帧
- linux - Linux 上 ELF64 二进制文件的静态修补
- dita - 如何将插件 jar 添加到 DITA OT 类路径中?
- visual-studio-code - VSCode - 我如何完全关闭java?
- .net - 使用 Nunit 测试 JSON 字符串响应