问题描述
多亏了https://www.youtube.com/watch?v=VDulvfBpzZE的资源,我安装了Firestore模拟器和测试环境,除了我要测试以下规则时,一切都很好:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function invitationIsForMe(destemail) {
return request.auth.email == destemail;
}
match /invitations/{inviteId} {
allow read,delete: if invitationIsForMe(resource.destemail);
}
}
这会在测试中产生错误: FirebaseError: 在对象上未定义属性电子邮件。
测试如下:
const me = {uid: 'myuserid',email: 'me@foo.bar'};
const getDb = (auth) => {
return firebase.initializeTestApp({projectId: YORGA_PROJECT_ID,auth}).firestore();
}
describe('firestore structure and rules',() => {
it("Can read an invitation sent to me",async () => {
const db = getDb(me);
const testDoc = db.collection('invitations').where('destemail','==',me.email);
await firebase.assertSucceeds(testDoc.get());
})
}
如果我使用request.auth.uid对其进行测试,则可以正常工作(但这不是我要寻找的逻辑)。 所以我的问题是:这是Firestore模拟器的限制吗?我希望不是,而只是我,但是如果是这种情况,我认为在初始化测试基础时给出的带有uid和auth电子邮件的示例有点令人困惑,因此值得警告。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)