@firebase/rules-unit-testing 4.0.0 → 4.0.1
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.d.ts +19 -19
- package/dist/esm/index.esm.js +587 -587
- package/dist/esm/index.esm.js.map +1 -1
- package/dist/esm/src/impl/discovery.d.ts +46 -46
- package/dist/esm/src/impl/rules.d.ts +29 -29
- package/dist/esm/src/impl/test_environment.d.ts +43 -43
- package/dist/esm/src/impl/url.d.ts +32 -32
- package/dist/esm/src/initialize.d.ts +39 -39
- package/dist/esm/src/public_types/index.d.ts +228 -228
- package/dist/esm/src/util.d.ts +75 -75
- package/dist/esm/test/dummy.test.d.ts +17 -17
- package/dist/esm/test/impl/discovery.test.d.ts +17 -17
- package/dist/esm/test/impl/rules.test.d.ts +17 -17
- package/dist/esm/test/setup.d.ts +19 -19
- package/dist/esm/test/test_utils.d.ts +18 -18
- package/dist/esm/test/util.test.d.ts +17 -17
- package/dist/index.cjs.js +587 -587
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +19 -19
- package/dist/src/impl/discovery.d.ts +46 -46
- package/dist/src/impl/rules.d.ts +29 -29
- package/dist/src/impl/test_environment.d.ts +43 -43
- package/dist/src/impl/url.d.ts +32 -32
- package/dist/src/initialize.d.ts +39 -39
- package/dist/src/public_types/index.d.ts +228 -228
- package/dist/src/util.d.ts +75 -75
- package/dist/test/dummy.test.d.ts +17 -17
- package/dist/test/impl/discovery.test.d.ts +17 -17
- package/dist/test/impl/rules.test.d.ts +17 -17
- package/dist/test/setup.d.ts +19 -19
- package/dist/test/test_utils.d.ts +18 -18
- package/dist/test/util.test.d.ts +17 -17
- package/package.json +1 -1
|
@@ -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;\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(conf.host, discovered?.hub?.host),\n port: conf.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;IAC9C,IAAI,IAAI,KAAK,SAAS,EAAE;AACtB,QAAA,IAAI,GAAG,YAAY,IAAI,WAAW,CAAC;AACpC,KAAA;SAAM,IAAI,IAAI,KAAK,IAAI,EAAE;AACxB,QAAA,IAAI,GAAG,YAAY,IAAI,KAAK,CAAC;AAC9B,KAAA;AACD,IAAA,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;AAGG;AACa,SAAA,OAAO,CAAC,WAAiC,EAAE,IAAY,EAAA;AACrE,IAAA,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE;AACnC,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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;AACH,SAAA;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,EAA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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,46 +1,46 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2021 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
|
-
import { EmulatorConfig, HostAndPort } from '../public_types';
|
|
18
|
-
/**
|
|
19
|
-
* Use the Firebase Emulator hub to discover other running emulators.
|
|
20
|
-
*
|
|
21
|
-
* @param hub the host and port where the Emulator Hub is running
|
|
22
|
-
* @private
|
|
23
|
-
*/
|
|
24
|
-
export declare function discoverEmulators(hub: HostAndPort, fetchImpl?: typeof fetch): Promise<DiscoveredEmulators>;
|
|
25
|
-
/**
|
|
26
|
-
* @private
|
|
27
|
-
*/
|
|
28
|
-
export interface DiscoveredEmulators {
|
|
29
|
-
database?: HostAndPort;
|
|
30
|
-
firestore?: HostAndPort;
|
|
31
|
-
storage?: HostAndPort;
|
|
32
|
-
hub?: HostAndPort;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* @private
|
|
36
|
-
*/
|
|
37
|
-
export declare function getEmulatorHostAndPort(emulator: keyof DiscoveredEmulators, conf?: EmulatorConfig, discovered?: DiscoveredEmulators): {
|
|
38
|
-
host: string;
|
|
39
|
-
port:
|
|
40
|
-
} | undefined;
|
|
41
|
-
export declare const EMULATOR_HOST_ENV_VARS: {
|
|
42
|
-
database: string;
|
|
43
|
-
firestore: string;
|
|
44
|
-
hub: string;
|
|
45
|
-
storage: string;
|
|
46
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2021 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
|
+
import { EmulatorConfig, HostAndPort } from '../public_types';
|
|
18
|
+
/**
|
|
19
|
+
* Use the Firebase Emulator hub to discover other running emulators.
|
|
20
|
+
*
|
|
21
|
+
* @param hub the host and port where the Emulator Hub is running
|
|
22
|
+
* @private
|
|
23
|
+
*/
|
|
24
|
+
export declare function discoverEmulators(hub: HostAndPort, fetchImpl?: typeof fetch): Promise<DiscoveredEmulators>;
|
|
25
|
+
/**
|
|
26
|
+
* @private
|
|
27
|
+
*/
|
|
28
|
+
export interface DiscoveredEmulators {
|
|
29
|
+
database?: HostAndPort;
|
|
30
|
+
firestore?: HostAndPort;
|
|
31
|
+
storage?: HostAndPort;
|
|
32
|
+
hub?: HostAndPort;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @private
|
|
36
|
+
*/
|
|
37
|
+
export declare function getEmulatorHostAndPort(emulator: keyof DiscoveredEmulators, conf?: EmulatorConfig, discovered?: DiscoveredEmulators): {
|
|
38
|
+
host: string;
|
|
39
|
+
port: any;
|
|
40
|
+
} | undefined;
|
|
41
|
+
export declare const EMULATOR_HOST_ENV_VARS: {
|
|
42
|
+
database: string;
|
|
43
|
+
firestore: string;
|
|
44
|
+
hub: string;
|
|
45
|
+
storage: string;
|
|
46
|
+
};
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2021 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
|
-
import { HostAndPort } from '../public_types';
|
|
18
|
-
/**
|
|
19
|
-
* @private
|
|
20
|
-
*/
|
|
21
|
-
export declare function loadDatabaseRules(hostAndPort: HostAndPort, databaseName: string, rules: string): Promise<void>;
|
|
22
|
-
/**
|
|
23
|
-
* @private
|
|
24
|
-
*/
|
|
25
|
-
export declare function loadFirestoreRules(hostAndPort: HostAndPort, projectId: string, rules: string): Promise<void>;
|
|
26
|
-
/**
|
|
27
|
-
* @private
|
|
28
|
-
*/
|
|
29
|
-
export declare function loadStorageRules(hostAndPort: HostAndPort, rules: string): Promise<void>;
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2021 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
|
+
import { HostAndPort } from '../public_types';
|
|
18
|
+
/**
|
|
19
|
+
* @private
|
|
20
|
+
*/
|
|
21
|
+
export declare function loadDatabaseRules(hostAndPort: HostAndPort, databaseName: string, rules: string): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* @private
|
|
24
|
+
*/
|
|
25
|
+
export declare function loadFirestoreRules(hostAndPort: HostAndPort, projectId: string, rules: string): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* @private
|
|
28
|
+
*/
|
|
29
|
+
export declare function loadStorageRules(hostAndPort: HostAndPort, rules: string): Promise<void>;
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2021 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
|
-
import 'firebase/compat/firestore';
|
|
18
|
-
import 'firebase/compat/database';
|
|
19
|
-
import 'firebase/compat/storage';
|
|
20
|
-
import { HostAndPort, RulesTestContext, RulesTestEnvironment, TokenOptions } from '../public_types';
|
|
21
|
-
import { DiscoveredEmulators } from './discovery';
|
|
22
|
-
/**
|
|
23
|
-
* An implementation of {@code RulesTestEnvironment}. This is private to hide the constructor,
|
|
24
|
-
* which should never be directly called by the developer.
|
|
25
|
-
* @private
|
|
26
|
-
*/
|
|
27
|
-
export declare class RulesTestEnvironmentImpl implements RulesTestEnvironment {
|
|
28
|
-
readonly projectId: string;
|
|
29
|
-
readonly emulators: DiscoveredEmulators;
|
|
30
|
-
private contexts;
|
|
31
|
-
private destroyed;
|
|
32
|
-
constructor(projectId: string, emulators: DiscoveredEmulators);
|
|
33
|
-
authenticatedContext(user_id: string, tokenOptions?: TokenOptions): RulesTestContext;
|
|
34
|
-
unauthenticatedContext(): RulesTestContext;
|
|
35
|
-
withSecurityRulesDisabled(callback: (context: RulesTestContext) => Promise<void>): Promise<void>;
|
|
36
|
-
private createContext;
|
|
37
|
-
clearDatabase(): Promise<void>;
|
|
38
|
-
clearFirestore(): Promise<void>;
|
|
39
|
-
clearStorage(): Promise<void>;
|
|
40
|
-
cleanup(): Promise<void>;
|
|
41
|
-
private checkNotDestroyed;
|
|
42
|
-
}
|
|
43
|
-
export declare function assertEmulatorRunning<E extends keyof DiscoveredEmulators>(emulators: DiscoveredEmulators, emulator: E): asserts emulators is Record<E, HostAndPort>;
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2021 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
|
+
import 'firebase/compat/firestore';
|
|
18
|
+
import 'firebase/compat/database';
|
|
19
|
+
import 'firebase/compat/storage';
|
|
20
|
+
import { HostAndPort, RulesTestContext, RulesTestEnvironment, TokenOptions } from '../public_types';
|
|
21
|
+
import { DiscoveredEmulators } from './discovery';
|
|
22
|
+
/**
|
|
23
|
+
* An implementation of {@code RulesTestEnvironment}. This is private to hide the constructor,
|
|
24
|
+
* which should never be directly called by the developer.
|
|
25
|
+
* @private
|
|
26
|
+
*/
|
|
27
|
+
export declare class RulesTestEnvironmentImpl implements RulesTestEnvironment {
|
|
28
|
+
readonly projectId: string;
|
|
29
|
+
readonly emulators: DiscoveredEmulators;
|
|
30
|
+
private contexts;
|
|
31
|
+
private destroyed;
|
|
32
|
+
constructor(projectId: string, emulators: DiscoveredEmulators);
|
|
33
|
+
authenticatedContext(user_id: string, tokenOptions?: TokenOptions): RulesTestContext;
|
|
34
|
+
unauthenticatedContext(): RulesTestContext;
|
|
35
|
+
withSecurityRulesDisabled(callback: (context: RulesTestContext) => Promise<void>): Promise<void>;
|
|
36
|
+
private createContext;
|
|
37
|
+
clearDatabase(): Promise<void>;
|
|
38
|
+
clearFirestore(): Promise<void>;
|
|
39
|
+
clearStorage(): Promise<void>;
|
|
40
|
+
cleanup(): Promise<void>;
|
|
41
|
+
private checkNotDestroyed;
|
|
42
|
+
}
|
|
43
|
+
export declare function assertEmulatorRunning<E extends keyof DiscoveredEmulators>(emulators: DiscoveredEmulators, emulator: E): asserts emulators is Record<E, HostAndPort>;
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2021 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
|
-
import { HostAndPort } from '../public_types';
|
|
18
|
-
/**
|
|
19
|
-
* Return a connectable hostname, replacing wildcard 0.0.0.0 or :: with loopback
|
|
20
|
-
* addresses 127.0.0.1 / ::1 correspondingly. See below for why this is needed:
|
|
21
|
-
* https://github.com/firebase/firebase-tools-ui/issues/286
|
|
22
|
-
*
|
|
23
|
-
* This assumes emulators are running on the same device as fallbackHost (e.g.
|
|
24
|
-
* hub), which should hold if both are started from the same CLI command.
|
|
25
|
-
* @private
|
|
26
|
-
*/
|
|
27
|
-
export declare function fixHostname(host: string, fallbackHost?: string): string;
|
|
28
|
-
/**
|
|
29
|
-
* Create a URL with host, port, and path. Handles IPv6 bracketing correctly.
|
|
30
|
-
* @private
|
|
31
|
-
*/
|
|
32
|
-
export declare function makeUrl(hostAndPort: HostAndPort | string, path: string): URL;
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2021 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
|
+
import { HostAndPort } from '../public_types';
|
|
18
|
+
/**
|
|
19
|
+
* Return a connectable hostname, replacing wildcard 0.0.0.0 or :: with loopback
|
|
20
|
+
* addresses 127.0.0.1 / ::1 correspondingly. See below for why this is needed:
|
|
21
|
+
* https://github.com/firebase/firebase-tools-ui/issues/286
|
|
22
|
+
*
|
|
23
|
+
* This assumes emulators are running on the same device as fallbackHost (e.g.
|
|
24
|
+
* hub), which should hold if both are started from the same CLI command.
|
|
25
|
+
* @private
|
|
26
|
+
*/
|
|
27
|
+
export declare function fixHostname(host: string, fallbackHost?: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* Create a URL with host, port, and path. Handles IPv6 bracketing correctly.
|
|
30
|
+
* @private
|
|
31
|
+
*/
|
|
32
|
+
export declare function makeUrl(hostAndPort: HostAndPort | string, path: string): URL;
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2021 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
|
-
import { RulesTestEnvironment, TestEnvironmentConfig } from './public_types';
|
|
18
|
-
/**
|
|
19
|
-
* Initializes a test environment for rules unit testing. Call this function first for test setup.
|
|
20
|
-
*
|
|
21
|
-
* Requires emulators to be running. This function tries to discover those emulators via environment
|
|
22
|
-
* variables or through the Firebase Emulator hub if hosts and ports are unspecified. It is strongly
|
|
23
|
-
* recommended to specify security rules for emulators used for testing. See minimal example below.
|
|
24
|
-
*
|
|
25
|
-
* @param config - the configuration for emulators. Most fields are optional if they can be discovered
|
|
26
|
-
* @returns a promise that resolves with an environment ready for testing, or rejects on error.
|
|
27
|
-
* @public
|
|
28
|
-
* @example
|
|
29
|
-
* ```javascript
|
|
30
|
-
* const testEnv = await initializeTestEnvironment({
|
|
31
|
-
* firestore: {
|
|
32
|
-
* rules: fs.readFileSync("/path/to/firestore.rules", "utf8"), // Load rules from file
|
|
33
|
-
* // host and port can be omitted if they can be discovered from the hub.
|
|
34
|
-
* },
|
|
35
|
-
* // ...
|
|
36
|
-
* });
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
export declare function initializeTestEnvironment(config: TestEnvironmentConfig): Promise<RulesTestEnvironment>;
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2021 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
|
+
import { RulesTestEnvironment, TestEnvironmentConfig } from './public_types';
|
|
18
|
+
/**
|
|
19
|
+
* Initializes a test environment for rules unit testing. Call this function first for test setup.
|
|
20
|
+
*
|
|
21
|
+
* Requires emulators to be running. This function tries to discover those emulators via environment
|
|
22
|
+
* variables or through the Firebase Emulator hub if hosts and ports are unspecified. It is strongly
|
|
23
|
+
* recommended to specify security rules for emulators used for testing. See minimal example below.
|
|
24
|
+
*
|
|
25
|
+
* @param config - the configuration for emulators. Most fields are optional if they can be discovered
|
|
26
|
+
* @returns a promise that resolves with an environment ready for testing, or rejects on error.
|
|
27
|
+
* @public
|
|
28
|
+
* @example
|
|
29
|
+
* ```javascript
|
|
30
|
+
* const testEnv = await initializeTestEnvironment({
|
|
31
|
+
* firestore: {
|
|
32
|
+
* rules: fs.readFileSync("/path/to/firestore.rules", "utf8"), // Load rules from file
|
|
33
|
+
* // host and port can be omitted if they can be discovered from the hub.
|
|
34
|
+
* },
|
|
35
|
+
* // ...
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function initializeTestEnvironment(config: TestEnvironmentConfig): Promise<RulesTestEnvironment>;
|