@@ -162,44 +162,95 @@ pytest --cov=firebase_admin --cov=tests
162
162
163
163
### Integration Testing
164
164
165
- A suite of integration tests are available under the ` integration/ ` directory.
166
- These tests are designed to run against an actual Firebase project. Create a new
167
- project in the [ Firebase Console] ( https://console.firebase.google.com ) , if you
168
- do not already have one suitable for running the tests aginst. Then obtain the
169
- following credentials from the project:
170
-
171
- 1 . * Service account certificate* : This can be downloaded as a JSON file from
172
- the "Settings > Service Accounts" tab of the Firebase console. Copy the
173
- file into the repo so it's available at ` cert.json ` .
174
- 2 . * Web API key* : This is displayed in the "Settings > General" tab of the
175
- console. Copy it and save to a new text file at ` apikey.txt ` .
176
-
177
- Then set up your Firebase/GCP project as follows:
178
-
179
- 1 . Enable Firestore: Go to the Firebase Console, and select "Database" from
180
- the "Develop" menu. Click on the "Create database" button. You may choose
181
- to set up Firestore either in the locked mode or in the test mode.
182
- 2 . Enable password auth: Select "Authentication" from the "Develop" menu in
183
- Firebase Console. Select the "Sign-in method" tab, and enable the
184
- "Email/Password" sign-in method, including the Email link (passwordless
185
- sign-in) option.
186
- 3 . Enable the Firebase ML API: Go to the
187
- [ Google Developers Console] (
188
- https://console.developers.google.com/apis/api/firebaseml.googleapis.com/overview )
189
- and make sure your project is selected. If the API is not already enabled, click Enable.
190
- 4 . Enable the IAM API: Go to the
191
- [ Google Cloud Platform Console] ( https://console.cloud.google.com ) and make
192
- sure your Firebase/GCP project is selected. Select "APIs & Services >
193
- Dashboard" from the main menu, and click the "ENABLE APIS AND SERVICES"
194
- button. Search for and enable the "Identity and Access Management (IAM)
195
- API".
196
- 5 . Grant your service account the 'Firebase Authentication Admin' role. This is
197
- required to ensure that exported user records contain the password hashes of
198
- the user accounts:
199
- 1 . Go to [ Google Cloud Platform Console / IAM & admin] ( https://console.cloud.google.com/iam-admin ) .
200
- 2 . Find your service account in the list, and click the 'pencil' icon to edit it's permissions.
201
- 3 . Click 'ADD ANOTHER ROLE' and choose 'Firebase Authentication Admin'.
202
- 4 . Click 'SAVE'.
165
+
166
+ Integration tests are executed against a real life Firebase project. If you do not already
167
+ have one suitable for running the tests against, you can create a new project in the
168
+ [ Firebase Console] ( https://console.firebase.google.com ) following the setup guide below.
169
+ If you already have a Firebase project, you'll need to obtain credentials to communicate and
170
+ authorize access to your Firebase project:
171
+
172
+
173
+ 1 . Service account certificate: This allows access to your Firebase project through a service account
174
+ which is required for all integration tests. This can be downloaded as a JSON file from the
175
+ ** Settings > Service Accounts** tab of the Firebase console when you click the
176
+ ** Generate new private key** button. Copy the file into the repo so it's available at ` cert.json ` .
177
+ > ** Note:** Service accounts should be carefully managed and their keys should never be stored in publicly accessible source code or repositories.
178
+
179
+
180
+ 2 . Web API key: This allows for Auth sign-in needed for some Authentication and Tenant Management
181
+ integration tests. This is displayed in the ** Settings > General** tab of the Firebase console
182
+ after enabling Authentication as described in the steps below. Copy it and save to a new text
183
+ file at ` apikey.txt ` .
184
+
185
+
186
+ Set up your Firebase project as follows:
187
+
188
+
189
+ 1 . Enable Authentication:
190
+ 1 . Go to the Firebase Console, and select ** Authentication** from the ** Build** menu.
191
+ 2 . Click on ** Get Started** .
192
+ 3 . Select ** Sign-in method > Add new provider > Email/Password** then enable both the
193
+ ** Email/Password** and ** Email link (passwordless sign-in)** options.
194
+
195
+
196
+ 2 . Enable Firestore:
197
+ 1 . Go to the Firebase Console, and select ** Firestore Database** from the ** Build** menu.
198
+ 2 . Click on the ** Create database** button. You can choose to set up Firestore either in
199
+ the production mode or in the test mode.
200
+
201
+
202
+ 3 . Enable Realtime Database:
203
+ 1 . Go to the Firebase Console, and select ** Realtime Database** from the ** Build** menu.
204
+ 2 . Click on the ** Create Database** button. You can choose to set up the Realtime Database
205
+ either in the locked mode or in the test mode.
206
+
207
+ > ** Note:** Integration tests are not run against the default Realtime Database reference and are
208
+ instead run against a database created at ` https://{PROJECT_ID}.firebaseio.com ` .
209
+ This second Realtime Database reference is created in the following steps.
210
+
211
+ 3 . In the ** Data** tab click on the kebab menu (3 dots) and select ** Create Database** .
212
+ 4 . Enter your Project ID (Found in the ** General** tab in ** Account Settings** ) as the
213
+ ** Realtime Database reference** . Again, you can choose to set up the Realtime Database
214
+ either in the locked mode or in the test mode.
215
+
216
+
217
+ 4 . Enable Storage:
218
+ 1 . Go to the Firebase Console, and select ** Storage** from the ** Build** menu.
219
+ 2 . Click on the ** Get started** button. You can choose to set up Cloud Storage
220
+ either in the production mode or in the test mode.
221
+
222
+
223
+ 5 . Enable the Firebase ML API:
224
+ 1 . Go to the
225
+ [ Google Cloud console | Firebase ML API] ( https://console.cloud.google.com/apis/api/firebaseml.googleapis.com/overview )
226
+ and make sure your project is selected.
227
+ 2 . If the API is not already enabled, click ** Enable** .
228
+
229
+
230
+ 6 . Enable the IAM API:
231
+ 1 . Go to the [ Google Cloud console] ( https://console.cloud.google.com )
232
+ and make sure your Firebase project is selected.
233
+ 2 . Select ** APIs & Services** from the main menu, and click the
234
+ ** ENABLE APIS AND SERVICES** button.
235
+ 3 . Search for and enable ** Identity and Access Management (IAM) API** by Google Enterprise API.
236
+
237
+
238
+ 7 . Enable Tenant Management:
239
+ 1 . Go to
240
+ [ Google Cloud console | Identity Platform] ( https://console.cloud.google.com/customer-identity/ )
241
+ and if it is not already enabled, click ** Enable** .
242
+ 2 . Then
243
+ [ enable multi-tenancy] ( https://cloud.google.com/identity-platform/docs/multi-tenancy-quickstart#enabling_multi-tenancy )
244
+ for your project.
245
+
246
+
247
+ 8 . Ensure your service account has the ** Firebase Authentication Admin** role. This is required
248
+ to ensure that exported user records contain the password hashes of the user accounts:
249
+ 1 . Go to [ Google Cloud console | IAM & admin] ( https://console.cloud.google.com/iam-admin ) .
250
+ 2 . Find your service account in the list. If not added click the pencil icon to edit its
251
+ permissions.
252
+ 3 . Click ** ADD ANOTHER ROLE** and choose ** Firebase Authentication Admin** .
253
+ 4 . Click ** SAVE** .
203
254
204
255
205
256
Now you can invoke the integration test suite as follows:
0 commit comments