@firebase/rules-unit-testing 1.3.15-canary.cdada6c68 → 1.3.16-2022028193537

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.
@@ -1,225 +0,0 @@
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 { FirebaseSignInProvider } from '@firebase/util';
18
- import firebase from 'firebase/compat/app';
19
- /**
20
- * More options for the mock user token to be used for testing, including developer-specfied custom
21
- * claims or optional overrides for Firebase Auth token payloads.
22
- * @public
23
- */
24
- export declare type TokenOptions = {
25
- /** The token issue time, in seconds since epoch */
26
- iat?: number;
27
- /** The token expiry time, normally 'iat' + 3600 */
28
- exp?: number;
29
- /** The time the user authenticated, normally 'iat' */
30
- auth_time?: number;
31
- /** The sign in provider, only set when the provider is 'anonymous' */
32
- provider_id?: 'anonymous';
33
- /** The user's primary email */
34
- email?: string;
35
- /** The user's email verification status */
36
- email_verified?: boolean;
37
- /** The user's primary phone number */
38
- phone_number?: string;
39
- /** The user's display name */
40
- name?: string;
41
- /** The user's profile photo URL */
42
- picture?: string;
43
- /** Information on all identities linked to this user */
44
- firebase?: {
45
- /** The primary sign-in provider */
46
- sign_in_provider: FirebaseSignInProvider;
47
- /** A map of providers to the user's list of unique identifiers from each provider */
48
- identities?: {
49
- [provider in FirebaseSignInProvider]?: string[];
50
- };
51
- };
52
- /** Set to PROJECT_ID by default. In rare cases, you may want to specify an override. */
53
- aud?: string;
54
- /** Set to https://securetoken.google.com/PROJECT_ID by default. In rare cases, you may want to specify an override. */
55
- iss?: string;
56
- /** Custom claims set by the developer */
57
- [claim: string]: unknown;
58
- /** DO NOT USE. The user ID MUST be specified as the first param in authenticatedContext(uid, options) instead. */
59
- uid?: never;
60
- /** DO NOT USE. The user ID MUST be specified as the first param in authenticatedContext(uid, options) instead. */
61
- sub?: never;
62
- /** DO NOT USE. The user ID MUST be specified as the first param in authenticatedContext(uid, options) instead. */
63
- user_id?: never;
64
- };
65
- /**
66
- * Configuration of the unit testing environment, including emulators.
67
- * @public
68
- */
69
- export interface TestEnvironmentConfig {
70
- /**
71
- * The project ID of the test environment. Can also be specified via the environment variable GCLOUD_PROJECT.
72
- *
73
- * A "demo-*" project ID is strongly recommended, especially for unit testing.
74
- * See: https://firebase.google.com/docs/emulator-suite/connect_firestore#choose_a_firebase_project
75
- */
76
- projectId?: string;
77
- /**
78
- * The Firebase Emulator hub. Can also be specified via the environment variable FIREBASE_EMULATOR_HUB.
79
- * If specified either way, other running emulators can be automatically discovered, and thus do
80
- * not to be explicity specified.
81
- */
82
- hub?: HostAndPort;
83
- /**
84
- * The Database emulator. Its host and port can also be discovered automatically through the hub
85
- * (see field "hub") or specified via the environment variable FIREBASE_DATABASE_EMULATOR_HOST.
86
- */
87
- database?: EmulatorConfig;
88
- /**
89
- * The Firestore emulator. Its host and port can also be discovered automatically through the hub
90
- * (see field "hub") or specified via the environment variable FIRESTORE_EMULATOR_HOST.
91
- */
92
- firestore?: EmulatorConfig;
93
- /**
94
- * The Storage emulator. Its host and port can also be discovered automatically through the hub
95
- * (see field "hub") or specified via the environment variable FIREBASE_STORAGE_EMULATOR_HOST.
96
- */
97
- storage?: EmulatorConfig;
98
- }
99
- /**
100
- * An object containing the hostname and port number of an emulator.
101
- * @public
102
- */
103
- export interface HostAndPort {
104
- /**
105
- * The host of the emulator. Can be omitted if discovered automatically through the hub or
106
- * specified via environment variables. See {@code TestEnvironmentConfig} for details.
107
- */
108
- host: string;
109
- /**
110
- * The port of the emulator. Can be omitted if discovered automatically through the hub or
111
- * specified via environment variables. See {@code TestEnvironmentConfig} for details.
112
- */
113
- port: number;
114
- }
115
- /**
116
- * Configuration for a given emulator.
117
- * @public
118
- */
119
- export declare type EmulatorConfig = {
120
- /** The security rules source code under test for this emulator. Strongly recommended. */
121
- rules?: string;
122
- } & (HostAndPort | {});
123
- /**
124
- * An object used to control the rules unit test environment. Can be used to create RulesTestContext
125
- * for different authentication situations.
126
- * @public
127
- */
128
- export interface RulesTestEnvironment {
129
- /** The project ID specified or discovered at test environment creation. */
130
- readonly projectId: string;
131
- /**
132
- * A readonly copy of the emulator config specified or discovered at test environment creation.
133
- */
134
- readonly emulators: {
135
- database?: HostAndPort;
136
- firestore?: HostAndPort;
137
- storage?: HostAndPort;
138
- };
139
- /**
140
- * Create a {@code RulesTestContext} which behaves like an authenticated Firebase Auth user.
141
- *
142
- * Requests created via the returned context will have a mock Firebase Auth token attached.
143
- *
144
- * @param user_id the User ID of the user. Specifies the value of "user_id" and "sub" on the token
145
- * @param tokenOptions custom claims or overrides for Firebase Auth token payloads
146
- *
147
- * @example
148
- * ```javascript
149
- * const alice = testEnv.authenticatedContext('alice');
150
- * await assertSucceeds(get(doc(alice.firestore(), '/doc/readable/by/alice'), { ... });
151
- * ```
152
- */
153
- authenticatedContext(user_id: string, tokenOptions?: TokenOptions): RulesTestContext;
154
- /**
155
- * Create a {@code RulesTestContext} which behaves like client that is NOT logged in via Firebase
156
- * Auth.
157
- *
158
- * Requests created via the returned context will not have Firebase Auth tokens attached.
159
- *
160
- * @example
161
- * ```javascript
162
- * const unauthed = testEnv.unauthenticatedContext();
163
- * await assertFails(get(doc(unauthed.firestore(), '/private/doc'), { ... });
164
- * ```
165
- */
166
- unauthenticatedContext(): RulesTestContext;
167
- withSecurityRulesDisabled(callback: (context: RulesTestContext) => Promise<void>): Promise<void>;
168
- /**
169
- * Clear all data in the Realtime Database emulator namespace.
170
- */
171
- clearDatabase(): Promise<void>;
172
- /**
173
- * Clear data in the Firestore that belongs to the {@code projectId} in the Firestore emulator.
174
- */
175
- clearFirestore(): Promise<void>;
176
- /**
177
- * Clear Storage files and metadata in all buckets in the Storage emulator.
178
- */
179
- clearStorage(): Promise<void>;
180
- /**
181
- * At the very end of your test code, call the cleanup function. Destroy all RulesTestContexts
182
- * created in test environment and clean up the underlying resources, allowing a clean exit.
183
- *
184
- * This method does not change the state in emulators in any way. To reset data between tests,
185
- * see {@code clearDatabase()}, {@code clearFirestore()} and {@code clearStorage()}.
186
- */
187
- cleanup(): Promise<void>;
188
- }
189
- /**
190
- * A test context that represents a client. Can be used to access emulators for rules unit testing.
191
- * @public
192
- */
193
- export interface RulesTestContext {
194
- /**
195
- * Get a Firestore instance for this test context. The returned Firebase JS Client SDK instance
196
- * can be used with the client SDK APIs (v9 modular or v9 compat).
197
- *
198
- * See: https://firebase.google.com/docs/reference/js/v9/firestore_
199
- * @param settings a settings object to configure the {@code Firestore} instance
200
- * @returns a Firestore instance configured to connect to the emulator
201
- * @public
202
- */
203
- firestore(settings?: firebase.firestore.Settings): firebase.firestore.Firestore;
204
- /**
205
- * Get a Firestore instance for this test context. The returned Firebase JS Client SDK instance
206
- * can be used with the client SDK APIs (v9 modular or v9 compat).
207
- *
208
- * See: https://firebase.google.com/docs/reference/js/v9/firestore_
209
- * @param databaseURL the URL of the Realtime Database instance. If specified, returns an instance
210
- * for an emulated version of the namespace with parameters extracted from URL
211
- * @returns a Database instance configured to connect to the emulator. It never connects to
212
- * production even if a production databaseURL is specified
213
- */
214
- database(databaseURL?: string): firebase.database.Database;
215
- /**
216
- * Get a Storage instance for this test context. The returned Firebase JS Client SDK instance
217
- * can be used with the client SDK APIs (v9 modular or v9 compat).
218
- *
219
- * See: https://firebase.google.com/docs/reference/js/v9/firestore_
220
- * @param settings the gs:// url to the Firebase Storage Bucket for testing. If specified,
221
- * returns a Storage instance for an emulated version of the bucket name
222
- * @returns a Storage instance configured to connect to the emulator
223
- */
224
- storage(bucketUrl?: string): firebase.storage.Storage;
225
- }
@@ -1,75 +0,0 @@
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
- /**
18
- * Run a setup function with background Cloud Functions triggers disabled. This can be used to
19
- * import data into the Realtime Database or Cloud Firestore emulator without triggering locally
20
- * emulated Cloud Functions.
21
- *
22
- * This method only works with Firebase CLI version 8.13.0 or higher. This overload works only if
23
- * the Emulator hub host:port is specified by the environment variable FIREBASE_EMULATOR_HUB.
24
- *
25
- * @param fn an function which may be sync or async (returns a promise)
26
- * @public
27
- */
28
- export declare function withFunctionTriggersDisabled<TResult>(fn: () => TResult | Promise<TResult>): Promise<TResult>;
29
- /**
30
- * Run a setup function with background Cloud Functions triggers disabled. This can be used to
31
- * import data into the Realtime Database or Cloud Firestore emulator without triggering locally
32
- * emulated Cloud Functions.
33
- *
34
- * This method only works with Firebase CLI version 8.13.0 or higher. The Emulator hub must be
35
- * running, which host and port are specified in this overload.
36
- *
37
- * @param fn an function which may be sync or async (returns a promise)
38
- * @param hub the host and port of the Emulator Hub (ex: `{host: 'localhost', port: 4400}`)
39
- * @public
40
- */
41
- export declare function withFunctionTriggersDisabled<TResult>(hub: {
42
- host: string;
43
- port: number;
44
- }, fn: () => TResult | Promise<TResult>): Promise<TResult>;
45
- /**
46
- * Assert the promise to be rejected with a "permission denied" error.
47
- *
48
- * Useful to assert a certain request to be denied by Security Rules. See example below.
49
- * This function recognizes permission-denied errors from Database, Firestore, and Storage JS SDKs.
50
- *
51
- * @param pr the promise to be asserted
52
- * @returns a Promise that is fulfilled if pr is rejected with "permission denied". If pr is
53
- * rejected with any other error or resolved, the returned promise rejects.
54
- * @public
55
- * @example
56
- * ```javascript
57
- * const unauthed = testEnv.unauthenticatedContext();
58
- * await assertFails(get(doc(unauthed.firestore(), '/private/doc'), { ... });
59
- * ```
60
- */
61
- export declare function assertFails(pr: Promise<any>): Promise<any>;
62
- /**
63
- * Assert the promise to be rejected with a "permission denied" error.
64
- *
65
- * This is a no-op function returning the passed promise as-is, but can be used for documentational
66
- * purposes in test code to emphasize that a certain request should succeed (e.g. allowed by rules).
67
- *
68
- * @public
69
- * @example
70
- * ```javascript
71
- * const alice = testEnv.authenticatedContext('alice');
72
- * await assertSucceeds(get(doc(alice.firestore(), '/doc/readable/by/alice'), { ... });
73
- * ```
74
- */
75
- export declare function assertSucceeds<T>(pr: Promise<T>): Promise<T>;
@@ -1,17 +0,0 @@
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
- export {};
@@ -1,17 +0,0 @@
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
- export {};
@@ -1,19 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2019 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
- export declare const mochaHooks: {
18
- afterEach(): void;
19
- };
@@ -1,18 +0,0 @@
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
- export declare function stashEnvVars(): void;
18
- export declare function restoreEnvVars(): void;
@@ -1,17 +0,0 @@
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
- export {};