@@ -1372,3 +1372,38 @@ describe('getAll() method', () => {
1372
1372
} ) ;
1373
1373
} ) ;
1374
1374
} ) ;
1375
+
1376
+ describe ( 'toJSON' , ( ) => {
1377
+ it ( 'Serializing Firestore settings redacts credentials' , ( ) => {
1378
+ const firestore = new Firestore . Firestore ( {
1379
+ projectId : 'myProjectId' ,
1380
+ credentials : { client_email : 'foo@bar' , private_key : 'asdf1234' } ,
1381
+ } ) ;
1382
+
1383
+ const serializedSettings = JSON . stringify ( firestore . _settings ) ;
1384
+
1385
+ // Instead of validating the serialized string for redacted credentials,
1386
+ // parse the settings and check the credential values.
1387
+ const parsedSettings = JSON . parse ( serializedSettings ) ;
1388
+ expect ( parsedSettings . credentials . client_email ) . to . equal ( '***' ) ;
1389
+ expect ( parsedSettings . credentials . private_key ) . to . equal ( '***' ) ;
1390
+ } ) ;
1391
+
1392
+ it ( 'Serializing Firestore instance' , ( ) => {
1393
+ const firestore = new Firestore . Firestore ( {
1394
+ projectId : 'myProjectId' ,
1395
+ credentials : { client_email : 'foo@bar' , private_key : 'asdf1234' } ,
1396
+ } ) ;
1397
+
1398
+ const serializedFirestore = JSON . stringify ( firestore ) ;
1399
+
1400
+ // Instead of validating the serialized string,
1401
+ // parse the JSON back to an object and check the properties.
1402
+ const expectedParsedFirestore = {
1403
+ projectId : 'myProjectId' ,
1404
+ } ;
1405
+
1406
+ const parsedFirestore = JSON . parse ( serializedFirestore ) ;
1407
+ expect ( parsedFirestore ) . to . deep . equal ( expectedParsedFirestore ) ;
1408
+ } ) ;
1409
+ } ) ;
0 commit comments