Skip to content

Commit 904928b

Browse files
pashankaXiaoshouzi-gh
authored andcommitted
Fix failing FDL deprecation integration tests (#2762)
1 parent 4c3b05f commit 904928b

File tree

1 file changed

+47
-21
lines changed

1 file changed

+47
-21
lines changed

test/integration/auth.spec.ts

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,7 @@ describe('admin.auth', () => {
11101110
const uid = generateRandomString(20).toLowerCase();
11111111
const email = uid + '@example.com';
11121112
const newEmail = uid + '[email protected]';
1113+
const newEmail2 = uid + '[email protected]';
11131114
const newPassword = 'newPassword';
11141115
const userData = {
11151116
uid,
@@ -1242,20 +1243,20 @@ describe('admin.auth', () => {
12421243
// Ensure old password set on created user.
12431244
return getAuth().updateUser(uid, { password: 'password' })
12441245
.then(() => {
1245-
return getAuth().generatePasswordResetLink(email, actionCodeSettingsWithCustomDomain);
1246+
return getAuth().generatePasswordResetLink(newEmail, actionCodeSettingsWithCustomDomain);
12461247
})
12471248
.then((link) => {
1248-
const code = getActionCode(link);
1249+
const code = getActionCodeForInAppRequest(link);
12491250
expect(getContinueUrlForInAppRequest(link)).equal(actionCodeSettings.url);
12501251
expect(getHostName(link)).equal(actionCodeSettingsWithCustomDomain.linkDomain);
12511252
return clientAuth().confirmPasswordReset(code, newPassword);
12521253
})
12531254
.then(() => {
1254-
return clientAuth().signInWithEmailAndPassword(email, newPassword);
1255+
return clientAuth().signInWithEmailAndPassword(newEmail, newPassword);
12551256
})
12561257
.then((result) => {
12571258
expect(result.user).to.exist;
1258-
expect(result.user!.email).to.equal(email);
1259+
expect(result.user!.email).to.equal(newEmail);
12591260
// Password reset also verifies the user's email.
12601261
expect(result.user!.emailVerified).to.be.true;
12611262
});
@@ -1266,23 +1267,23 @@ describe('admin.auth', () => {
12661267
return this.skip(); // Not yet supported in Auth Emulator.
12671268
}
12681269
// 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 })
12701271
.then((userRecord) => {
12711272
expect(userRecord.emailVerified).to.be.false;
1272-
return getAuth().generateEmailVerificationLink(email, actionCodeSettingsWithCustomDomain);
1273+
return getAuth().generateEmailVerificationLink(newEmail, actionCodeSettingsWithCustomDomain);
12731274
})
12741275
.then((link) => {
1275-
const code = getActionCode(link);
1276+
const code = getActionCodeForInAppRequest(link);
12761277
expect(getContinueUrlForInAppRequest(link)).equal(actionCodeSettings.url);
12771278
expect(getHostName(link)).equal(actionCodeSettingsWithCustomDomain.linkDomain);
12781279
return clientAuth().applyActionCode(code);
12791280
})
12801281
.then(() => {
1281-
return clientAuth().signInWithEmailAndPassword(email, userData.password);
1282+
return clientAuth().signInWithEmailAndPassword(newEmail, userData.password);
12821283
})
12831284
.then((result) => {
12841285
expect(result.user).to.exist;
1285-
expect(result.user!.email).to.equal(email);
1286+
expect(result.user!.email).to.equal(newEmail);
12861287
expect(result.user!.emailVerified).to.be.true;
12871288
});
12881289
});
@@ -1309,23 +1310,23 @@ describe('admin.auth', () => {
13091310
return this.skip(); // Not yet supported in Auth Emulator.
13101311
}
13111312
// 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 })
13131314
.then((userRecord) => {
13141315
expect(userRecord.emailVerified).to.be.true;
1315-
return getAuth().generateVerifyAndChangeEmailLink(email, newEmail, actionCodeSettingsWithCustomDomain);
1316+
return getAuth().generateVerifyAndChangeEmailLink(newEmail, newEmail2, actionCodeSettingsWithCustomDomain);
13161317
})
13171318
.then((link) => {
1318-
const code = getActionCode(link);
1319+
const code = getActionCodeForInAppRequest(link);
13191320
expect(getContinueUrlForInAppRequest(link)).equal(actionCodeSettings.url);
13201321
expect(getHostName(link)).equal(actionCodeSettingsWithCustomDomain.linkDomain);
13211322
return clientAuth().applyActionCode(code);
13221323
})
13231324
.then(() => {
1324-
return clientAuth().signInWithEmailAndPassword(newEmail, 'password');
1325+
return clientAuth().signInWithEmailAndPassword(newEmail2, 'password');
13251326
})
13261327
.then((result) => {
13271328
expect(result.user).to.exist;
1328-
expect(result.user!.email).to.equal(newEmail);
1329+
expect(result.user!.email).to.equal(newEmail2);
13291330
expect(result.user!.emailVerified).to.be.true;
13301331
});
13311332
});
@@ -3438,19 +3439,44 @@ function getHostName(link: string): string {
34383439
* Coninue URL will be part of action link url
34393440
*
34403441
* @param link The link to parse for continue url
3441-
* @returns
3442+
* @returns Link's corresponding continueUrl
34423443
*/
34433444
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 {
34443474
// Extract action url from link param
34453475
const parsedUrl = new url.URL(link);
34463476
const linkParam = parsedUrl.searchParams.get('link') ?? '';
34473477
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);
34543480
}
34553481

34563482
/**

0 commit comments

Comments
 (0)