不允许任何客户端用户写入 - Firebase 和 Mocha

如何解决不允许任何客户端用户写入 - Firebase 和 Mocha

我正在尝试使用 Firebase 安全规则创建单元测试。我不断收到以下错误

> test@1.0.0 test C:\Users\simeon.ramjit\Documents\projects\plant-order-form\test
> mocha --exit

  My cool app
Warning: FIRESTORE_EMULATOR_HOST not set,using default value localhost:8080    
    √ Understands basic addition
    1) Not allow any client side user to write to GLOBAL_DATA/DASH_DATA

  1 passing (2s)
  1 failing

  1) My cool app
       Not allow any client side user to write to GLOBAL_DATA/DASH_DATA:    
     Error: Timeout of 2000ms exceeded. For async tests and hooks,ensure "done()" is called; if returning a Promise,ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\plant-order-form\test\test.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processtimers (internal/timers.js:497:7)

npm ERR! Test Failed.  See above for more details.

使用 done() 不能解决问题,也不能设置更长的超时期限。下面是我的 test.js

const assert = require("assert");
const firebase = require("@firebase/rules-unit-testing");

const MY_PROJECT_ID = "example";
const idAdmin = "user_admin";
const adminAuth = { uid: idAdmin,email: "admin@example.com",admin: true };

function getFirestore(auth) {
  return firebase
    .initializeTestApp({ projectId: MY_PROJECT_ID,auth: auth })
    .firestore();
}

beforeEach(async () => {
  await firebase.clearFirestoreData({ projectId: MY_PROJECT_ID });
});

describe("My cool app",() => {
  it("Understands basic addition",() => {
    assert.strictEqual(2 + 2,4);
  });

  it("Not allow any client side user to write to GLOBAL_DATA/DASH_DATA",async () => {
    const db = getFirestore(adminAuth);
    const testDoc = db.collection('GLOBAL_DATA').doc('DASH_DATA');

    await firebase.assertFails(testDoc.get());
    

  })
});

after(async () => {
  await firebase.clearFirestoreData({ projectId: MY_PROJECT_ID });
});

下面是firebase emulators:start

的结果
PS C:\Users\simeon.ramjit\Documents\projects\plant-order-form> firebase emulators:start
i  emulators: Starting emulators: auth,functions,firestore
!  functions: The following emulators are not running,calls to these services from the Functions emulator will affect production: database,hosting,pubsub
!  Your requested "node" version "12" doesn't match your global version "14"
i  firestore: Firestore Emulator logging to firestore-debug.log
i  ui: Emulator UI logging to ui-debug.log
i  functions: Watching "C:\Users\simeon.ramjit\Documents\projects\plant-order-form\functions" for Cloud Functions...
+  functions[changeUserAuthorization]: http function initialized (http://localhost:5001/plant-order-form/us-central1/changeUserAuthorization).
+  functions[createuser]: http function initialized (http://localhost:5001/plant-order-form/us-central1/createuser).
+  functions[deleteUser]: http function initialized (http://localhost:5001/plant-order-form/us-central1/deleteUser).
+  functions[downloadItemPdf]: http function initialized (http://localhost:5001/plant-order-form/us-central1/downloadItemPdf).
+  functions[downloadReqssplit]: http function initialized (http://localhost:5001/plant-order-form/us-central1/downloadReqssplit).
+  functions[sendRepeatOrderStatusChangeEmail]: firestore function initialized.
+  functions[stripGeneralDataFromItemUpload]: firestore function initialized.
+  functions[sendEmailReciept]: firestore function initialized.
i  functions[updateItemDatabase]: function ignored because the storage emulator does not exist or is not running.
i  functions[scheduledFirestoreExport]: function ignored because the pubsub emulator does not exist or is not running.
+  functions[firestoreImport]: http function initialized (http://localhost:5001/plant-order-form/us-central1/firestoreImport).
+  functions[updateBlynkSevenC]: http function initialized (http://localhost:5001/plant-order-form/us-central1/updateBlynkSevenC).
+  functions[updateBlynkNineC]: http function initialized (http://localhost:5001/plant-order-form/us-central1/updateBlynkNineC).
+  functions[updateMachinestatus]: http function initialized (http://localhost:5001/plant-order-form/us-central1/updateMachinestatus).
+  functions[resetConversionMachineOrderDetails]: http function initialized (http://localhost:5001/plant-order-form/us-central1/resetConversionMachineOrderDetails).
+  functions[updateTimeStatusChanged]: http function initialized (http://localhost:5001/plant-order-form/us-central1/updateTimeStatusChanged).
i  functions[sendSixAmOrderSummary]: function ignored because the pubsub emulator does not exist or is not running.
i  functions[sendTwelvePmOrderSummary]: function ignored because the pubsub emulator does not exist or is not running.
+  functions[downloadBatchRequisition]: http function initialized (http://localhost:5001/plant-order-form/us-central1/downloadBatchRequisition).
+  functions[stripBatchNumber]: firestore function initialized.
i  functions[sendOrderScheduledSummary]: function ignored because the pubsub emulator does not exist or is not running.
+  functions[updateBlynkExtrusion]: firestore function initialized.
+  functions[downloadBtReq]: http function initialized (http://localhost:5001/plant-order-form/us-central1/downloadBtReq).
i  functions[sendScheduledBatchConfirmation]: function ignored because the pubsub emulator does not exist or is not running.
i  functions[updateMouldingItemDatabase]: function ignored because the storage emulator does not exist or is not running.
+  functions[sendMouldingSlackMessage]: firestore function initialized.
+  functions[sendDailyMouldingProductionUpdate]: http function initialized (http://localhost:5001/plant-order-form/us-central1/sendDailyMouldingProductionUpdate).
i  functions[uploadPriceList]: function ignored because the storage emulator does not exist or is not running.

┌─────────────────────────────────────────────────────────────┐
│ ✔  All emulators ready! It is Now safe to connect your app. │
│ i  View Emulator UI at http://localhost:4000                │
└─────────────────────────────────────────────────────────────┘

┌────────────────┬────────────────┬─────────────────────────────────┐
│ Emulator       │ Host:Port      │ View in Emulator UI             │
├────────────────┼────────────────┼─────────────────────────────────┤
│ Authentication │ localhost:9099 │ http://localhost:4000/auth      │
├────────────────┼────────────────┼─────────────────────────────────┤
│ Functions      │ localhost:5001 │ http://localhost:4000/functions │
├────────────────┼────────────────┼─────────────────────────────────┤
│ Firestore      │ localhost:8080 │ http://localhost:4000/firestore │
└────────────────┴────────────────┴─────────────────────────────────┘
  Emulator Hub running at localhost:4400
  Other reserved ports: 4500

Issues? Report them at https://github.com/firebase/firebase-tools/issues and attach the *-debug.log files.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?