@firebase/rules-unit-testing 4.0.1-canary.c8cbfff16 → 4.0.1-canary.cb19688bf
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.esm.js +16 -16
- package/dist/esm/index.esm.js.map +1 -1
- package/dist/esm/util/index.d.ts +1 -0
- package/dist/esm/util/src/emulator.d.ts +7 -0
- package/dist/esm/util/src/environment.d.ts +2 -0
- package/dist/esm/util/src/url.d.ts +27 -0
- package/dist/index.cjs.js +16 -16
- package/dist/index.cjs.js.map +1 -1
- package/dist/util/index.d.ts +1 -0
- package/dist/util/src/emulator.d.ts +7 -0
- package/dist/util/src/environment.d.ts +2 -0
- package/dist/util/src/url.d.ts +27 -0
- package/package.json +2 -2
package/dist/esm/index.esm.js
CHANGED
|
@@ -116,7 +116,6 @@ async function discoverEmulators(hub, fetchImpl = fetch) {
|
|
|
116
116
|
* @private
|
|
117
117
|
*/
|
|
118
118
|
function getEmulatorHostAndPort(emulator, conf, discovered) {
|
|
119
|
-
var _a, _b;
|
|
120
119
|
if (conf && ('host' in conf || 'port' in conf)) {
|
|
121
120
|
const { host, port } = conf;
|
|
122
121
|
if (host || port) {
|
|
@@ -129,20 +128,20 @@ function getEmulatorHostAndPort(emulator, conf, discovered) {
|
|
|
129
128
|
'reports it as not running. This may lead to errors such as connection refused.');
|
|
130
129
|
}
|
|
131
130
|
return {
|
|
132
|
-
host: fixHostname(host,
|
|
131
|
+
host: fixHostname(host, discovered?.hub?.host),
|
|
133
132
|
port: port
|
|
134
133
|
};
|
|
135
134
|
}
|
|
136
135
|
}
|
|
137
136
|
const envVar = EMULATOR_HOST_ENV_VARS[emulator];
|
|
138
|
-
const fallback =
|
|
137
|
+
const fallback = discovered?.[emulator] || emulatorFromEnvVar(envVar);
|
|
139
138
|
if (fallback) {
|
|
140
139
|
if (discovered && !discovered[emulator]) {
|
|
141
140
|
console.warn(`Warning: the environment variable ${envVar} is set, but the Emulator hub reports the ` +
|
|
142
141
|
`${emulator} emulator as not running. This may lead to errors such as connection refused.`);
|
|
143
142
|
}
|
|
144
143
|
return {
|
|
145
|
-
host: fixHostname(fallback.host,
|
|
144
|
+
host: fixHostname(fallback.host, discovered?.hub?.host),
|
|
146
145
|
port: fallback.port
|
|
147
146
|
};
|
|
148
147
|
}
|
|
@@ -163,7 +162,7 @@ function emulatorFromEnvVar(envVar) {
|
|
|
163
162
|
try {
|
|
164
163
|
parsed = new URL(`http://${hostAndPort}`);
|
|
165
164
|
}
|
|
166
|
-
catch
|
|
165
|
+
catch {
|
|
167
166
|
throw new Error(`Invalid format in environment variable ${envVar}=${hostAndPort} (expected host:port)`);
|
|
168
167
|
}
|
|
169
168
|
let host = parsed.hostname;
|
|
@@ -204,7 +203,11 @@ class RulesTestEnvironmentImpl {
|
|
|
204
203
|
}
|
|
205
204
|
authenticatedContext(user_id, tokenOptions) {
|
|
206
205
|
this.checkNotDestroyed();
|
|
207
|
-
return this.createContext(
|
|
206
|
+
return this.createContext({
|
|
207
|
+
...tokenOptions,
|
|
208
|
+
sub: user_id,
|
|
209
|
+
user_id: user_id
|
|
210
|
+
});
|
|
208
211
|
}
|
|
209
212
|
unauthenticatedContext() {
|
|
210
213
|
this.checkNotDestroyed();
|
|
@@ -289,9 +292,8 @@ class RulesTestContextImpl {
|
|
|
289
292
|
this.envDestroyed = false;
|
|
290
293
|
}
|
|
291
294
|
cleanup() {
|
|
292
|
-
var _a;
|
|
293
295
|
this.destroyed = true;
|
|
294
|
-
|
|
296
|
+
this.app?.delete();
|
|
295
297
|
this.app = undefined;
|
|
296
298
|
}
|
|
297
299
|
firestore(settings) {
|
|
@@ -458,14 +460,13 @@ async function loadStorageRules(hostAndPort, rules) {
|
|
|
458
460
|
* ```
|
|
459
461
|
*/
|
|
460
462
|
async function initializeTestEnvironment(config) {
|
|
461
|
-
var _a, _b, _c;
|
|
462
463
|
const projectId = config.projectId || process.env.GCLOUD_PROJECT;
|
|
463
464
|
if (!projectId) {
|
|
464
465
|
throw new Error('Missing projectId option or env var GCLOUD_PROJECT! Please specify the projectId either ' +
|
|
465
466
|
'way.\n(A demo-* projectId is strongly recommended for unit tests, such as "demo-test".)');
|
|
466
467
|
}
|
|
467
468
|
const hub = getEmulatorHostAndPort('hub', config.hub);
|
|
468
|
-
let discovered = hub ?
|
|
469
|
+
let discovered = hub ? { ...(await discoverEmulators(hub)), hub } : undefined;
|
|
469
470
|
const emulators = {};
|
|
470
471
|
if (hub) {
|
|
471
472
|
emulators.hub = hub;
|
|
@@ -476,15 +477,15 @@ async function initializeTestEnvironment(config) {
|
|
|
476
477
|
emulators[emulator] = hostAndPort;
|
|
477
478
|
}
|
|
478
479
|
}
|
|
479
|
-
if (
|
|
480
|
+
if (config.database?.rules) {
|
|
480
481
|
assertEmulatorRunning(emulators, 'database');
|
|
481
482
|
await loadDatabaseRules(emulators.database, projectId, config.database.rules);
|
|
482
483
|
}
|
|
483
|
-
if (
|
|
484
|
+
if (config.firestore?.rules) {
|
|
484
485
|
assertEmulatorRunning(emulators, 'firestore');
|
|
485
486
|
await loadFirestoreRules(emulators.firestore, projectId, config.firestore.rules);
|
|
486
487
|
}
|
|
487
|
-
if (
|
|
488
|
+
if (config.storage?.rules) {
|
|
488
489
|
assertEmulatorRunning(emulators, 'storage');
|
|
489
490
|
await loadStorageRules(emulators.storage, config.storage.rules);
|
|
490
491
|
}
|
|
@@ -570,9 +571,8 @@ function assertFails(pr) {
|
|
|
570
571
|
return pr.then(() => {
|
|
571
572
|
return Promise.reject(new Error('Expected request to fail, but it succeeded.'));
|
|
572
573
|
}, (err) => {
|
|
573
|
-
|
|
574
|
-
const
|
|
575
|
-
const errMessage = ((_b = err === null || err === void 0 ? void 0 : err.message) === null || _b === void 0 ? void 0 : _b.toLowerCase()) || '';
|
|
574
|
+
const errCode = err?.code?.toLowerCase() || '';
|
|
575
|
+
const errMessage = err?.message?.toLowerCase() || '';
|
|
576
576
|
const isPermissionDenied = errCode === 'permission-denied' ||
|
|
577
577
|
errCode === 'permission_denied' ||
|
|
578
578
|
errMessage.indexOf('permission_denied') >= 0 ||
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":["../../src/impl/url.ts","../../src/impl/discovery.ts","../../src/impl/test_environment.ts","../../src/impl/rules.ts","../../src/initialize.ts","../../src/util.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { HostAndPort } from '../public_types';\n\n/**\n * Return a connectable hostname, replacing wildcard 0.0.0.0 or :: with loopback\n * addresses 127.0.0.1 / ::1 correspondingly. See below for why this is needed:\n * https://github.com/firebase/firebase-tools-ui/issues/286\n *\n * This assumes emulators are running on the same device as fallbackHost (e.g.\n * hub), which should hold if both are started from the same CLI command.\n * @private\n */\nexport function fixHostname(host: string, fallbackHost?: string): string {\n host = host.replace('[', '').replace(']', ''); // Remove IPv6 brackets\n if (host === '0.0.0.0') {\n host = fallbackHost || '127.0.0.1';\n } else if (host === '::') {\n host = fallbackHost || '::1';\n }\n return host;\n}\n\n/**\n * Create a URL with host, port, and path. Handles IPv6 bracketing correctly.\n * @private\n */\nexport function makeUrl(hostAndPort: HostAndPort | string, path: string): URL {\n if (typeof hostAndPort === 'object') {\n const { host, port } = hostAndPort;\n if (host.includes(':')) {\n hostAndPort = `[${host}]:${port}`;\n } else {\n hostAndPort = `${host}:${port}`;\n }\n }\n const url = new URL(`http://${hostAndPort}/`);\n url.pathname = path;\n return url;\n}\n","/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { EmulatorConfig, HostAndPort } from '../public_types';\nimport { makeUrl, fixHostname } from './url';\n\n/**\n * Use the Firebase Emulator hub to discover other running emulators.\n *\n * @param hub the host and port where the Emulator Hub is running\n * @private\n */\nexport async function discoverEmulators(\n hub: HostAndPort,\n fetchImpl: typeof fetch = fetch\n): Promise<DiscoveredEmulators> {\n const res = await fetchImpl(makeUrl(hub, '/emulators'));\n if (!res.ok) {\n throw new Error(\n `HTTP Error ${res.status} when attempting to reach Emulator Hub at ${res.url}, are you sure it is running?`\n );\n }\n\n const emulators: DiscoveredEmulators = {};\n\n const data = await res.json();\n\n if (data.database) {\n emulators.database = {\n host: data.database.host,\n port: data.database.port\n };\n }\n\n if (data.firestore) {\n emulators.firestore = {\n host: data.firestore.host,\n port: data.firestore.port\n };\n }\n\n if (data.storage) {\n emulators.storage = {\n host: data.storage.host,\n port: data.storage.port\n };\n }\n\n if (data.hub) {\n emulators.hub = {\n host: data.hub.host,\n port: data.hub.port\n };\n }\n return emulators;\n}\n\n/**\n * @private\n */\nexport interface DiscoveredEmulators {\n database?: HostAndPort;\n firestore?: HostAndPort;\n storage?: HostAndPort;\n hub?: HostAndPort;\n}\n\n/**\n * @private\n */\nexport function getEmulatorHostAndPort(\n emulator: keyof DiscoveredEmulators,\n conf?: EmulatorConfig,\n discovered?: DiscoveredEmulators\n) {\n if (conf && ('host' in conf || 'port' in conf)) {\n const { host, port } = conf as any;\n if (host || port) {\n if (!host || !port) {\n throw new Error(\n `Invalid configuration ${emulator}.host=${host} and ${emulator}.port=${port}. ` +\n 'If either parameter is supplied, both must be defined.'\n );\n }\n if (discovered && !discovered[emulator]) {\n console.warn(\n `Warning: config for the ${emulator} emulator is specified, but the Emulator hub ` +\n 'reports it as not running. This may lead to errors such as connection refused.'\n );\n }\n return {\n host: fixHostname(host, discovered?.hub?.host),\n port: port\n };\n }\n }\n const envVar = EMULATOR_HOST_ENV_VARS[emulator];\n const fallback = discovered?.[emulator] || emulatorFromEnvVar(envVar);\n if (fallback) {\n if (discovered && !discovered[emulator]) {\n console.warn(\n `Warning: the environment variable ${envVar} is set, but the Emulator hub reports the ` +\n `${emulator} emulator as not running. This may lead to errors such as connection refused.`\n );\n }\n return {\n host: fixHostname(fallback.host, discovered?.hub?.host),\n port: fallback.port\n };\n }\n}\n\n// Visible for testing.\nexport const EMULATOR_HOST_ENV_VARS = {\n 'database': 'FIREBASE_DATABASE_EMULATOR_HOST',\n 'firestore': 'FIRESTORE_EMULATOR_HOST',\n 'hub': 'FIREBASE_EMULATOR_HUB',\n 'storage': 'FIREBASE_STORAGE_EMULATOR_HOST'\n};\n\nfunction emulatorFromEnvVar(envVar: string): HostAndPort | undefined {\n const hostAndPort = process.env[envVar];\n if (!hostAndPort) {\n return undefined;\n }\n\n let parsed: URL;\n try {\n parsed = new URL(`http://${hostAndPort}`);\n } catch {\n throw new Error(\n `Invalid format in environment variable ${envVar}=${hostAndPort} (expected host:port)`\n );\n }\n let host = parsed.hostname;\n const port = Number(parsed.port || '80');\n if (!Number.isInteger(port)) {\n throw new Error(\n `Invalid port in environment variable ${envVar}=${hostAndPort}`\n );\n }\n return { host, port };\n}\n","/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport firebase from 'firebase/compat/app';\nimport 'firebase/compat/firestore';\nimport 'firebase/compat/database';\nimport 'firebase/compat/storage';\n\nimport {\n HostAndPort,\n RulesTestContext,\n RulesTestEnvironment,\n TokenOptions\n} from '../public_types';\n\nimport { DiscoveredEmulators } from './discovery';\nimport { makeUrl } from './url';\n\n/**\n * An implementation of {@code RulesTestEnvironment}. This is private to hide the constructor,\n * which should never be directly called by the developer.\n * @private\n */\nexport class RulesTestEnvironmentImpl implements RulesTestEnvironment {\n private contexts = new Set<RulesTestContextImpl>();\n private destroyed = false;\n\n constructor(\n readonly projectId: string,\n readonly emulators: DiscoveredEmulators\n ) {}\n\n authenticatedContext(\n user_id: string,\n tokenOptions?: TokenOptions\n ): RulesTestContext {\n this.checkNotDestroyed();\n return this.createContext({\n ...tokenOptions,\n sub: user_id,\n user_id: user_id\n });\n }\n\n unauthenticatedContext(): RulesTestContext {\n this.checkNotDestroyed();\n return this.createContext(/* authToken = */ undefined);\n }\n\n async withSecurityRulesDisabled(\n callback: (context: RulesTestContext) => Promise<void>\n ): Promise<void> {\n this.checkNotDestroyed();\n // The \"owner\" token is recognized by the emulators as a special value that bypasses Security\n // Rules. This should only ever be used in withSecurityRulesDisabled.\n // If you're reading this and thinking about doing this in your own app / tests / scripts, think\n // twice. Instead, just use withSecurityRulesDisabled for unit testing OR connect your Firebase\n // Admin SDKs to the emulators for integration testing via environment variables.\n // See: https://firebase.google.com/docs/emulator-suite/connect_firestore#admin_sdks\n const context = this.createContext('owner');\n try {\n await callback(context);\n } finally {\n // We eagerly clean up this context to actively prevent misuse outside of the callback, e.g.\n // storing the context in a variable.\n context.cleanup();\n this.contexts.delete(context);\n }\n }\n\n private createContext(\n authToken: string | firebase.EmulatorMockTokenOptions | undefined\n ): RulesTestContextImpl {\n const context = new RulesTestContextImpl(\n this.projectId,\n this.emulators,\n authToken\n );\n this.contexts.add(context);\n return context;\n }\n\n clearDatabase(): Promise<void> {\n this.checkNotDestroyed();\n return this.withSecurityRulesDisabled(context => {\n return context.database().ref('/').set(null);\n });\n }\n\n async clearFirestore(): Promise<void> {\n this.checkNotDestroyed();\n assertEmulatorRunning(this.emulators, 'firestore');\n\n const resp = await fetch(\n makeUrl(\n this.emulators.firestore,\n `/emulator/v1/projects/${this.projectId}/databases/(default)/documents`\n ),\n {\n method: 'DELETE'\n }\n );\n\n if (!resp.ok) {\n throw new Error(await resp.text());\n }\n }\n\n clearStorage(): Promise<void> {\n this.checkNotDestroyed();\n return this.withSecurityRulesDisabled(async context => {\n const { items } = await context.storage().ref().listAll();\n await Promise.all(\n items.map((item: { delete: () => any }) => {\n return item.delete();\n })\n );\n });\n }\n\n async cleanup(): Promise<void> {\n this.destroyed = true;\n this.contexts.forEach(context => {\n context.envDestroyed = true;\n context.cleanup();\n });\n this.contexts.clear();\n }\n\n private checkNotDestroyed() {\n if (this.destroyed) {\n throw new Error(\n 'This RulesTestEnvironment has already been cleaned up. ' +\n '(This may indicate a leak or missing `await` in your test cases. If you do intend to ' +\n 'perform more tests, please call cleanup() later or create another RulesTestEnvironment.)'\n );\n }\n }\n}\n/**\n * An implementation of {@code RulesTestContext}. This is private to hide the constructor,\n * which should never be directly called by the developer.\n * @private\n */\nclass RulesTestContextImpl implements RulesTestContext {\n private app?: firebase.app.App;\n private destroyed = false;\n envDestroyed = false;\n\n constructor(\n readonly projectId: string,\n readonly emulators: DiscoveredEmulators,\n readonly authToken: firebase.EmulatorMockTokenOptions | string | undefined\n ) {}\n\n cleanup() {\n this.destroyed = true;\n this.app?.delete();\n\n this.app = undefined;\n }\n\n firestore(\n settings?: firebase.firestore.Settings\n ): firebase.firestore.Firestore {\n assertEmulatorRunning(this.emulators, 'firestore');\n const firestore = this.getApp().firestore();\n if (settings) {\n firestore.settings(settings);\n }\n firestore.useEmulator(\n this.emulators.firestore.host,\n this.emulators.firestore.port,\n { mockUserToken: this.authToken }\n );\n return firestore;\n }\n database(databaseURL?: string): firebase.database.Database {\n assertEmulatorRunning(this.emulators, 'database');\n if (!databaseURL) {\n const url = makeUrl(this.emulators.database, '');\n // Make sure to set the namespace equal to projectId -- otherwise the RTDB SDK will by default\n // use `${projectId}-default-rtdb`, which is treated as a different DB by the RTDB emulator\n // (and thus WON'T apply any rules set for the `projectId` DB during initialization).\n url.searchParams.append('ns', this.projectId);\n databaseURL = url.toString();\n }\n const database = this.getApp().database(databaseURL);\n database.useEmulator(\n this.emulators.database.host,\n this.emulators.database.port,\n { mockUserToken: this.authToken }\n );\n return database;\n }\n storage(bucketUrl = `gs://${this.projectId}`): firebase.storage.Storage {\n assertEmulatorRunning(this.emulators, 'storage');\n const storage = this.getApp().storage(bucketUrl);\n storage.useEmulator(\n this.emulators.storage.host,\n this.emulators.storage.port,\n { mockUserToken: this.authToken }\n );\n return storage;\n }\n\n private getApp(): firebase.app.App {\n if (this.envDestroyed) {\n throw new Error(\n 'This RulesTestContext is no longer valid because its RulesTestEnvironment has been ' +\n 'cleaned up. (This may indicate a leak or missing `await` in your test cases.)'\n );\n }\n if (this.destroyed) {\n throw new Error(\n 'This RulesTestContext is no longer valid. When using withSecurityRulesDisabled, ' +\n 'make sure to perform all operations on the context within the callback function and ' +\n 'return a Promise that resolves when the operations are done.'\n );\n }\n if (!this.app) {\n this.app = firebase.initializeApp(\n { projectId: this.projectId },\n `_Firebase_RulesUnitTesting_${Date.now()}_${Math.random()}`\n );\n }\n return this.app;\n }\n}\n\nexport function assertEmulatorRunning<E extends keyof DiscoveredEmulators>(\n emulators: DiscoveredEmulators,\n emulator: E\n): asserts emulators is Record<E, HostAndPort> {\n if (!emulators[emulator]) {\n if (emulators.hub) {\n throw new Error(\n `The ${emulator} emulator is not running (according to Emulator hub). To force ` +\n 'connecting anyway, please specify its host and port in initializeTestEnvironment({...}).'\n );\n } else {\n throw new Error(\n `The host and port of the ${emulator} emulator must be specified. (You may wrap the test ` +\n \"script with `firebase emulators:exec './your-test-script'` to enable automatic \" +\n `discovery, or specify manually via initializeTestEnvironment({${emulator}: {host, port}}).`\n );\n }\n }\n}\n","/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { HostAndPort } from '../public_types';\nimport { makeUrl } from './url';\n\n/**\n * @private\n */\nexport async function loadDatabaseRules(\n hostAndPort: HostAndPort,\n databaseName: string,\n rules: string\n): Promise<void> {\n const url = makeUrl(hostAndPort, '/.settings/rules.json');\n url.searchParams.append('ns', databaseName);\n const resp = await fetch(url, {\n method: 'PUT',\n headers: { Authorization: 'Bearer owner' },\n body: rules\n });\n\n if (!resp.ok) {\n throw new Error(await resp.text());\n }\n}\n\n/**\n * @private\n */\nexport async function loadFirestoreRules(\n hostAndPort: HostAndPort,\n projectId: string,\n rules: string\n): Promise<void> {\n const resp = await fetch(\n makeUrl(hostAndPort, `/emulator/v1/projects/${projectId}:securityRules`),\n {\n method: 'PUT',\n body: JSON.stringify({\n rules: {\n files: [{ content: rules }]\n }\n })\n }\n );\n\n if (!resp.ok) {\n throw new Error(await resp.text());\n }\n}\n\n/**\n * @private\n */\nexport async function loadStorageRules(\n hostAndPort: HostAndPort,\n rules: string\n): Promise<void> {\n const resp = await fetch(makeUrl(hostAndPort, '/internal/setRules'), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json'\n },\n body: JSON.stringify({\n rules: {\n files: [{ name: 'storage.rules', content: rules }]\n }\n })\n });\n if (!resp.ok) {\n throw new Error(await resp.text());\n }\n}\n","/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { RulesTestEnvironment, TestEnvironmentConfig } from './public_types';\nimport {\n DiscoveredEmulators,\n discoverEmulators,\n getEmulatorHostAndPort\n} from './impl/discovery';\nimport {\n assertEmulatorRunning,\n RulesTestEnvironmentImpl\n} from './impl/test_environment';\nimport {\n loadDatabaseRules,\n loadFirestoreRules,\n loadStorageRules\n} from './impl/rules';\n\n/**\n * Initializes a test environment for rules unit testing. Call this function first for test setup.\n *\n * Requires emulators to be running. This function tries to discover those emulators via environment\n * variables or through the Firebase Emulator hub if hosts and ports are unspecified. It is strongly\n * recommended to specify security rules for emulators used for testing. See minimal example below.\n *\n * @param config - the configuration for emulators. Most fields are optional if they can be discovered\n * @returns a promise that resolves with an environment ready for testing, or rejects on error.\n * @public\n * @example\n * ```javascript\n * const testEnv = await initializeTestEnvironment({\n * firestore: {\n * rules: fs.readFileSync(\"/path/to/firestore.rules\", \"utf8\"), // Load rules from file\n * // host and port can be omitted if they can be discovered from the hub.\n * },\n * // ...\n * });\n * ```\n */\nexport async function initializeTestEnvironment(\n config: TestEnvironmentConfig\n): Promise<RulesTestEnvironment> {\n const projectId = config.projectId || process.env.GCLOUD_PROJECT;\n if (!projectId) {\n throw new Error(\n 'Missing projectId option or env var GCLOUD_PROJECT! Please specify the projectId either ' +\n 'way.\\n(A demo-* projectId is strongly recommended for unit tests, such as \"demo-test\".)'\n );\n }\n const hub = getEmulatorHostAndPort('hub', config.hub);\n let discovered = hub ? { ...(await discoverEmulators(hub)), hub } : undefined;\n\n const emulators: DiscoveredEmulators = {};\n if (hub) {\n emulators.hub = hub;\n }\n\n for (const emulator of SUPPORTED_EMULATORS) {\n const hostAndPort = getEmulatorHostAndPort(\n emulator,\n config[emulator],\n discovered\n );\n if (hostAndPort) {\n emulators[emulator] = hostAndPort;\n }\n }\n\n if (config.database?.rules) {\n assertEmulatorRunning(emulators, 'database');\n await loadDatabaseRules(\n emulators.database,\n projectId,\n config.database.rules\n );\n }\n if (config.firestore?.rules) {\n assertEmulatorRunning(emulators, 'firestore');\n await loadFirestoreRules(\n emulators.firestore,\n projectId,\n config.firestore.rules\n );\n }\n if (config.storage?.rules) {\n assertEmulatorRunning(emulators, 'storage');\n await loadStorageRules(emulators.storage, config.storage.rules);\n }\n\n return new RulesTestEnvironmentImpl(projectId, emulators);\n}\n\nconst SUPPORTED_EMULATORS = ['database', 'firestore', 'storage'] as const;\n","/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n EMULATOR_HOST_ENV_VARS,\n getEmulatorHostAndPort\n} from './impl/discovery';\nimport { fixHostname, makeUrl } from './impl/url';\nimport { HostAndPort } from './public_types';\n\n/**\n * Run a setup function with background Cloud Functions triggers disabled. This can be used to\n * import data into the Realtime Database or Cloud Firestore emulator without triggering locally\n * emulated Cloud Functions.\n *\n * This method only works with Firebase CLI version 8.13.0 or higher. This overload works only if\n * the Emulator hub host:port is specified by the environment variable FIREBASE_EMULATOR_HUB.\n *\n * @param fn - a function which may be sync or async (returns a promise)\n * @public\n */\nexport async function withFunctionTriggersDisabled<TResult>(\n fn: () => TResult | Promise<TResult>\n): Promise<TResult>;\n\n/**\n * Run a setup function with background Cloud Functions triggers disabled. This can be used to\n * import data into the Realtime Database or Cloud Firestore emulator without triggering locally\n * emulated Cloud Functions.\n *\n * This method only works with Firebase CLI version 8.13.0 or higher. The Emulator hub must be\n * running, which host and port are specified in this overload.\n *\n * @param fn - a function which may be sync or async (returns a promise)\n * @param hub - the host and port of the Emulator Hub (ex: `{host: 'localhost', port: 4400}`)\n * @public\n */\nexport async function withFunctionTriggersDisabled<TResult>(\n hub: { host: string; port: number },\n fn: () => TResult | Promise<TResult>\n): Promise<TResult>;\n\nexport async function withFunctionTriggersDisabled<TResult>(\n fnOrHub: { host: string; port: number } | (() => TResult | Promise<TResult>),\n maybeFn?: () => TResult | Promise<TResult>\n): Promise<TResult> {\n let hub: HostAndPort | undefined;\n if (typeof fnOrHub === 'function') {\n maybeFn = fnOrHub;\n hub = getEmulatorHostAndPort('hub');\n } else {\n hub = getEmulatorHostAndPort('hub', fnOrHub);\n if (!maybeFn) {\n throw new Error('The callback function must be specified!');\n }\n }\n if (!hub) {\n throw new Error(\n 'Please specify the Emulator Hub host and port via arguments or set the environment ' +\n `variable ${EMULATOR_HOST_ENV_VARS.hub}!`\n );\n }\n\n hub.host = fixHostname(hub.host);\n makeUrl(hub, '/functions/disableBackgroundTriggers');\n // Disable background triggers\n const disableRes = await fetch(\n makeUrl(hub, '/functions/disableBackgroundTriggers'),\n {\n method: 'PUT'\n }\n );\n if (!disableRes.ok) {\n throw new Error(\n `HTTP Error ${disableRes.status} when disabling functions triggers, are you using firebase-tools 8.13.0 or higher?`\n );\n }\n\n // Run the user's function\n let result: TResult | undefined = undefined;\n try {\n result = await maybeFn();\n } finally {\n // Re-enable background triggers\n const enableRes = await fetch(\n makeUrl(hub, '/functions/enableBackgroundTriggers'),\n {\n method: 'PUT'\n }\n );\n\n if (!enableRes.ok) {\n throw new Error(\n `HTTP Error ${enableRes.status} when enabling functions triggers, are you using firebase-tools 8.13.0 or higher?`\n );\n }\n }\n\n // Return the user's function result\n return result;\n}\n\n/**\n * Assert the promise to be rejected with a \"permission denied\" error.\n *\n * Useful to assert a certain request to be denied by Security Rules. See example below.\n * This function recognizes permission-denied errors from Database, Firestore, and Storage JS SDKs.\n *\n * @param pr - the promise to be asserted\n * @returns a Promise that is fulfilled if pr is rejected with \"permission denied\". If pr is\n * rejected with any other error or resolved, the returned promise rejects.\n * @public\n * @example\n * ```javascript\n * const unauthed = testEnv.unauthenticatedContext();\n * await assertFails(get(doc(unauthed.firestore(), '/private/doc'), { ... });\n * ```\n */\nexport function assertFails(pr: Promise<any>): Promise<any> {\n return pr.then(\n () => {\n return Promise.reject(\n new Error('Expected request to fail, but it succeeded.')\n );\n },\n (err: any) => {\n const errCode = err?.code?.toLowerCase() || '';\n const errMessage = err?.message?.toLowerCase() || '';\n const isPermissionDenied =\n errCode === 'permission-denied' ||\n errCode === 'permission_denied' ||\n errMessage.indexOf('permission_denied') >= 0 ||\n errMessage.indexOf('permission denied') >= 0 ||\n // Storage permission errors contain message: (storage/unauthorized)\n errMessage.indexOf('unauthorized') >= 0;\n\n if (!isPermissionDenied) {\n return Promise.reject(\n new Error(\n `Expected PERMISSION_DENIED but got unexpected error: ${err}`\n )\n );\n }\n return err;\n }\n );\n}\n\n/**\n * Assert the promise to be successful.\n *\n * This is a no-op function returning the passed promise as-is, but can be used for documentational\n * purposes in test code to emphasize that a certain request should succeed (e.g. allowed by rules).\n *\n * @public\n * @example\n * ```javascript\n * const alice = testEnv.authenticatedContext('alice');\n * await assertSucceeds(get(doc(alice.firestore(), '/doc/readable/by/alice'), { ... });\n * ```\n */\nexport function assertSucceeds<T>(pr: Promise<T>): Promise<T> {\n return pr;\n}\n"],"names":[],"mappings":";;;;;AAAA;;;;;;;;;;;;;;;AAeG;AAIH;;;;;;;;AAQG;AACa,SAAA,WAAW,CAAC,IAAY,EAAE,YAAqB,EAAA;AAC7D,IAAA,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;AAC9C,IAAA,IAAI,IAAI,KAAK,SAAS,EAAE;AACtB,QAAA,IAAI,GAAG,YAAY,IAAI,WAAW,CAAC;KACpC;AAAM,SAAA,IAAI,I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P,CAAA,qDAAA,EAAwD,GAAG,CAAA,CAAE,CAC9D,CACF,CAAC;SACH;AACD,QAAA,OAAO,GAAG,CAAC;AACb,KAAC,CACF,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;AAYG;AACG,SAAU,cAAc,CAAI,EAAc,EAAA;AAC9C,IAAA,OAAO,EAAE,CAAC;AACZ;;;;"}
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../../src/impl/url.ts","../../src/impl/discovery.ts","../../src/impl/test_environment.ts","../../src/impl/rules.ts","../../src/initialize.ts","../../src/util.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { HostAndPort } from '../public_types';\n\n/**\n * Return a connectable hostname, replacing wildcard 0.0.0.0 or :: with loopback\n * addresses 127.0.0.1 / ::1 correspondingly. See below for why this is needed:\n * https://github.com/firebase/firebase-tools-ui/issues/286\n *\n * This assumes emulators are running on the same device as fallbackHost (e.g.\n * hub), which should hold if both are started from the same CLI command.\n * @private\n */\nexport function fixHostname(host: string, fallbackHost?: string): string {\n host = host.replace('[', '').replace(']', ''); // Remove IPv6 brackets\n if (host === '0.0.0.0') {\n host = fallbackHost || '127.0.0.1';\n } else if (host === '::') {\n host = fallbackHost || '::1';\n }\n return host;\n}\n\n/**\n * Create a URL with host, port, and path. Handles IPv6 bracketing correctly.\n * @private\n */\nexport function makeUrl(hostAndPort: HostAndPort | string, path: string): URL {\n if (typeof hostAndPort === 'object') {\n const { host, port } = hostAndPort;\n if (host.includes(':')) {\n hostAndPort = `[${host}]:${port}`;\n } else {\n hostAndPort = `${host}:${port}`;\n }\n }\n const url = new URL(`http://${hostAndPort}/`);\n url.pathname = path;\n return url;\n}\n","/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { EmulatorConfig, HostAndPort } from '../public_types';\nimport { makeUrl, fixHostname } from './url';\n\n/**\n * Use the Firebase Emulator hub to discover other running emulators.\n *\n * @param hub the host and port where the Emulator Hub is running\n * @private\n */\nexport async function discoverEmulators(\n hub: HostAndPort,\n fetchImpl: typeof fetch = fetch\n): Promise<DiscoveredEmulators> {\n const res = await fetchImpl(makeUrl(hub, '/emulators'));\n if (!res.ok) {\n throw new Error(\n `HTTP Error ${res.status} when attempting to reach Emulator Hub at ${res.url}, are you sure it is running?`\n );\n }\n\n const emulators: DiscoveredEmulators = {};\n\n const data = await res.json();\n\n if (data.database) {\n emulators.database = {\n host: data.database.host,\n port: data.database.port\n };\n }\n\n if (data.firestore) {\n emulators.firestore = {\n host: data.firestore.host,\n port: data.firestore.port\n };\n }\n\n if (data.storage) {\n emulators.storage = {\n host: data.storage.host,\n port: data.storage.port\n };\n }\n\n if (data.hub) {\n emulators.hub = {\n host: data.hub.host,\n port: data.hub.port\n };\n }\n return emulators;\n}\n\n/**\n * @private\n */\nexport interface DiscoveredEmulators {\n database?: HostAndPort;\n firestore?: HostAndPort;\n storage?: HostAndPort;\n hub?: HostAndPort;\n}\n\n/**\n * @private\n */\nexport function getEmulatorHostAndPort(\n emulator: keyof DiscoveredEmulators,\n conf?: EmulatorConfig,\n discovered?: DiscoveredEmulators\n) {\n if (conf && ('host' in conf || 'port' in conf)) {\n const { host, port } = conf as any;\n if (host || port) {\n if (!host || !port) {\n throw new Error(\n `Invalid configuration ${emulator}.host=${host} and ${emulator}.port=${port}. ` +\n 'If either parameter is supplied, both must be defined.'\n );\n }\n if (discovered && !discovered[emulator]) {\n console.warn(\n `Warning: config for the ${emulator} emulator is specified, but the Emulator hub ` +\n 'reports it as not running. This may lead to errors such as connection refused.'\n );\n }\n return {\n host: fixHostname(host, discovered?.hub?.host),\n port: port\n };\n }\n }\n const envVar = EMULATOR_HOST_ENV_VARS[emulator];\n const fallback = discovered?.[emulator] || emulatorFromEnvVar(envVar);\n if (fallback) {\n if (discovered && !discovered[emulator]) {\n console.warn(\n `Warning: the environment variable ${envVar} is set, but the Emulator hub reports the ` +\n `${emulator} emulator as not running. This may lead to errors such as connection refused.`\n );\n }\n return {\n host: fixHostname(fallback.host, discovered?.hub?.host),\n port: fallback.port\n };\n }\n}\n\n// Visible for testing.\nexport const EMULATOR_HOST_ENV_VARS = {\n 'database': 'FIREBASE_DATABASE_EMULATOR_HOST',\n 'firestore': 'FIRESTORE_EMULATOR_HOST',\n 'hub': 'FIREBASE_EMULATOR_HUB',\n 'storage': 'FIREBASE_STORAGE_EMULATOR_HOST'\n};\n\nfunction emulatorFromEnvVar(envVar: string): HostAndPort | undefined {\n const hostAndPort = process.env[envVar];\n if (!hostAndPort) {\n return undefined;\n }\n\n let parsed: URL;\n try {\n parsed = new URL(`http://${hostAndPort}`);\n } catch {\n throw new Error(\n `Invalid format in environment variable ${envVar}=${hostAndPort} (expected host:port)`\n );\n }\n let host = parsed.hostname;\n const port = Number(parsed.port || '80');\n if (!Number.isInteger(port)) {\n throw new Error(\n `Invalid port in environment variable ${envVar}=${hostAndPort}`\n );\n }\n return { host, port };\n}\n","/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport firebase from 'firebase/compat/app';\nimport 'firebase/compat/firestore';\nimport 'firebase/compat/database';\nimport 'firebase/compat/storage';\n\nimport {\n HostAndPort,\n RulesTestContext,\n RulesTestEnvironment,\n TokenOptions\n} from '../public_types';\n\nimport { DiscoveredEmulators } from './discovery';\nimport { makeUrl } from './url';\n\n/**\n * An implementation of {@code RulesTestEnvironment}. This is private to hide the constructor,\n * which should never be directly called by the developer.\n * @private\n */\nexport class RulesTestEnvironmentImpl implements RulesTestEnvironment {\n private contexts = new Set<RulesTestContextImpl>();\n private destroyed = false;\n\n constructor(\n readonly projectId: string,\n readonly emulators: DiscoveredEmulators\n ) {}\n\n authenticatedContext(\n user_id: string,\n tokenOptions?: TokenOptions\n ): RulesTestContext {\n this.checkNotDestroyed();\n return this.createContext({\n ...tokenOptions,\n sub: user_id,\n user_id: user_id\n });\n }\n\n unauthenticatedContext(): RulesTestContext {\n this.checkNotDestroyed();\n return this.createContext(/* authToken = */ undefined);\n }\n\n async withSecurityRulesDisabled(\n callback: (context: RulesTestContext) => Promise<void>\n ): Promise<void> {\n this.checkNotDestroyed();\n // The \"owner\" token is recognized by the emulators as a special value that bypasses Security\n // Rules. This should only ever be used in withSecurityRulesDisabled.\n // If you're reading this and thinking about doing this in your own app / tests / scripts, think\n // twice. Instead, just use withSecurityRulesDisabled for unit testing OR connect your Firebase\n // Admin SDKs to the emulators for integration testing via environment variables.\n // See: https://firebase.google.com/docs/emulator-suite/connect_firestore#admin_sdks\n const context = this.createContext('owner');\n try {\n await callback(context);\n } finally {\n // We eagerly clean up this context to actively prevent misuse outside of the callback, e.g.\n // storing the context in a variable.\n context.cleanup();\n this.contexts.delete(context);\n }\n }\n\n private createContext(\n authToken: string | firebase.EmulatorMockTokenOptions | undefined\n ): RulesTestContextImpl {\n const context = new RulesTestContextImpl(\n this.projectId,\n this.emulators,\n authToken\n );\n this.contexts.add(context);\n return context;\n }\n\n clearDatabase(): Promise<void> {\n this.checkNotDestroyed();\n return this.withSecurityRulesDisabled(context => {\n return context.database().ref('/').set(null);\n });\n }\n\n async clearFirestore(): Promise<void> {\n this.checkNotDestroyed();\n assertEmulatorRunning(this.emulators, 'firestore');\n\n const resp = await fetch(\n makeUrl(\n this.emulators.firestore,\n `/emulator/v1/projects/${this.projectId}/databases/(default)/documents`\n ),\n {\n method: 'DELETE'\n }\n );\n\n if (!resp.ok) {\n throw new Error(await resp.text());\n }\n }\n\n clearStorage(): Promise<void> {\n this.checkNotDestroyed();\n return this.withSecurityRulesDisabled(async context => {\n const { items } = await context.storage().ref().listAll();\n await Promise.all(\n items.map((item: { delete: () => any }) => {\n return item.delete();\n })\n );\n });\n }\n\n async cleanup(): Promise<void> {\n this.destroyed = true;\n this.contexts.forEach(context => {\n context.envDestroyed = true;\n context.cleanup();\n });\n this.contexts.clear();\n }\n\n private checkNotDestroyed() {\n if (this.destroyed) {\n throw new Error(\n 'This RulesTestEnvironment has already been cleaned up. ' +\n '(This may indicate a leak or missing `await` in your test cases. If you do intend to ' +\n 'perform more tests, please call cleanup() later or create another RulesTestEnvironment.)'\n );\n }\n }\n}\n/**\n * An implementation of {@code RulesTestContext}. This is private to hide the constructor,\n * which should never be directly called by the developer.\n * @private\n */\nclass RulesTestContextImpl implements RulesTestContext {\n private app?: firebase.app.App;\n private destroyed = false;\n envDestroyed = false;\n\n constructor(\n readonly projectId: string,\n readonly emulators: DiscoveredEmulators,\n readonly authToken: firebase.EmulatorMockTokenOptions | string | undefined\n ) {}\n\n cleanup() {\n this.destroyed = true;\n this.app?.delete();\n\n this.app = undefined;\n }\n\n firestore(\n settings?: firebase.firestore.Settings\n ): firebase.firestore.Firestore {\n assertEmulatorRunning(this.emulators, 'firestore');\n const firestore = this.getApp().firestore();\n if (settings) {\n firestore.settings(settings);\n }\n firestore.useEmulator(\n this.emulators.firestore.host,\n this.emulators.firestore.port,\n { mockUserToken: this.authToken }\n );\n return firestore;\n }\n database(databaseURL?: string): firebase.database.Database {\n assertEmulatorRunning(this.emulators, 'database');\n if (!databaseURL) {\n const url = makeUrl(this.emulators.database, '');\n // Make sure to set the namespace equal to projectId -- otherwise the RTDB SDK will by default\n // use `${projectId}-default-rtdb`, which is treated as a different DB by the RTDB emulator\n // (and thus WON'T apply any rules set for the `projectId` DB during initialization).\n url.searchParams.append('ns', this.projectId);\n databaseURL = url.toString();\n }\n const database = this.getApp().database(databaseURL);\n database.useEmulator(\n this.emulators.database.host,\n this.emulators.database.port,\n { mockUserToken: this.authToken }\n );\n return database;\n }\n storage(bucketUrl = `gs://${this.projectId}`): firebase.storage.Storage {\n assertEmulatorRunning(this.emulators, 'storage');\n const storage = this.getApp().storage(bucketUrl);\n storage.useEmulator(\n this.emulators.storage.host,\n this.emulators.storage.port,\n { mockUserToken: this.authToken }\n );\n return storage;\n }\n\n private getApp(): firebase.app.App {\n if (this.envDestroyed) {\n throw new Error(\n 'This RulesTestContext is no longer valid because its RulesTestEnvironment has been ' +\n 'cleaned up. (This may indicate a leak or missing `await` in your test cases.)'\n );\n }\n if (this.destroyed) {\n throw new Error(\n 'This RulesTestContext is no longer valid. When using withSecurityRulesDisabled, ' +\n 'make sure to perform all operations on the context within the callback function and ' +\n 'return a Promise that resolves when the operations are done.'\n );\n }\n if (!this.app) {\n this.app = firebase.initializeApp(\n { projectId: this.projectId },\n `_Firebase_RulesUnitTesting_${Date.now()}_${Math.random()}`\n );\n }\n return this.app;\n }\n}\n\nexport function assertEmulatorRunning<E extends keyof DiscoveredEmulators>(\n emulators: DiscoveredEmulators,\n emulator: E\n): asserts emulators is Record<E, HostAndPort> {\n if (!emulators[emulator]) {\n if (emulators.hub) {\n throw new Error(\n `The ${emulator} emulator is not running (according to Emulator hub). To force ` +\n 'connecting anyway, please specify its host and port in initializeTestEnvironment({...}).'\n );\n } else {\n throw new Error(\n `The host and port of the ${emulator} emulator must be specified. (You may wrap the test ` +\n \"script with `firebase emulators:exec './your-test-script'` to enable automatic \" +\n `discovery, or specify manually via initializeTestEnvironment({${emulator}: {host, port}}).`\n );\n }\n }\n}\n","/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { HostAndPort } from '../public_types';\nimport { makeUrl } from './url';\n\n/**\n * @private\n */\nexport async function loadDatabaseRules(\n hostAndPort: HostAndPort,\n databaseName: string,\n rules: string\n): Promise<void> {\n const url = makeUrl(hostAndPort, '/.settings/rules.json');\n url.searchParams.append('ns', databaseName);\n const resp = await fetch(url, {\n method: 'PUT',\n headers: { Authorization: 'Bearer owner' },\n body: rules\n });\n\n if (!resp.ok) {\n throw new Error(await resp.text());\n }\n}\n\n/**\n * @private\n */\nexport async function loadFirestoreRules(\n hostAndPort: HostAndPort,\n projectId: string,\n rules: string\n): Promise<void> {\n const resp = await fetch(\n makeUrl(hostAndPort, `/emulator/v1/projects/${projectId}:securityRules`),\n {\n method: 'PUT',\n body: JSON.stringify({\n rules: {\n files: [{ content: rules }]\n }\n })\n }\n );\n\n if (!resp.ok) {\n throw new Error(await resp.text());\n }\n}\n\n/**\n * @private\n */\nexport async function loadStorageRules(\n hostAndPort: HostAndPort,\n rules: string\n): Promise<void> {\n const resp = await fetch(makeUrl(hostAndPort, '/internal/setRules'), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json'\n },\n body: JSON.stringify({\n rules: {\n files: [{ name: 'storage.rules', content: rules }]\n }\n })\n });\n if (!resp.ok) {\n throw new Error(await resp.text());\n }\n}\n","/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { RulesTestEnvironment, TestEnvironmentConfig } from './public_types';\nimport {\n DiscoveredEmulators,\n discoverEmulators,\n getEmulatorHostAndPort\n} from './impl/discovery';\nimport {\n assertEmulatorRunning,\n RulesTestEnvironmentImpl\n} from './impl/test_environment';\nimport {\n loadDatabaseRules,\n loadFirestoreRules,\n loadStorageRules\n} from './impl/rules';\n\n/**\n * Initializes a test environment for rules unit testing. Call this function first for test setup.\n *\n * Requires emulators to be running. This function tries to discover those emulators via environment\n * variables or through the Firebase Emulator hub if hosts and ports are unspecified. It is strongly\n * recommended to specify security rules for emulators used for testing. See minimal example below.\n *\n * @param config - the configuration for emulators. Most fields are optional if they can be discovered\n * @returns a promise that resolves with an environment ready for testing, or rejects on error.\n * @public\n * @example\n * ```javascript\n * const testEnv = await initializeTestEnvironment({\n * firestore: {\n * rules: fs.readFileSync(\"/path/to/firestore.rules\", \"utf8\"), // Load rules from file\n * // host and port can be omitted if they can be discovered from the hub.\n * },\n * // ...\n * });\n * ```\n */\nexport async function initializeTestEnvironment(\n config: TestEnvironmentConfig\n): Promise<RulesTestEnvironment> {\n const projectId = config.projectId || process.env.GCLOUD_PROJECT;\n if (!projectId) {\n throw new Error(\n 'Missing projectId option or env var GCLOUD_PROJECT! Please specify the projectId either ' +\n 'way.\\n(A demo-* projectId is strongly recommended for unit tests, such as \"demo-test\".)'\n );\n }\n const hub = getEmulatorHostAndPort('hub', config.hub);\n let discovered = hub ? { ...(await discoverEmulators(hub)), hub } : undefined;\n\n const emulators: DiscoveredEmulators = {};\n if (hub) {\n emulators.hub = hub;\n }\n\n for (const emulator of SUPPORTED_EMULATORS) {\n const hostAndPort = getEmulatorHostAndPort(\n emulator,\n config[emulator],\n discovered\n );\n if (hostAndPort) {\n emulators[emulator] = hostAndPort;\n }\n }\n\n if (config.database?.rules) {\n assertEmulatorRunning(emulators, 'database');\n await loadDatabaseRules(\n emulators.database,\n projectId,\n config.database.rules\n );\n }\n if (config.firestore?.rules) {\n assertEmulatorRunning(emulators, 'firestore');\n await loadFirestoreRules(\n emulators.firestore,\n projectId,\n config.firestore.rules\n );\n }\n if (config.storage?.rules) {\n assertEmulatorRunning(emulators, 'storage');\n await loadStorageRules(emulators.storage, config.storage.rules);\n }\n\n return new RulesTestEnvironmentImpl(projectId, emulators);\n}\n\nconst SUPPORTED_EMULATORS = ['database', 'firestore', 'storage'] as const;\n","/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n EMULATOR_HOST_ENV_VARS,\n getEmulatorHostAndPort\n} from './impl/discovery';\nimport { fixHostname, makeUrl } from './impl/url';\nimport { HostAndPort } from './public_types';\n\n/**\n * Run a setup function with background Cloud Functions triggers disabled. This can be used to\n * import data into the Realtime Database or Cloud Firestore emulator without triggering locally\n * emulated Cloud Functions.\n *\n * This method only works with Firebase CLI version 8.13.0 or higher. This overload works only if\n * the Emulator hub host:port is specified by the environment variable FIREBASE_EMULATOR_HUB.\n *\n * @param fn - a function which may be sync or async (returns a promise)\n * @public\n */\nexport async function withFunctionTriggersDisabled<TResult>(\n fn: () => TResult | Promise<TResult>\n): Promise<TResult>;\n\n/**\n * Run a setup function with background Cloud Functions triggers disabled. This can be used to\n * import data into the Realtime Database or Cloud Firestore emulator without triggering locally\n * emulated Cloud Functions.\n *\n * This method only works with Firebase CLI version 8.13.0 or higher. The Emulator hub must be\n * running, which host and port are specified in this overload.\n *\n * @param fn - a function which may be sync or async (returns a promise)\n * @param hub - the host and port of the Emulator Hub (ex: `{host: 'localhost', port: 4400}`)\n * @public\n */\nexport async function withFunctionTriggersDisabled<TResult>(\n hub: { host: string; port: number },\n fn: () => TResult | Promise<TResult>\n): Promise<TResult>;\n\nexport async function withFunctionTriggersDisabled<TResult>(\n fnOrHub: { host: string; port: number } | (() => TResult | Promise<TResult>),\n maybeFn?: () => TResult | Promise<TResult>\n): Promise<TResult> {\n let hub: HostAndPort | undefined;\n if (typeof fnOrHub === 'function') {\n maybeFn = fnOrHub;\n hub = getEmulatorHostAndPort('hub');\n } else {\n hub = getEmulatorHostAndPort('hub', fnOrHub);\n if (!maybeFn) {\n throw new Error('The callback function must be specified!');\n }\n }\n if (!hub) {\n throw new Error(\n 'Please specify the Emulator Hub host and port via arguments or set the environment ' +\n `variable ${EMULATOR_HOST_ENV_VARS.hub}!`\n );\n }\n\n hub.host = fixHostname(hub.host);\n makeUrl(hub, '/functions/disableBackgroundTriggers');\n // Disable background triggers\n const disableRes = await fetch(\n makeUrl(hub, '/functions/disableBackgroundTriggers'),\n {\n method: 'PUT'\n }\n );\n if (!disableRes.ok) {\n throw new Error(\n `HTTP Error ${disableRes.status} when disabling functions triggers, are you using firebase-tools 8.13.0 or higher?`\n );\n }\n\n // Run the user's function\n let result: TResult | undefined = undefined;\n try {\n result = await maybeFn();\n } finally {\n // Re-enable background triggers\n const enableRes = await fetch(\n makeUrl(hub, '/functions/enableBackgroundTriggers'),\n {\n method: 'PUT'\n }\n );\n\n if (!enableRes.ok) {\n throw new Error(\n `HTTP Error ${enableRes.status} when enabling functions triggers, are you using firebase-tools 8.13.0 or higher?`\n );\n }\n }\n\n // Return the user's function result\n return result;\n}\n\n/**\n * Assert the promise to be rejected with a \"permission denied\" error.\n *\n * Useful to assert a certain request to be denied by Security Rules. See example below.\n * This function recognizes permission-denied errors from Database, Firestore, and Storage JS SDKs.\n *\n * @param pr - the promise to be asserted\n * @returns a Promise that is fulfilled if pr is rejected with \"permission denied\". If pr is\n * rejected with any other error or resolved, the returned promise rejects.\n * @public\n * @example\n * ```javascript\n * const unauthed = testEnv.unauthenticatedContext();\n * await assertFails(get(doc(unauthed.firestore(), '/private/doc'), { ... });\n * ```\n */\nexport function assertFails(pr: Promise<any>): Promise<any> {\n return pr.then(\n () => {\n return Promise.reject(\n new Error('Expected request to fail, but it succeeded.')\n );\n },\n (err: any) => {\n const errCode = err?.code?.toLowerCase() || '';\n const errMessage = err?.message?.toLowerCase() || '';\n const isPermissionDenied =\n errCode === 'permission-denied' ||\n errCode === 'permission_denied' ||\n errMessage.indexOf('permission_denied') >= 0 ||\n errMessage.indexOf('permission denied') >= 0 ||\n // Storage permission errors contain message: (storage/unauthorized)\n errMessage.indexOf('unauthorized') >= 0;\n\n if (!isPermissionDenied) {\n return Promise.reject(\n new Error(\n `Expected PERMISSION_DENIED but got unexpected error: ${err}`\n )\n );\n }\n return err;\n }\n );\n}\n\n/**\n * Assert the promise to be successful.\n *\n * This is a no-op function returning the passed promise as-is, but can be used for documentational\n * purposes in test code to emphasize that a certain request should succeed (e.g. allowed by rules).\n *\n * @public\n * @example\n * ```javascript\n * const alice = testEnv.authenticatedContext('alice');\n * await assertSucceeds(get(doc(alice.firestore(), '/doc/readable/by/alice'), { ... });\n * ```\n */\nexport function assertSucceeds<T>(pr: Promise<T>): Promise<T> {\n return pr;\n}\n"],"names":[],"mappings":";;;;;AAAA;;;;;;;;;;;;;;;AAeG;AAIH;;;;;;;;AAQG;AACa,SAAA,WAAW,CAAC,IAAY,EAAE,YAAqB,EAAA;AAC7D,IAAA,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,EA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AAC,IAAI,CAAC;AAC5C,YAAA,UAAU,CAAC,OAAO,CAAC,mBAAmB,CAAC,IAAI,CAAC;;AAE5C,YAAA,UAAU,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAE1C,IAAI,CAAC,kBAAkB,EAAE;AACvB,YAAA,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,KAAK,CACP,CAAA,qDAAA,EAAwD,GAAG,CAAA,CAAE,CAC9D,CACF,CAAC;SACH;AACD,QAAA,OAAO,GAAG,CAAC;AACb,KAAC,CACF,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;AAYG;AACG,SAAU,cAAc,CAAI,EAAc,EAAA;AAC9C,IAAA,OAAO,EAAE,CAAC;AACZ;;;;"}
|
package/dist/esm/util/index.d.ts
CHANGED
|
@@ -44,4 +44,11 @@ export type EmulatorMockTokenOptions = ({
|
|
|
44
44
|
sub: string;
|
|
45
45
|
}) & Partial<FirebaseIdToken>;
|
|
46
46
|
export declare function createMockUserToken(token: EmulatorMockTokenOptions, projectId?: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* Updates Emulator Banner. Primarily used for Firebase Studio
|
|
49
|
+
* @param name
|
|
50
|
+
* @param isRunningEmulator
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
export declare function updateEmulatorBanner(name: string, isRunningEmulator: boolean): void;
|
|
47
54
|
export {};
|
|
@@ -69,6 +69,8 @@ export declare function isUWP(): boolean;
|
|
|
69
69
|
export declare function isNodeSdk(): boolean;
|
|
70
70
|
/** Returns true if we are running in Safari. */
|
|
71
71
|
export declare function isSafari(): boolean;
|
|
72
|
+
/** Returns true if we are running in Safari or WebKit */
|
|
73
|
+
export declare function isSafariOrWebkit(): boolean;
|
|
72
74
|
/**
|
|
73
75
|
* This method checks if indexedDB is supported by current browser/service worker context
|
|
74
76
|
* @return true if indexedDB is supported by current browser/service worker context
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Checks whether host is a cloud workstation or not.
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export declare function isCloudWorkstation(url: string): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Makes a fetch request to the given server.
|
|
24
|
+
* Mostly used for forwarding cookies in Firebase Studio.
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
export declare function pingServer(endpoint: string): Promise<boolean>;
|
package/dist/index.cjs.js
CHANGED
|
@@ -124,7 +124,6 @@ async function discoverEmulators(hub, fetchImpl = fetch) {
|
|
|
124
124
|
* @private
|
|
125
125
|
*/
|
|
126
126
|
function getEmulatorHostAndPort(emulator, conf, discovered) {
|
|
127
|
-
var _a, _b;
|
|
128
127
|
if (conf && ('host' in conf || 'port' in conf)) {
|
|
129
128
|
const { host, port } = conf;
|
|
130
129
|
if (host || port) {
|
|
@@ -137,20 +136,20 @@ function getEmulatorHostAndPort(emulator, conf, discovered) {
|
|
|
137
136
|
'reports it as not running. This may lead to errors such as connection refused.');
|
|
138
137
|
}
|
|
139
138
|
return {
|
|
140
|
-
host: fixHostname(host,
|
|
139
|
+
host: fixHostname(host, discovered?.hub?.host),
|
|
141
140
|
port: port
|
|
142
141
|
};
|
|
143
142
|
}
|
|
144
143
|
}
|
|
145
144
|
const envVar = EMULATOR_HOST_ENV_VARS[emulator];
|
|
146
|
-
const fallback =
|
|
145
|
+
const fallback = discovered?.[emulator] || emulatorFromEnvVar(envVar);
|
|
147
146
|
if (fallback) {
|
|
148
147
|
if (discovered && !discovered[emulator]) {
|
|
149
148
|
console.warn(`Warning: the environment variable ${envVar} is set, but the Emulator hub reports the ` +
|
|
150
149
|
`${emulator} emulator as not running. This may lead to errors such as connection refused.`);
|
|
151
150
|
}
|
|
152
151
|
return {
|
|
153
|
-
host: fixHostname(fallback.host,
|
|
152
|
+
host: fixHostname(fallback.host, discovered?.hub?.host),
|
|
154
153
|
port: fallback.port
|
|
155
154
|
};
|
|
156
155
|
}
|
|
@@ -171,7 +170,7 @@ function emulatorFromEnvVar(envVar) {
|
|
|
171
170
|
try {
|
|
172
171
|
parsed = new URL(`http://${hostAndPort}`);
|
|
173
172
|
}
|
|
174
|
-
catch
|
|
173
|
+
catch {
|
|
175
174
|
throw new Error(`Invalid format in environment variable ${envVar}=${hostAndPort} (expected host:port)`);
|
|
176
175
|
}
|
|
177
176
|
let host = parsed.hostname;
|
|
@@ -212,7 +211,11 @@ class RulesTestEnvironmentImpl {
|
|
|
212
211
|
}
|
|
213
212
|
authenticatedContext(user_id, tokenOptions) {
|
|
214
213
|
this.checkNotDestroyed();
|
|
215
|
-
return this.createContext(
|
|
214
|
+
return this.createContext({
|
|
215
|
+
...tokenOptions,
|
|
216
|
+
sub: user_id,
|
|
217
|
+
user_id: user_id
|
|
218
|
+
});
|
|
216
219
|
}
|
|
217
220
|
unauthenticatedContext() {
|
|
218
221
|
this.checkNotDestroyed();
|
|
@@ -297,9 +300,8 @@ class RulesTestContextImpl {
|
|
|
297
300
|
this.envDestroyed = false;
|
|
298
301
|
}
|
|
299
302
|
cleanup() {
|
|
300
|
-
var _a;
|
|
301
303
|
this.destroyed = true;
|
|
302
|
-
|
|
304
|
+
this.app?.delete();
|
|
303
305
|
this.app = undefined;
|
|
304
306
|
}
|
|
305
307
|
firestore(settings) {
|
|
@@ -466,14 +468,13 @@ async function loadStorageRules(hostAndPort, rules) {
|
|
|
466
468
|
* ```
|
|
467
469
|
*/
|
|
468
470
|
async function initializeTestEnvironment(config) {
|
|
469
|
-
var _a, _b, _c;
|
|
470
471
|
const projectId = config.projectId || process.env.GCLOUD_PROJECT;
|
|
471
472
|
if (!projectId) {
|
|
472
473
|
throw new Error('Missing projectId option or env var GCLOUD_PROJECT! Please specify the projectId either ' +
|
|
473
474
|
'way.\n(A demo-* projectId is strongly recommended for unit tests, such as "demo-test".)');
|
|
474
475
|
}
|
|
475
476
|
const hub = getEmulatorHostAndPort('hub', config.hub);
|
|
476
|
-
let discovered = hub ?
|
|
477
|
+
let discovered = hub ? { ...(await discoverEmulators(hub)), hub } : undefined;
|
|
477
478
|
const emulators = {};
|
|
478
479
|
if (hub) {
|
|
479
480
|
emulators.hub = hub;
|
|
@@ -484,15 +485,15 @@ async function initializeTestEnvironment(config) {
|
|
|
484
485
|
emulators[emulator] = hostAndPort;
|
|
485
486
|
}
|
|
486
487
|
}
|
|
487
|
-
if (
|
|
488
|
+
if (config.database?.rules) {
|
|
488
489
|
assertEmulatorRunning(emulators, 'database');
|
|
489
490
|
await loadDatabaseRules(emulators.database, projectId, config.database.rules);
|
|
490
491
|
}
|
|
491
|
-
if (
|
|
492
|
+
if (config.firestore?.rules) {
|
|
492
493
|
assertEmulatorRunning(emulators, 'firestore');
|
|
493
494
|
await loadFirestoreRules(emulators.firestore, projectId, config.firestore.rules);
|
|
494
495
|
}
|
|
495
|
-
if (
|
|
496
|
+
if (config.storage?.rules) {
|
|
496
497
|
assertEmulatorRunning(emulators, 'storage');
|
|
497
498
|
await loadStorageRules(emulators.storage, config.storage.rules);
|
|
498
499
|
}
|
|
@@ -578,9 +579,8 @@ function assertFails(pr) {
|
|
|
578
579
|
return pr.then(() => {
|
|
579
580
|
return Promise.reject(new Error('Expected request to fail, but it succeeded.'));
|
|
580
581
|
}, (err) => {
|
|
581
|
-
|
|
582
|
-
const
|
|
583
|
-
const errMessage = ((_b = err === null || err === void 0 ? void 0 : err.message) === null || _b === void 0 ? void 0 : _b.toLowerCase()) || '';
|
|
582
|
+
const errCode = err?.code?.toLowerCase() || '';
|
|
583
|
+
const errMessage = err?.message?.toLowerCase() || '';
|
|
584
584
|
const isPermissionDenied = errCode === 'permission-denied' ||
|
|
585
585
|
errCode === 'permission_denied' ||
|
|
586
586
|
errMessage.indexOf('permission_denied') >= 0 ||
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../src/impl/url.ts","../src/impl/discovery.ts","../src/impl/test_environment.ts","../src/impl/rules.ts","../src/initialize.ts","../src/util.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { HostAndPort } from '../public_types';\n\n/**\n * Return a connectable hostname, replacing wildcard 0.0.0.0 or :: with loopback\n * addresses 127.0.0.1 / ::1 correspondingly. See below for why this is needed:\n * https://github.com/firebase/firebase-tools-ui/issues/286\n *\n * This assumes emulators are running on the same device as fallbackHost (e.g.\n * hub), which should hold if both are started from the same CLI command.\n * @private\n */\nexport function fixHostname(host: string, fallbackHost?: string): string {\n host = host.replace('[', '').replace(']', ''); // Remove IPv6 brackets\n if (host === '0.0.0.0') {\n host = fallbackHost || '127.0.0.1';\n } else if (host === '::') {\n host = fallbackHost || '::1';\n }\n return host;\n}\n\n/**\n * Create a URL with host, port, and path. Handles IPv6 bracketing correctly.\n * @private\n */\nexport function makeUrl(hostAndPort: HostAndPort | string, path: string): URL {\n if (typeof hostAndPort === 'object') {\n const { host, port } = hostAndPort;\n if (host.includes(':')) {\n hostAndPort = `[${host}]:${port}`;\n } else {\n hostAndPort = `${host}:${port}`;\n }\n }\n const url = new URL(`http://${hostAndPort}/`);\n url.pathname = path;\n return url;\n}\n","/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { EmulatorConfig, HostAndPort } from '../public_types';\nimport { makeUrl, fixHostname } from './url';\n\n/**\n * Use the Firebase Emulator hub to discover other running emulators.\n *\n * @param hub the host and port where the Emulator Hub is running\n * @private\n */\nexport async function discoverEmulators(\n hub: HostAndPort,\n fetchImpl: typeof fetch = fetch\n): Promise<DiscoveredEmulators> {\n const res = await fetchImpl(makeUrl(hub, '/emulators'));\n if (!res.ok) {\n throw new Error(\n `HTTP Error ${res.status} when attempting to reach Emulator Hub at ${res.url}, are you sure it is running?`\n );\n }\n\n const emulators: DiscoveredEmulators = {};\n\n const data = await res.json();\n\n if (data.database) {\n emulators.database = {\n host: data.database.host,\n port: data.database.port\n };\n }\n\n if (data.firestore) {\n emulators.firestore = {\n host: data.firestore.host,\n port: data.firestore.port\n };\n }\n\n if (data.storage) {\n emulators.storage = {\n host: data.storage.host,\n port: data.storage.port\n };\n }\n\n if (data.hub) {\n emulators.hub = {\n host: data.hub.host,\n port: data.hub.port\n };\n }\n return emulators;\n}\n\n/**\n * @private\n */\nexport interface DiscoveredEmulators {\n database?: HostAndPort;\n firestore?: HostAndPort;\n storage?: HostAndPort;\n hub?: HostAndPort;\n}\n\n/**\n * @private\n */\nexport function getEmulatorHostAndPort(\n emulator: keyof DiscoveredEmulators,\n conf?: EmulatorConfig,\n discovered?: DiscoveredEmulators\n) {\n if (conf && ('host' in conf || 'port' in conf)) {\n const { host, port } = conf as any;\n if (host || port) {\n if (!host || !port) {\n throw new Error(\n `Invalid configuration ${emulator}.host=${host} and ${emulator}.port=${port}. ` +\n 'If either parameter is supplied, both must be defined.'\n );\n }\n if (discovered && !discovered[emulator]) {\n console.warn(\n `Warning: config for the ${emulator} emulator is specified, but the Emulator hub ` +\n 'reports it as not running. This may lead to errors such as connection refused.'\n );\n }\n return {\n host: fixHostname(host, discovered?.hub?.host),\n port: port\n };\n }\n }\n const envVar = EMULATOR_HOST_ENV_VARS[emulator];\n const fallback = discovered?.[emulator] || emulatorFromEnvVar(envVar);\n if (fallback) {\n if (discovered && !discovered[emulator]) {\n console.warn(\n `Warning: the environment variable ${envVar} is set, but the Emulator hub reports the ` +\n `${emulator} emulator as not running. This may lead to errors such as connection refused.`\n );\n }\n return {\n host: fixHostname(fallback.host, discovered?.hub?.host),\n port: fallback.port\n };\n }\n}\n\n// Visible for testing.\nexport const EMULATOR_HOST_ENV_VARS = {\n 'database': 'FIREBASE_DATABASE_EMULATOR_HOST',\n 'firestore': 'FIRESTORE_EMULATOR_HOST',\n 'hub': 'FIREBASE_EMULATOR_HUB',\n 'storage': 'FIREBASE_STORAGE_EMULATOR_HOST'\n};\n\nfunction emulatorFromEnvVar(envVar: string): HostAndPort | undefined {\n const hostAndPort = process.env[envVar];\n if (!hostAndPort) {\n return undefined;\n }\n\n let parsed: URL;\n try {\n parsed = new URL(`http://${hostAndPort}`);\n } catch {\n throw new Error(\n `Invalid format in environment variable ${envVar}=${hostAndPort} (expected host:port)`\n );\n }\n let host = parsed.hostname;\n const port = Number(parsed.port || '80');\n if (!Number.isInteger(port)) {\n throw new Error(\n `Invalid port in environment variable ${envVar}=${hostAndPort}`\n );\n }\n return { host, port };\n}\n","/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport firebase from 'firebase/compat/app';\nimport 'firebase/compat/firestore';\nimport 'firebase/compat/database';\nimport 'firebase/compat/storage';\n\nimport {\n HostAndPort,\n RulesTestContext,\n RulesTestEnvironment,\n TokenOptions\n} from '../public_types';\n\nimport { DiscoveredEmulators } from './discovery';\nimport { makeUrl } from './url';\n\n/**\n * An implementation of {@code RulesTestEnvironment}. This is private to hide the constructor,\n * which should never be directly called by the developer.\n * @private\n */\nexport class RulesTestEnvironmentImpl implements RulesTestEnvironment {\n private contexts = new Set<RulesTestContextImpl>();\n private destroyed = false;\n\n constructor(\n readonly projectId: string,\n readonly emulators: DiscoveredEmulators\n ) {}\n\n authenticatedContext(\n user_id: string,\n tokenOptions?: TokenOptions\n ): RulesTestContext {\n this.checkNotDestroyed();\n return this.createContext({\n ...tokenOptions,\n sub: user_id,\n user_id: user_id\n });\n }\n\n unauthenticatedContext(): RulesTestContext {\n this.checkNotDestroyed();\n return this.createContext(/* authToken = */ undefined);\n }\n\n async withSecurityRulesDisabled(\n callback: (context: RulesTestContext) => Promise<void>\n ): Promise<void> {\n this.checkNotDestroyed();\n // The \"owner\" token is recognized by the emulators as a special value that bypasses Security\n // Rules. This should only ever be used in withSecurityRulesDisabled.\n // If you're reading this and thinking about doing this in your own app / tests / scripts, think\n // twice. Instead, just use withSecurityRulesDisabled for unit testing OR connect your Firebase\n // Admin SDKs to the emulators for integration testing via environment variables.\n // See: https://firebase.google.com/docs/emulator-suite/connect_firestore#admin_sdks\n const context = this.createContext('owner');\n try {\n await callback(context);\n } finally {\n // We eagerly clean up this context to actively prevent misuse outside of the callback, e.g.\n // storing the context in a variable.\n context.cleanup();\n this.contexts.delete(context);\n }\n }\n\n private createContext(\n authToken: string | firebase.EmulatorMockTokenOptions | undefined\n ): RulesTestContextImpl {\n const context = new RulesTestContextImpl(\n this.projectId,\n this.emulators,\n authToken\n );\n this.contexts.add(context);\n return context;\n }\n\n clearDatabase(): Promise<void> {\n this.checkNotDestroyed();\n return this.withSecurityRulesDisabled(context => {\n return context.database().ref('/').set(null);\n });\n }\n\n async clearFirestore(): Promise<void> {\n this.checkNotDestroyed();\n assertEmulatorRunning(this.emulators, 'firestore');\n\n const resp = await fetch(\n makeUrl(\n this.emulators.firestore,\n `/emulator/v1/projects/${this.projectId}/databases/(default)/documents`\n ),\n {\n method: 'DELETE'\n }\n );\n\n if (!resp.ok) {\n throw new Error(await resp.text());\n }\n }\n\n clearStorage(): Promise<void> {\n this.checkNotDestroyed();\n return this.withSecurityRulesDisabled(async context => {\n const { items } = await context.storage().ref().listAll();\n await Promise.all(\n items.map((item: { delete: () => any }) => {\n return item.delete();\n })\n );\n });\n }\n\n async cleanup(): Promise<void> {\n this.destroyed = true;\n this.contexts.forEach(context => {\n context.envDestroyed = true;\n context.cleanup();\n });\n this.contexts.clear();\n }\n\n private checkNotDestroyed() {\n if (this.destroyed) {\n throw new Error(\n 'This RulesTestEnvironment has already been cleaned up. ' +\n '(This may indicate a leak or missing `await` in your test cases. If you do intend to ' +\n 'perform more tests, please call cleanup() later or create another RulesTestEnvironment.)'\n );\n }\n }\n}\n/**\n * An implementation of {@code RulesTestContext}. This is private to hide the constructor,\n * which should never be directly called by the developer.\n * @private\n */\nclass RulesTestContextImpl implements RulesTestContext {\n private app?: firebase.app.App;\n private destroyed = false;\n envDestroyed = false;\n\n constructor(\n readonly projectId: string,\n readonly emulators: DiscoveredEmulators,\n readonly authToken: firebase.EmulatorMockTokenOptions | string | undefined\n ) {}\n\n cleanup() {\n this.destroyed = true;\n this.app?.delete();\n\n this.app = undefined;\n }\n\n firestore(\n settings?: firebase.firestore.Settings\n ): firebase.firestore.Firestore {\n assertEmulatorRunning(this.emulators, 'firestore');\n const firestore = this.getApp().firestore();\n if (settings) {\n firestore.settings(settings);\n }\n firestore.useEmulator(\n this.emulators.firestore.host,\n this.emulators.firestore.port,\n { mockUserToken: this.authToken }\n );\n return firestore;\n }\n database(databaseURL?: string): firebase.database.Database {\n assertEmulatorRunning(this.emulators, 'database');\n if (!databaseURL) {\n const url = makeUrl(this.emulators.database, '');\n // Make sure to set the namespace equal to projectId -- otherwise the RTDB SDK will by default\n // use `${projectId}-default-rtdb`, which is treated as a different DB by the RTDB emulator\n // (and thus WON'T apply any rules set for the `projectId` DB during initialization).\n url.searchParams.append('ns', this.projectId);\n databaseURL = url.toString();\n }\n const database = this.getApp().database(databaseURL);\n database.useEmulator(\n this.emulators.database.host,\n this.emulators.database.port,\n { mockUserToken: this.authToken }\n );\n return database;\n }\n storage(bucketUrl = `gs://${this.projectId}`): firebase.storage.Storage {\n assertEmulatorRunning(this.emulators, 'storage');\n const storage = this.getApp().storage(bucketUrl);\n storage.useEmulator(\n this.emulators.storage.host,\n this.emulators.storage.port,\n { mockUserToken: this.authToken }\n );\n return storage;\n }\n\n private getApp(): firebase.app.App {\n if (this.envDestroyed) {\n throw new Error(\n 'This RulesTestContext is no longer valid because its RulesTestEnvironment has been ' +\n 'cleaned up. (This may indicate a leak or missing `await` in your test cases.)'\n );\n }\n if (this.destroyed) {\n throw new Error(\n 'This RulesTestContext is no longer valid. When using withSecurityRulesDisabled, ' +\n 'make sure to perform all operations on the context within the callback function and ' +\n 'return a Promise that resolves when the operations are done.'\n );\n }\n if (!this.app) {\n this.app = firebase.initializeApp(\n { projectId: this.projectId },\n `_Firebase_RulesUnitTesting_${Date.now()}_${Math.random()}`\n );\n }\n return this.app;\n }\n}\n\nexport function assertEmulatorRunning<E extends keyof DiscoveredEmulators>(\n emulators: DiscoveredEmulators,\n emulator: E\n): asserts emulators is Record<E, HostAndPort> {\n if (!emulators[emulator]) {\n if (emulators.hub) {\n throw new Error(\n `The ${emulator} emulator is not running (according to Emulator hub). To force ` +\n 'connecting anyway, please specify its host and port in initializeTestEnvironment({...}).'\n );\n } else {\n throw new Error(\n `The host and port of the ${emulator} emulator must be specified. (You may wrap the test ` +\n \"script with `firebase emulators:exec './your-test-script'` to enable automatic \" +\n `discovery, or specify manually via initializeTestEnvironment({${emulator}: {host, port}}).`\n );\n }\n }\n}\n","/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { HostAndPort } from '../public_types';\nimport { makeUrl } from './url';\n\n/**\n * @private\n */\nexport async function loadDatabaseRules(\n hostAndPort: HostAndPort,\n databaseName: string,\n rules: string\n): Promise<void> {\n const url = makeUrl(hostAndPort, '/.settings/rules.json');\n url.searchParams.append('ns', databaseName);\n const resp = await fetch(url, {\n method: 'PUT',\n headers: { Authorization: 'Bearer owner' },\n body: rules\n });\n\n if (!resp.ok) {\n throw new Error(await resp.text());\n }\n}\n\n/**\n * @private\n */\nexport async function loadFirestoreRules(\n hostAndPort: HostAndPort,\n projectId: string,\n rules: string\n): Promise<void> {\n const resp = await fetch(\n makeUrl(hostAndPort, `/emulator/v1/projects/${projectId}:securityRules`),\n {\n method: 'PUT',\n body: JSON.stringify({\n rules: {\n files: [{ content: rules }]\n }\n })\n }\n );\n\n if (!resp.ok) {\n throw new Error(await resp.text());\n }\n}\n\n/**\n * @private\n */\nexport async function loadStorageRules(\n hostAndPort: HostAndPort,\n rules: string\n): Promise<void> {\n const resp = await fetch(makeUrl(hostAndPort, '/internal/setRules'), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json'\n },\n body: JSON.stringify({\n rules: {\n files: [{ name: 'storage.rules', content: rules }]\n }\n })\n });\n if (!resp.ok) {\n throw new Error(await resp.text());\n }\n}\n","/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { RulesTestEnvironment, TestEnvironmentConfig } from './public_types';\nimport {\n DiscoveredEmulators,\n discoverEmulators,\n getEmulatorHostAndPort\n} from './impl/discovery';\nimport {\n assertEmulatorRunning,\n RulesTestEnvironmentImpl\n} from './impl/test_environment';\nimport {\n loadDatabaseRules,\n loadFirestoreRules,\n loadStorageRules\n} from './impl/rules';\n\n/**\n * Initializes a test environment for rules unit testing. Call this function first for test setup.\n *\n * Requires emulators to be running. This function tries to discover those emulators via environment\n * variables or through the Firebase Emulator hub if hosts and ports are unspecified. It is strongly\n * recommended to specify security rules for emulators used for testing. See minimal example below.\n *\n * @param config - the configuration for emulators. Most fields are optional if they can be discovered\n * @returns a promise that resolves with an environment ready for testing, or rejects on error.\n * @public\n * @example\n * ```javascript\n * const testEnv = await initializeTestEnvironment({\n * firestore: {\n * rules: fs.readFileSync(\"/path/to/firestore.rules\", \"utf8\"), // Load rules from file\n * // host and port can be omitted if they can be discovered from the hub.\n * },\n * // ...\n * });\n * ```\n */\nexport async function initializeTestEnvironment(\n config: TestEnvironmentConfig\n): Promise<RulesTestEnvironment> {\n const projectId = config.projectId || process.env.GCLOUD_PROJECT;\n if (!projectId) {\n throw new Error(\n 'Missing projectId option or env var GCLOUD_PROJECT! Please specify the projectId either ' +\n 'way.\\n(A demo-* projectId is strongly recommended for unit tests, such as \"demo-test\".)'\n );\n }\n const hub = getEmulatorHostAndPort('hub', config.hub);\n let discovered = hub ? { ...(await discoverEmulators(hub)), hub } : undefined;\n\n const emulators: DiscoveredEmulators = {};\n if (hub) {\n emulators.hub = hub;\n }\n\n for (const emulator of SUPPORTED_EMULATORS) {\n const hostAndPort = getEmulatorHostAndPort(\n emulator,\n config[emulator],\n discovered\n );\n if (hostAndPort) {\n emulators[emulator] = hostAndPort;\n }\n }\n\n if (config.database?.rules) {\n assertEmulatorRunning(emulators, 'database');\n await loadDatabaseRules(\n emulators.database,\n projectId,\n config.database.rules\n );\n }\n if (config.firestore?.rules) {\n assertEmulatorRunning(emulators, 'firestore');\n await loadFirestoreRules(\n emulators.firestore,\n projectId,\n config.firestore.rules\n );\n }\n if (config.storage?.rules) {\n assertEmulatorRunning(emulators, 'storage');\n await loadStorageRules(emulators.storage, config.storage.rules);\n }\n\n return new RulesTestEnvironmentImpl(projectId, emulators);\n}\n\nconst SUPPORTED_EMULATORS = ['database', 'firestore', 'storage'] as const;\n","/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n EMULATOR_HOST_ENV_VARS,\n getEmulatorHostAndPort\n} from './impl/discovery';\nimport { fixHostname, makeUrl } from './impl/url';\nimport { HostAndPort } from './public_types';\n\n/**\n * Run a setup function with background Cloud Functions triggers disabled. This can be used to\n * import data into the Realtime Database or Cloud Firestore emulator without triggering locally\n * emulated Cloud Functions.\n *\n * This method only works with Firebase CLI version 8.13.0 or higher. This overload works only if\n * the Emulator hub host:port is specified by the environment variable FIREBASE_EMULATOR_HUB.\n *\n * @param fn - a function which may be sync or async (returns a promise)\n * @public\n */\nexport async function withFunctionTriggersDisabled<TResult>(\n fn: () => TResult | Promise<TResult>\n): Promise<TResult>;\n\n/**\n * Run a setup function with background Cloud Functions triggers disabled. This can be used to\n * import data into the Realtime Database or Cloud Firestore emulator without triggering locally\n * emulated Cloud Functions.\n *\n * This method only works with Firebase CLI version 8.13.0 or higher. The Emulator hub must be\n * running, which host and port are specified in this overload.\n *\n * @param fn - a function which may be sync or async (returns a promise)\n * @param hub - the host and port of the Emulator Hub (ex: `{host: 'localhost', port: 4400}`)\n * @public\n */\nexport async function withFunctionTriggersDisabled<TResult>(\n hub: { host: string; port: number },\n fn: () => TResult | Promise<TResult>\n): Promise<TResult>;\n\nexport async function withFunctionTriggersDisabled<TResult>(\n fnOrHub: { host: string; port: number } | (() => TResult | Promise<TResult>),\n maybeFn?: () => TResult | Promise<TResult>\n): Promise<TResult> {\n let hub: HostAndPort | undefined;\n if (typeof fnOrHub === 'function') {\n maybeFn = fnOrHub;\n hub = getEmulatorHostAndPort('hub');\n } else {\n hub = getEmulatorHostAndPort('hub', fnOrHub);\n if (!maybeFn) {\n throw new Error('The callback function must be specified!');\n }\n }\n if (!hub) {\n throw new Error(\n 'Please specify the Emulator Hub host and port via arguments or set the environment ' +\n `variable ${EMULATOR_HOST_ENV_VARS.hub}!`\n );\n }\n\n hub.host = fixHostname(hub.host);\n makeUrl(hub, '/functions/disableBackgroundTriggers');\n // Disable background triggers\n const disableRes = await fetch(\n makeUrl(hub, '/functions/disableBackgroundTriggers'),\n {\n method: 'PUT'\n }\n );\n if (!disableRes.ok) {\n throw new Error(\n `HTTP Error ${disableRes.status} when disabling functions triggers, are you using firebase-tools 8.13.0 or higher?`\n );\n }\n\n // Run the user's function\n let result: TResult | undefined = undefined;\n try {\n result = await maybeFn();\n } finally {\n // Re-enable background triggers\n const enableRes = await fetch(\n makeUrl(hub, '/functions/enableBackgroundTriggers'),\n {\n method: 'PUT'\n }\n );\n\n if (!enableRes.ok) {\n throw new Error(\n `HTTP Error ${enableRes.status} when enabling functions triggers, are you using firebase-tools 8.13.0 or higher?`\n );\n }\n }\n\n // Return the user's function result\n return result;\n}\n\n/**\n * Assert the promise to be rejected with a \"permission denied\" error.\n *\n * Useful to assert a certain request to be denied by Security Rules. See example below.\n * This function recognizes permission-denied errors from Database, Firestore, and Storage JS SDKs.\n *\n * @param pr - the promise to be asserted\n * @returns a Promise that is fulfilled if pr is rejected with \"permission denied\". If pr is\n * rejected with any other error or resolved, the returned promise rejects.\n * @public\n * @example\n * ```javascript\n * const unauthed = testEnv.unauthenticatedContext();\n * await assertFails(get(doc(unauthed.firestore(), '/private/doc'), { ... });\n * ```\n */\nexport function assertFails(pr: Promise<any>): Promise<any> {\n return pr.then(\n () => {\n return Promise.reject(\n new Error('Expected request to fail, but it succeeded.')\n );\n },\n (err: any) => {\n const errCode = err?.code?.toLowerCase() || '';\n const errMessage = err?.message?.toLowerCase() || '';\n const isPermissionDenied =\n errCode === 'permission-denied' ||\n errCode === 'permission_denied' ||\n errMessage.indexOf('permission_denied') >= 0 ||\n errMessage.indexOf('permission denied') >= 0 ||\n // Storage permission errors contain message: (storage/unauthorized)\n errMessage.indexOf('unauthorized') >= 0;\n\n if (!isPermissionDenied) {\n return Promise.reject(\n new Error(\n `Expected PERMISSION_DENIED but got unexpected error: ${err}`\n )\n );\n }\n return err;\n }\n );\n}\n\n/**\n * Assert the promise to be successful.\n *\n * This is a no-op function returning the passed promise as-is, but can be used for documentational\n * purposes in test code to emphasize that a certain request should succeed (e.g. allowed by rules).\n *\n * @public\n * @example\n * ```javascript\n * const alice = testEnv.authenticatedContext('alice');\n * await assertSucceeds(get(doc(alice.firestore(), '/doc/readable/by/alice'), { ... });\n * ```\n */\nexport function assertSucceeds<T>(pr: Promise<T>): Promise<T> {\n return pr;\n}\n"],"names":["firebase"],"mappings":";;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;AAeG;AAIH;;;;;;;;AAQG;AACa,SAAA,WAAW,CAAC,I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AC,OAAO,CAAC,mBAAmB,CAAC,IAAI,CAAC;AAC5C,YAAA,UAAU,CAAC,OAAO,CAAC,mBAAmB,CAAC,IAAI,CAAC;;AAE5C,YAAA,UAAU,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAE1C,IAAI,CAAC,kBAAkB,EAAE;AACvB,YAAA,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,KAAK,CACP,CAAA,qDAAA,EAAwD,GAAG,CAAA,CAAE,CAC9D,CACF,CAAC;SACH;AACD,QAAA,OAAO,GAAG,CAAC;AACb,KAAC,CACF,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;AAYG;AACG,SAAU,cAAc,CAAI,EAAc,EAAA;AAC9C,IAAA,OAAO,EAAE,CAAC;AACZ;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/impl/url.ts","../src/impl/discovery.ts","../src/impl/test_environment.ts","../src/impl/rules.ts","../src/initialize.ts","../src/util.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { HostAndPort } from '../public_types';\n\n/**\n * Return a connectable hostname, replacing wildcard 0.0.0.0 or :: with loopback\n * addresses 127.0.0.1 / ::1 correspondingly. See below for why this is needed:\n * https://github.com/firebase/firebase-tools-ui/issues/286\n *\n * This assumes emulators are running on the same device as fallbackHost (e.g.\n * hub), which should hold if both are started from the same CLI command.\n * @private\n */\nexport function fixHostname(host: string, fallbackHost?: string): string {\n host = host.replace('[', '').replace(']', ''); // Remove IPv6 brackets\n if (host === '0.0.0.0') {\n host = fallbackHost || '127.0.0.1';\n } else if (host === '::') {\n host = fallbackHost || '::1';\n }\n return host;\n}\n\n/**\n * Create a URL with host, port, and path. Handles IPv6 bracketing correctly.\n * @private\n */\nexport function makeUrl(hostAndPort: HostAndPort | string, path: string): URL {\n if (typeof hostAndPort === 'object') {\n const { host, port } = hostAndPort;\n if (host.includes(':')) {\n hostAndPort = `[${host}]:${port}`;\n } else {\n hostAndPort = `${host}:${port}`;\n }\n }\n const url = new URL(`http://${hostAndPort}/`);\n url.pathname = path;\n return url;\n}\n","/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { EmulatorConfig, HostAndPort } from '../public_types';\nimport { makeUrl, fixHostname } from './url';\n\n/**\n * Use the Firebase Emulator hub to discover other running emulators.\n *\n * @param hub the host and port where the Emulator Hub is running\n * @private\n */\nexport async function discoverEmulators(\n hub: HostAndPort,\n fetchImpl: typeof fetch = fetch\n): Promise<DiscoveredEmulators> {\n const res = await fetchImpl(makeUrl(hub, '/emulators'));\n if (!res.ok) {\n throw new Error(\n `HTTP Error ${res.status} when attempting to reach Emulator Hub at ${res.url}, are you sure it is running?`\n );\n }\n\n const emulators: DiscoveredEmulators = {};\n\n const data = await res.json();\n\n if (data.database) {\n emulators.database = {\n host: data.database.host,\n port: data.database.port\n };\n }\n\n if (data.firestore) {\n emulators.firestore = {\n host: data.firestore.host,\n port: data.firestore.port\n };\n }\n\n if (data.storage) {\n emulators.storage = {\n host: data.storage.host,\n port: data.storage.port\n };\n }\n\n if (data.hub) {\n emulators.hub = {\n host: data.hub.host,\n port: data.hub.port\n };\n }\n return emulators;\n}\n\n/**\n * @private\n */\nexport interface DiscoveredEmulators {\n database?: HostAndPort;\n firestore?: HostAndPort;\n storage?: HostAndPort;\n hub?: HostAndPort;\n}\n\n/**\n * @private\n */\nexport function getEmulatorHostAndPort(\n emulator: keyof DiscoveredEmulators,\n conf?: EmulatorConfig,\n discovered?: DiscoveredEmulators\n) {\n if (conf && ('host' in conf || 'port' in conf)) {\n const { host, port } = conf as any;\n if (host || port) {\n if (!host || !port) {\n throw new Error(\n `Invalid configuration ${emulator}.host=${host} and ${emulator}.port=${port}. ` +\n 'If either parameter is supplied, both must be defined.'\n );\n }\n if (discovered && !discovered[emulator]) {\n console.warn(\n `Warning: config for the ${emulator} emulator is specified, but the Emulator hub ` +\n 'reports it as not running. This may lead to errors such as connection refused.'\n );\n }\n return {\n host: fixHostname(host, discovered?.hub?.host),\n port: port\n };\n }\n }\n const envVar = EMULATOR_HOST_ENV_VARS[emulator];\n const fallback = discovered?.[emulator] || emulatorFromEnvVar(envVar);\n if (fallback) {\n if (discovered && !discovered[emulator]) {\n console.warn(\n `Warning: the environment variable ${envVar} is set, but the Emulator hub reports the ` +\n `${emulator} emulator as not running. This may lead to errors such as connection refused.`\n );\n }\n return {\n host: fixHostname(fallback.host, discovered?.hub?.host),\n port: fallback.port\n };\n }\n}\n\n// Visible for testing.\nexport const EMULATOR_HOST_ENV_VARS = {\n 'database': 'FIREBASE_DATABASE_EMULATOR_HOST',\n 'firestore': 'FIRESTORE_EMULATOR_HOST',\n 'hub': 'FIREBASE_EMULATOR_HUB',\n 'storage': 'FIREBASE_STORAGE_EMULATOR_HOST'\n};\n\nfunction emulatorFromEnvVar(envVar: string): HostAndPort | undefined {\n const hostAndPort = process.env[envVar];\n if (!hostAndPort) {\n return undefined;\n }\n\n let parsed: URL;\n try {\n parsed = new URL(`http://${hostAndPort}`);\n } catch {\n throw new Error(\n `Invalid format in environment variable ${envVar}=${hostAndPort} (expected host:port)`\n );\n }\n let host = parsed.hostname;\n const port = Number(parsed.port || '80');\n if (!Number.isInteger(port)) {\n throw new Error(\n `Invalid port in environment variable ${envVar}=${hostAndPort}`\n );\n }\n return { host, port };\n}\n","/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport firebase from 'firebase/compat/app';\nimport 'firebase/compat/firestore';\nimport 'firebase/compat/database';\nimport 'firebase/compat/storage';\n\nimport {\n HostAndPort,\n RulesTestContext,\n RulesTestEnvironment,\n TokenOptions\n} from '../public_types';\n\nimport { DiscoveredEmulators } from './discovery';\nimport { makeUrl } from './url';\n\n/**\n * An implementation of {@code RulesTestEnvironment}. This is private to hide the constructor,\n * which should never be directly called by the developer.\n * @private\n */\nexport class RulesTestEnvironmentImpl implements RulesTestEnvironment {\n private contexts = new Set<RulesTestContextImpl>();\n private destroyed = false;\n\n constructor(\n readonly projectId: string,\n readonly emulators: DiscoveredEmulators\n ) {}\n\n authenticatedContext(\n user_id: string,\n tokenOptions?: TokenOptions\n ): RulesTestContext {\n this.checkNotDestroyed();\n return this.createContext({\n ...tokenOptions,\n sub: user_id,\n user_id: user_id\n });\n }\n\n unauthenticatedContext(): RulesTestContext {\n this.checkNotDestroyed();\n return this.createContext(/* authToken = */ undefined);\n }\n\n async withSecurityRulesDisabled(\n callback: (context: RulesTestContext) => Promise<void>\n ): Promise<void> {\n this.checkNotDestroyed();\n // The \"owner\" token is recognized by the emulators as a special value that bypasses Security\n // Rules. This should only ever be used in withSecurityRulesDisabled.\n // If you're reading this and thinking about doing this in your own app / tests / scripts, think\n // twice. Instead, just use withSecurityRulesDisabled for unit testing OR connect your Firebase\n // Admin SDKs to the emulators for integration testing via environment variables.\n // See: https://firebase.google.com/docs/emulator-suite/connect_firestore#admin_sdks\n const context = this.createContext('owner');\n try {\n await callback(context);\n } finally {\n // We eagerly clean up this context to actively prevent misuse outside of the callback, e.g.\n // storing the context in a variable.\n context.cleanup();\n this.contexts.delete(context);\n }\n }\n\n private createContext(\n authToken: string | firebase.EmulatorMockTokenOptions | undefined\n ): RulesTestContextImpl {\n const context = new RulesTestContextImpl(\n this.projectId,\n this.emulators,\n authToken\n );\n this.contexts.add(context);\n return context;\n }\n\n clearDatabase(): Promise<void> {\n this.checkNotDestroyed();\n return this.withSecurityRulesDisabled(context => {\n return context.database().ref('/').set(null);\n });\n }\n\n async clearFirestore(): Promise<void> {\n this.checkNotDestroyed();\n assertEmulatorRunning(this.emulators, 'firestore');\n\n const resp = await fetch(\n makeUrl(\n this.emulators.firestore,\n `/emulator/v1/projects/${this.projectId}/databases/(default)/documents`\n ),\n {\n method: 'DELETE'\n }\n );\n\n if (!resp.ok) {\n throw new Error(await resp.text());\n }\n }\n\n clearStorage(): Promise<void> {\n this.checkNotDestroyed();\n return this.withSecurityRulesDisabled(async context => {\n const { items } = await context.storage().ref().listAll();\n await Promise.all(\n items.map((item: { delete: () => any }) => {\n return item.delete();\n })\n );\n });\n }\n\n async cleanup(): Promise<void> {\n this.destroyed = true;\n this.contexts.forEach(context => {\n context.envDestroyed = true;\n context.cleanup();\n });\n this.contexts.clear();\n }\n\n private checkNotDestroyed() {\n if (this.destroyed) {\n throw new Error(\n 'This RulesTestEnvironment has already been cleaned up. ' +\n '(This may indicate a leak or missing `await` in your test cases. If you do intend to ' +\n 'perform more tests, please call cleanup() later or create another RulesTestEnvironment.)'\n );\n }\n }\n}\n/**\n * An implementation of {@code RulesTestContext}. This is private to hide the constructor,\n * which should never be directly called by the developer.\n * @private\n */\nclass RulesTestContextImpl implements RulesTestContext {\n private app?: firebase.app.App;\n private destroyed = false;\n envDestroyed = false;\n\n constructor(\n readonly projectId: string,\n readonly emulators: DiscoveredEmulators,\n readonly authToken: firebase.EmulatorMockTokenOptions | string | undefined\n ) {}\n\n cleanup() {\n this.destroyed = true;\n this.app?.delete();\n\n this.app = undefined;\n }\n\n firestore(\n settings?: firebase.firestore.Settings\n ): firebase.firestore.Firestore {\n assertEmulatorRunning(this.emulators, 'firestore');\n const firestore = this.getApp().firestore();\n if (settings) {\n firestore.settings(settings);\n }\n firestore.useEmulator(\n this.emulators.firestore.host,\n this.emulators.firestore.port,\n { mockUserToken: this.authToken }\n );\n return firestore;\n }\n database(databaseURL?: string): firebase.database.Database {\n assertEmulatorRunning(this.emulators, 'database');\n if (!databaseURL) {\n const url = makeUrl(this.emulators.database, '');\n // Make sure to set the namespace equal to projectId -- otherwise the RTDB SDK will by default\n // use `${projectId}-default-rtdb`, which is treated as a different DB by the RTDB emulator\n // (and thus WON'T apply any rules set for the `projectId` DB during initialization).\n url.searchParams.append('ns', this.projectId);\n databaseURL = url.toString();\n }\n const database = this.getApp().database(databaseURL);\n database.useEmulator(\n this.emulators.database.host,\n this.emulators.database.port,\n { mockUserToken: this.authToken }\n );\n return database;\n }\n storage(bucketUrl = `gs://${this.projectId}`): firebase.storage.Storage {\n assertEmulatorRunning(this.emulators, 'storage');\n const storage = this.getApp().storage(bucketUrl);\n storage.useEmulator(\n this.emulators.storage.host,\n this.emulators.storage.port,\n { mockUserToken: this.authToken }\n );\n return storage;\n }\n\n private getApp(): firebase.app.App {\n if (this.envDestroyed) {\n throw new Error(\n 'This RulesTestContext is no longer valid because its RulesTestEnvironment has been ' +\n 'cleaned up. (This may indicate a leak or missing `await` in your test cases.)'\n );\n }\n if (this.destroyed) {\n throw new Error(\n 'This RulesTestContext is no longer valid. When using withSecurityRulesDisabled, ' +\n 'make sure to perform all operations on the context within the callback function and ' +\n 'return a Promise that resolves when the operations are done.'\n );\n }\n if (!this.app) {\n this.app = firebase.initializeApp(\n { projectId: this.projectId },\n `_Firebase_RulesUnitTesting_${Date.now()}_${Math.random()}`\n );\n }\n return this.app;\n }\n}\n\nexport function assertEmulatorRunning<E extends keyof DiscoveredEmulators>(\n emulators: DiscoveredEmulators,\n emulator: E\n): asserts emulators is Record<E, HostAndPort> {\n if (!emulators[emulator]) {\n if (emulators.hub) {\n throw new Error(\n `The ${emulator} emulator is not running (according to Emulator hub). To force ` +\n 'connecting anyway, please specify its host and port in initializeTestEnvironment({...}).'\n );\n } else {\n throw new Error(\n `The host and port of the ${emulator} emulator must be specified. (You may wrap the test ` +\n \"script with `firebase emulators:exec './your-test-script'` to enable automatic \" +\n `discovery, or specify manually via initializeTestEnvironment({${emulator}: {host, port}}).`\n );\n }\n }\n}\n","/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { HostAndPort } from '../public_types';\nimport { makeUrl } from './url';\n\n/**\n * @private\n */\nexport async function loadDatabaseRules(\n hostAndPort: HostAndPort,\n databaseName: string,\n rules: string\n): Promise<void> {\n const url = makeUrl(hostAndPort, '/.settings/rules.json');\n url.searchParams.append('ns', databaseName);\n const resp = await fetch(url, {\n method: 'PUT',\n headers: { Authorization: 'Bearer owner' },\n body: rules\n });\n\n if (!resp.ok) {\n throw new Error(await resp.text());\n }\n}\n\n/**\n * @private\n */\nexport async function loadFirestoreRules(\n hostAndPort: HostAndPort,\n projectId: string,\n rules: string\n): Promise<void> {\n const resp = await fetch(\n makeUrl(hostAndPort, `/emulator/v1/projects/${projectId}:securityRules`),\n {\n method: 'PUT',\n body: JSON.stringify({\n rules: {\n files: [{ content: rules }]\n }\n })\n }\n );\n\n if (!resp.ok) {\n throw new Error(await resp.text());\n }\n}\n\n/**\n * @private\n */\nexport async function loadStorageRules(\n hostAndPort: HostAndPort,\n rules: string\n): Promise<void> {\n const resp = await fetch(makeUrl(hostAndPort, '/internal/setRules'), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json'\n },\n body: JSON.stringify({\n rules: {\n files: [{ name: 'storage.rules', content: rules }]\n }\n })\n });\n if (!resp.ok) {\n throw new Error(await resp.text());\n }\n}\n","/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { RulesTestEnvironment, TestEnvironmentConfig } from './public_types';\nimport {\n DiscoveredEmulators,\n discoverEmulators,\n getEmulatorHostAndPort\n} from './impl/discovery';\nimport {\n assertEmulatorRunning,\n RulesTestEnvironmentImpl\n} from './impl/test_environment';\nimport {\n loadDatabaseRules,\n loadFirestoreRules,\n loadStorageRules\n} from './impl/rules';\n\n/**\n * Initializes a test environment for rules unit testing. Call this function first for test setup.\n *\n * Requires emulators to be running. This function tries to discover those emulators via environment\n * variables or through the Firebase Emulator hub if hosts and ports are unspecified. It is strongly\n * recommended to specify security rules for emulators used for testing. See minimal example below.\n *\n * @param config - the configuration for emulators. Most fields are optional if they can be discovered\n * @returns a promise that resolves with an environment ready for testing, or rejects on error.\n * @public\n * @example\n * ```javascript\n * const testEnv = await initializeTestEnvironment({\n * firestore: {\n * rules: fs.readFileSync(\"/path/to/firestore.rules\", \"utf8\"), // Load rules from file\n * // host and port can be omitted if they can be discovered from the hub.\n * },\n * // ...\n * });\n * ```\n */\nexport async function initializeTestEnvironment(\n config: TestEnvironmentConfig\n): Promise<RulesTestEnvironment> {\n const projectId = config.projectId || process.env.GCLOUD_PROJECT;\n if (!projectId) {\n throw new Error(\n 'Missing projectId option or env var GCLOUD_PROJECT! Please specify the projectId either ' +\n 'way.\\n(A demo-* projectId is strongly recommended for unit tests, such as \"demo-test\".)'\n );\n }\n const hub = getEmulatorHostAndPort('hub', config.hub);\n let discovered = hub ? { ...(await discoverEmulators(hub)), hub } : undefined;\n\n const emulators: DiscoveredEmulators = {};\n if (hub) {\n emulators.hub = hub;\n }\n\n for (const emulator of SUPPORTED_EMULATORS) {\n const hostAndPort = getEmulatorHostAndPort(\n emulator,\n config[emulator],\n discovered\n );\n if (hostAndPort) {\n emulators[emulator] = hostAndPort;\n }\n }\n\n if (config.database?.rules) {\n assertEmulatorRunning(emulators, 'database');\n await loadDatabaseRules(\n emulators.database,\n projectId,\n config.database.rules\n );\n }\n if (config.firestore?.rules) {\n assertEmulatorRunning(emulators, 'firestore');\n await loadFirestoreRules(\n emulators.firestore,\n projectId,\n config.firestore.rules\n );\n }\n if (config.storage?.rules) {\n assertEmulatorRunning(emulators, 'storage');\n await loadStorageRules(emulators.storage, config.storage.rules);\n }\n\n return new RulesTestEnvironmentImpl(projectId, emulators);\n}\n\nconst SUPPORTED_EMULATORS = ['database', 'firestore', 'storage'] as const;\n","/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n EMULATOR_HOST_ENV_VARS,\n getEmulatorHostAndPort\n} from './impl/discovery';\nimport { fixHostname, makeUrl } from './impl/url';\nimport { HostAndPort } from './public_types';\n\n/**\n * Run a setup function with background Cloud Functions triggers disabled. This can be used to\n * import data into the Realtime Database or Cloud Firestore emulator without triggering locally\n * emulated Cloud Functions.\n *\n * This method only works with Firebase CLI version 8.13.0 or higher. This overload works only if\n * the Emulator hub host:port is specified by the environment variable FIREBASE_EMULATOR_HUB.\n *\n * @param fn - a function which may be sync or async (returns a promise)\n * @public\n */\nexport async function withFunctionTriggersDisabled<TResult>(\n fn: () => TResult | Promise<TResult>\n): Promise<TResult>;\n\n/**\n * Run a setup function with background Cloud Functions triggers disabled. This can be used to\n * import data into the Realtime Database or Cloud Firestore emulator without triggering locally\n * emulated Cloud Functions.\n *\n * This method only works with Firebase CLI version 8.13.0 or higher. The Emulator hub must be\n * running, which host and port are specified in this overload.\n *\n * @param fn - a function which may be sync or async (returns a promise)\n * @param hub - the host and port of the Emulator Hub (ex: `{host: 'localhost', port: 4400}`)\n * @public\n */\nexport async function withFunctionTriggersDisabled<TResult>(\n hub: { host: string; port: number },\n fn: () => TResult | Promise<TResult>\n): Promise<TResult>;\n\nexport async function withFunctionTriggersDisabled<TResult>(\n fnOrHub: { host: string; port: number } | (() => TResult | Promise<TResult>),\n maybeFn?: () => TResult | Promise<TResult>\n): Promise<TResult> {\n let hub: HostAndPort | undefined;\n if (typeof fnOrHub === 'function') {\n maybeFn = fnOrHub;\n hub = getEmulatorHostAndPort('hub');\n } else {\n hub = getEmulatorHostAndPort('hub', fnOrHub);\n if (!maybeFn) {\n throw new Error('The callback function must be specified!');\n }\n }\n if (!hub) {\n throw new Error(\n 'Please specify the Emulator Hub host and port via arguments or set the environment ' +\n `variable ${EMULATOR_HOST_ENV_VARS.hub}!`\n );\n }\n\n hub.host = fixHostname(hub.host);\n makeUrl(hub, '/functions/disableBackgroundTriggers');\n // Disable background triggers\n const disableRes = await fetch(\n makeUrl(hub, '/functions/disableBackgroundTriggers'),\n {\n method: 'PUT'\n }\n );\n if (!disableRes.ok) {\n throw new Error(\n `HTTP Error ${disableRes.status} when disabling functions triggers, are you using firebase-tools 8.13.0 or higher?`\n );\n }\n\n // Run the user's function\n let result: TResult | undefined = undefined;\n try {\n result = await maybeFn();\n } finally {\n // Re-enable background triggers\n const enableRes = await fetch(\n makeUrl(hub, '/functions/enableBackgroundTriggers'),\n {\n method: 'PUT'\n }\n );\n\n if (!enableRes.ok) {\n throw new Error(\n `HTTP Error ${enableRes.status} when enabling functions triggers, are you using firebase-tools 8.13.0 or higher?`\n );\n }\n }\n\n // Return the user's function result\n return result;\n}\n\n/**\n * Assert the promise to be rejected with a \"permission denied\" error.\n *\n * Useful to assert a certain request to be denied by Security Rules. See example below.\n * This function recognizes permission-denied errors from Database, Firestore, and Storage JS SDKs.\n *\n * @param pr - the promise to be asserted\n * @returns a Promise that is fulfilled if pr is rejected with \"permission denied\". If pr is\n * rejected with any other error or resolved, the returned promise rejects.\n * @public\n * @example\n * ```javascript\n * const unauthed = testEnv.unauthenticatedContext();\n * await assertFails(get(doc(unauthed.firestore(), '/private/doc'), { ... });\n * ```\n */\nexport function assertFails(pr: Promise<any>): Promise<any> {\n return pr.then(\n () => {\n return Promise.reject(\n new Error('Expected request to fail, but it succeeded.')\n );\n },\n (err: any) => {\n const errCode = err?.code?.toLowerCase() || '';\n const errMessage = err?.message?.toLowerCase() || '';\n const isPermissionDenied =\n errCode === 'permission-denied' ||\n errCode === 'permission_denied' ||\n errMessage.indexOf('permission_denied') >= 0 ||\n errMessage.indexOf('permission denied') >= 0 ||\n // Storage permission errors contain message: (storage/unauthorized)\n errMessage.indexOf('unauthorized') >= 0;\n\n if (!isPermissionDenied) {\n return Promise.reject(\n new Error(\n `Expected PERMISSION_DENIED but got unexpected error: ${err}`\n )\n );\n }\n return err;\n }\n );\n}\n\n/**\n * Assert the promise to be successful.\n *\n * This is a no-op function returning the passed promise as-is, but can be used for documentational\n * purposes in test code to emphasize that a certain request should succeed (e.g. allowed by rules).\n *\n * @public\n * @example\n * ```javascript\n * const alice = testEnv.authenticatedContext('alice');\n * await assertSucceeds(get(doc(alice.firestore(), '/doc/readable/by/alice'), { ... });\n * ```\n */\nexport function assert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OAAO,GAAG,GAAG,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;QAC/C,MAAM,UAAU,GAAG,GAAG,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;AACrD,QAAA,MAAM,kBAAkB,GACtB,OAAO,KAAK,mBAAmB;AAC/B,YAAA,OAAO,KAAK,mBAAmB;AAC/B,YAAA,UAAU,CAAC,OAAO,CAAC,mBAAmB,CAAC,IAAI,CAAC;AAC5C,YAAA,UAAU,CAAC,OAAO,CAAC,mBAAmB,CAAC,IAAI,CAAC;;AAE5C,YAAA,UAAU,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAE1C,IAAI,CAAC,kBAAkB,EAAE;AACvB,YAAA,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,KAAK,CACP,CAAA,qDAAA,EAAwD,GAAG,CAAA,CAAE,CAC9D,CACF,CAAC;SACH;AACD,QAAA,OAAO,GAAG,CAAC;AACb,KAAC,CACF,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;AAYG;AACG,SAAU,cAAc,CAAI,EAAc,EAAA;AAC9C,IAAA,OAAO,EAAE,CAAC;AACZ;;;;;;;"}
|
package/dist/util/index.d.ts
CHANGED
|
@@ -44,4 +44,11 @@ export type EmulatorMockTokenOptions = ({
|
|
|
44
44
|
sub: string;
|
|
45
45
|
}) & Partial<FirebaseIdToken>;
|
|
46
46
|
export declare function createMockUserToken(token: EmulatorMockTokenOptions, projectId?: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* Updates Emulator Banner. Primarily used for Firebase Studio
|
|
49
|
+
* @param name
|
|
50
|
+
* @param isRunningEmulator
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
export declare function updateEmulatorBanner(name: string, isRunningEmulator: boolean): void;
|
|
47
54
|
export {};
|
|
@@ -69,6 +69,8 @@ export declare function isUWP(): boolean;
|
|
|
69
69
|
export declare function isNodeSdk(): boolean;
|
|
70
70
|
/** Returns true if we are running in Safari. */
|
|
71
71
|
export declare function isSafari(): boolean;
|
|
72
|
+
/** Returns true if we are running in Safari or WebKit */
|
|
73
|
+
export declare function isSafariOrWebkit(): boolean;
|
|
72
74
|
/**
|
|
73
75
|
* This method checks if indexedDB is supported by current browser/service worker context
|
|
74
76
|
* @return true if indexedDB is supported by current browser/service worker context
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Checks whether host is a cloud workstation or not.
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export declare function isCloudWorkstation(url: string): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Makes a fetch request to the given server.
|
|
24
|
+
* Mostly used for forwarding cookies in Firebase Studio.
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
export declare function pingServer(endpoint: string): Promise<boolean>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firebase/rules-unit-testing",
|
|
3
|
-
"version": "4.0.1-canary.
|
|
3
|
+
"version": "4.0.1-canary.cb19688bf",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)",
|
|
6
6
|
"main": "dist/index.cjs.js",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"rollup-plugin-typescript2": "0.36.0"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"firebase": "11.
|
|
46
|
+
"firebase": "11.10.0-canary.cb19688bf"
|
|
47
47
|
},
|
|
48
48
|
"repository": {
|
|
49
49
|
"directory": "packages/rules-unit-testing",
|