【问题标题】:Getting 'FirebaseError: Error compiling rules' on really simple rules definition in firebase emulator在 Firebase 模拟器中非常简单的规则定义中获取“FirebaseError:错误编译规则”
【发布时间】:2021-06-11 00:10:36
【问题描述】:

总结

我在尝试解析最简单的 firestore 规则时遇到错误。

鉴于它是如此简单,我不禁认为这可能是某种版本控制问题?但不确定。我试图更新 firebase 工具。我真的在 stackoverflow 和其他地方找不到任何类似的错误。

希望有人对此有一些想法?

firestore.rules

service cloud.firestore {
  match /databases/{database}/documents {
    match /users/{userID} {
      allow read, write: if request.auth != null;
    }
  }
}

尝试运行“npm test”/mocha 测试时模拟器解析 firestore.rules 时出错(请参阅下面的测试)

L5:11 Missing 'match' keyword before path.
L6:7 Unexpected 'allow'.
L6:7 mismatched input 'allow' expecting {'{', '/', PATH_SEGMENT}
L8:11 Missing 'match' keyword before path.
L9:7 Unexpected 'allow'.
L9:7 mismatched input 'allow' expecting {'{', '/', PATH_SEGMENT}
L9:28 Missing 'match' keyword before path.
L9:38 Forward slash '/' found where identifier or binding expected.
L9:39 mismatched input '$' expecting {'{', '/', PATH_SEGMENT}
L9:50 Missing 'match' keyword before path.
L9:66 Forward slash '/' found where identifier or binding expected.
L9:67 Unexpected '$'.
L9:68 Unexpected '{'.
L9:69 mismatched input 'request' expecting {'{', '/', PATH_SEGMENT}
L9:86 Unexpected ')'.
L15:1 Unexpected '}'.
      at new FirestoreError (node_modules\@firebase\firestore\dist\index.node.cjs.js:1205:28)
      at fromRpcStatus (node_modules\@firebase\firestore\dist\index.node.cjs.js:5240:12)
      at fromWatchChange (node_modules\@firebase\firestore\dist\index.node.cjs.js:5476:35)
      at PersistentListenStream.onMessage (node_modules\@firebase\firestore\dist\index.node.cjs.js:15743:27)
      at C:\files\react-learning\app-02\test\node_modules\@firebase\firestore\dist\index.node.cjs.js:15676:30
      at C:\files\react-learning\app-02\test\node_modules\@firebase\firestore\dist\index.node.cjs.js:15712:28
      at C:\files\react-learning\app-02\test\node_modules\@firebase\firestore\dist\index.node.cjs.js:14143:20
      at processTicksAndRejections (node:internal/process/task_queues:94:5)

单元测试正在运行

const firebase = require('@firebase/testing')

const MY_PROJECT_ID = 'my-app-id'

describe('my app', () => {

    it('can read users', async () => {

        const db = firebase.initializeTestApp(
            {
                projectId: MY_PROJECT_ID,
                auth: {
                    uid: '1231123', 
                    email: 'someemail@blah.com'
                }
            }
        ).firestore()

        const USER_ID = 'qnWc3u3UjowlF1PCVLSn'
        const testDoc = db.collection('users').doc(USER_ID)
        await firebase.assertSucceeds(testDoc.get())
    })
})

它在 'await firebase...' 行失败。

我期待什么

上面的firestore.rules被解析没有任何问题,这样mocha测试就可以运行了。

版本

火力基地 9.5.0

【问题讨论】:

    标签: firebase google-cloud-firestore firebase-security


    【解决方案1】:

    找到答案了。

    我需要阅读 Firestore 规则。

    失踪了。

    1. const fs = require('fs');在顶部,并且
    2. firebase.loadFirestoreRules({ 项目 ID:MY_PROJECT_ID, 规则:fs.readFileSync('../firestore.rules', 'utf8') }) ...在我尝试调用任何规则之前。

    很确定这不在来自 Google 的关于测试规则的 YouTube 视频中......但在文档中 => https://firebase.google.com/docs/rules/unit-tests 大约在页面下方的 2/3 处。

    【讨论】:

      猜你喜欢
      • 2018-01-20
      • 1970-01-01
      • 2016-03-13
      • 1970-01-01
      • 1970-01-01
      • 2021-12-16
      • 1970-01-01
      • 1970-01-01
      • 2018-04-16
      相关资源
      最近更新 更多