@@ -1110,6 +1110,7 @@ describe('admin.auth', () => {
1110
1110
const uid = generateRandomString ( 20 ) . toLowerCase ( ) ;
1111
1111
const email = uid + '@example.com' ;
1112
1112
const newEmail = uid + '[email protected] ' ;
1113
+ const newEmail2 = uid + '[email protected] ' ;
1113
1114
const newPassword = 'newPassword' ;
1114
1115
const userData = {
1115
1116
uid,
@@ -1242,20 +1243,20 @@ describe('admin.auth', () => {
1242
1243
// Ensure old password set on created user.
1243
1244
return getAuth ( ) . updateUser ( uid , { password : 'password' } )
1244
1245
. then ( ( ) => {
1245
- return getAuth ( ) . generatePasswordResetLink ( email , actionCodeSettingsWithCustomDomain ) ;
1246
+ return getAuth ( ) . generatePasswordResetLink ( newEmail , actionCodeSettingsWithCustomDomain ) ;
1246
1247
} )
1247
1248
. then ( ( link ) => {
1248
- const code = getActionCode ( link ) ;
1249
+ const code = getActionCodeForInAppRequest ( link ) ;
1249
1250
expect ( getContinueUrlForInAppRequest ( link ) ) . equal ( actionCodeSettings . url ) ;
1250
1251
expect ( getHostName ( link ) ) . equal ( actionCodeSettingsWithCustomDomain . linkDomain ) ;
1251
1252
return clientAuth ( ) . confirmPasswordReset ( code , newPassword ) ;
1252
1253
} )
1253
1254
. then ( ( ) => {
1254
- return clientAuth ( ) . signInWithEmailAndPassword ( email , newPassword ) ;
1255
+ return clientAuth ( ) . signInWithEmailAndPassword ( newEmail , newPassword ) ;
1255
1256
} )
1256
1257
. then ( ( result ) => {
1257
1258
expect ( result . user ) . to . exist ;
1258
- expect ( result . user ! . email ) . to . equal ( email ) ;
1259
+ expect ( result . user ! . email ) . to . equal ( newEmail ) ;
1259
1260
// Password reset also verifies the user's email.
1260
1261
expect ( result . user ! . emailVerified ) . to . be . true ;
1261
1262
} ) ;
@@ -1266,23 +1267,23 @@ describe('admin.auth', () => {
1266
1267
return this . skip ( ) ; // Not yet supported in Auth Emulator.
1267
1268
}
1268
1269
// Ensure the user's email is unverified.
1269
- return getAuth ( ) . updateUser ( uid , { password : '123456 ' , emailVerified : false } )
1270
+ return getAuth ( ) . updateUser ( uid , { password : 'password ' , emailVerified : false } )
1270
1271
. then ( ( userRecord ) => {
1271
1272
expect ( userRecord . emailVerified ) . to . be . false ;
1272
- return getAuth ( ) . generateEmailVerificationLink ( email , actionCodeSettingsWithCustomDomain ) ;
1273
+ return getAuth ( ) . generateEmailVerificationLink ( newEmail , actionCodeSettingsWithCustomDomain ) ;
1273
1274
} )
1274
1275
. then ( ( link ) => {
1275
- const code = getActionCode ( link ) ;
1276
+ const code = getActionCodeForInAppRequest ( link ) ;
1276
1277
expect ( getContinueUrlForInAppRequest ( link ) ) . equal ( actionCodeSettings . url ) ;
1277
1278
expect ( getHostName ( link ) ) . equal ( actionCodeSettingsWithCustomDomain . linkDomain ) ;
1278
1279
return clientAuth ( ) . applyActionCode ( code ) ;
1279
1280
} )
1280
1281
. then ( ( ) => {
1281
- return clientAuth ( ) . signInWithEmailAndPassword ( email , userData . password ) ;
1282
+ return clientAuth ( ) . signInWithEmailAndPassword ( newEmail , userData . password ) ;
1282
1283
} )
1283
1284
. then ( ( result ) => {
1284
1285
expect ( result . user ) . to . exist ;
1285
- expect ( result . user ! . email ) . to . equal ( email ) ;
1286
+ expect ( result . user ! . email ) . to . equal ( newEmail ) ;
1286
1287
expect ( result . user ! . emailVerified ) . to . be . true ;
1287
1288
} ) ;
1288
1289
} ) ;
@@ -1309,23 +1310,23 @@ describe('admin.auth', () => {
1309
1310
return this . skip ( ) ; // Not yet supported in Auth Emulator.
1310
1311
}
1311
1312
// Ensure the user's email is verified.
1312
- return getAuth ( ) . updateUser ( uid , { password : '123456 ' , emailVerified : true } )
1313
+ return getAuth ( ) . updateUser ( uid , { password : 'password ' , emailVerified : true } )
1313
1314
. then ( ( userRecord ) => {
1314
1315
expect ( userRecord . emailVerified ) . to . be . true ;
1315
- return getAuth ( ) . generateVerifyAndChangeEmailLink ( email , newEmail , actionCodeSettingsWithCustomDomain ) ;
1316
+ return getAuth ( ) . generateVerifyAndChangeEmailLink ( newEmail , newEmail2 , actionCodeSettingsWithCustomDomain ) ;
1316
1317
} )
1317
1318
. then ( ( link ) => {
1318
- const code = getActionCode ( link ) ;
1319
+ const code = getActionCodeForInAppRequest ( link ) ;
1319
1320
expect ( getContinueUrlForInAppRequest ( link ) ) . equal ( actionCodeSettings . url ) ;
1320
1321
expect ( getHostName ( link ) ) . equal ( actionCodeSettingsWithCustomDomain . linkDomain ) ;
1321
1322
return clientAuth ( ) . applyActionCode ( code ) ;
1322
1323
} )
1323
1324
. then ( ( ) => {
1324
- return clientAuth ( ) . signInWithEmailAndPassword ( newEmail , 'password' ) ;
1325
+ return clientAuth ( ) . signInWithEmailAndPassword ( newEmail2 , 'password' ) ;
1325
1326
} )
1326
1327
. then ( ( result ) => {
1327
1328
expect ( result . user ) . to . exist ;
1328
- expect ( result . user ! . email ) . to . equal ( newEmail ) ;
1329
+ expect ( result . user ! . email ) . to . equal ( newEmail2 ) ;
1329
1330
expect ( result . user ! . emailVerified ) . to . be . true ;
1330
1331
} ) ;
1331
1332
} ) ;
@@ -3438,19 +3439,44 @@ function getHostName(link: string): string {
3438
3439
* Coninue URL will be part of action link url
3439
3440
*
3440
3441
* @param link The link to parse for continue url
3441
- * @returns
3442
+ * @returns Link's corresponding continueUrl
3442
3443
*/
3443
3444
function getContinueUrlForInAppRequest ( link : string ) : string {
3445
+ const actionUrl = extractLinkUrl ( link ) ;
3446
+ const continueUrl = actionUrl . searchParams . get ( 'continueUrl' ) ;
3447
+ expect ( continueUrl ) . to . exist ;
3448
+ return continueUrl ! ;
3449
+ }
3450
+
3451
+ /**
3452
+ * Returns the action code corresponding to the link for in app requests.
3453
+ * URL will be of the form, http://abc/__/auth/link?link=<action link url>
3454
+ * oobCode will be part of action link url
3455
+ *
3456
+ * @param link The link to parse for the action code.
3457
+ * @return The link's corresponding action code.
3458
+ */
3459
+ function getActionCodeForInAppRequest ( link : string ) : string {
3460
+ const actionUrl = extractLinkUrl ( link ) ;
3461
+ const oobCode = actionUrl . searchParams . get ( 'oobCode' ) ;
3462
+ expect ( oobCode ) . to . exist ;
3463
+ return oobCode ! ;
3464
+ }
3465
+
3466
+ /**
3467
+ * Extract URL in link parameter from the full link
3468
+ * URL will be of the form, http://abc/__/auth/link?link=<action link url>
3469
+ *
3470
+ * @param link The link to parse for the param
3471
+ * @returns URL inside link param
3472
+ */
3473
+ function extractLinkUrl ( link : string ) : url . URL {
3444
3474
// Extract action url from link param
3445
3475
const parsedUrl = new url . URL ( link ) ;
3446
3476
const linkParam = parsedUrl . searchParams . get ( 'link' ) ?? '' ;
3447
3477
expect ( linkParam ) . is . not . empty ;
3448
-
3449
- // Extract continueUrl param from action url
3450
- const actionUrl = new url . URL ( linkParam ) ;
3451
- const continueUrl = actionUrl . searchParams . get ( 'continueUrl' ) ;
3452
- expect ( continueUrl ) . to . exist ;
3453
- return continueUrl ! ;
3478
+
3479
+ return new url . URL ( linkParam ) ;
3454
3480
}
3455
3481
3456
3482
/**
0 commit comments