Skip to content

Commit 29e0be2

Browse files
authored
Fix RUTv2 not setting RTDB namespace by default. (#5501)
* Fix RUTv2 compat instances not working with modular. * Create fast-brooms-tie.md * Fix RUTv2 not setting RTDB namespace by default. * Create little-foxes-own.md
1 parent 46d26ff commit 29e0be2

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

.changeset/little-foxes-own.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@firebase/rules-unit-testing": patch
3+
---
4+
5+
Set RTDB namespace to be same as projectId by default instead of `${projectId}-default-rtdb`. This fixes rules not being applied and other issues related to namespace mismatch.

packages/rules-unit-testing/src/impl/test_environment.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,14 @@ class RulesTestContextImpl implements RulesTestContext {
192192
}
193193
database(databaseURL?: string): firebase.database.Database {
194194
assertEmulatorRunning(this.emulators, 'database');
195+
if (!databaseURL) {
196+
const url = makeUrl(this.emulators.database, '');
197+
// Make sure to set the namespace equal to projectId -- otherwise the RTDB SDK will by default
198+
// use `${projectId}-default-rtdb`, which is treated as a different DB by the RTDB emulator
199+
// (and thus WON'T apply any rules set for the `projectId` DB during initialization).
200+
url.searchParams.append('ns', this.projectId);
201+
databaseURL = url.toString();
202+
}
195203
const database = this.getApp().database(databaseURL);
196204
database.useEmulator(
197205
this.emulators.database.host,

0 commit comments

Comments
 (0)