Skip to content

Commit 28096d4

Browse files
committed
Add additional tests
1 parent d9e456b commit 28096d4

File tree

1 file changed

+78
-1
lines changed

1 file changed

+78
-1
lines changed

test/integration/auth.spec.ts

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ const actionCodeSettingsWithCustomDomain: ActionCodeSettings = {
8888
bundleId: 'com.google.experimental1.dev.extension0',
8989
},
9090
}
91+
const actionCodeSettingsForFdlLinks: ActionCodeSettings = {
92+
url: 'http://localhost/?a=1&b=2#c=3',
93+
handleCodeInApp: true,
94+
iOS: {
95+
bundleId: 'com.google.experimental1.dev.extension0',
96+
},
97+
}
9198
let deleteQueue = Promise.resolve();
9299

93100
interface UserImportTest {
@@ -1114,6 +1121,13 @@ describe('admin.auth', () => {
11141121

11151122
// Create the test user before running this suite of tests.
11161123
before(() => {
1124+
// Update project config to have HOSTING_DOMAIN as mobileLinksConfig after each test
1125+
const updateMobileLinksRequest: UpdateProjectConfigRequest = {
1126+
mobileLinksConfig: {
1127+
domain: 'HOSTING_DOMAIN',
1128+
},
1129+
};
1130+
getAuth().projectConfigManager().updateProjectConfig(updateMobileLinksRequest);
11171131
return getAuth().createUser(userData);
11181132
});
11191133

@@ -1316,6 +1330,54 @@ describe('admin.auth', () => {
13161330
expect(result.user!.emailVerified).to.be.true;
13171331
});
13181332
});
1333+
1334+
it('generateSignInWithEmailLink() should return a FDL sign-in'
1335+
+ 'link with mobileLinksConfig set to FIREBASE_DYNAMIC_LINK_DOMAIN', function () {
1336+
if (authEmulatorHost) {
1337+
return this.skip(); // Not yet supported in Auth Emulator.
1338+
}
1339+
1340+
const updateMobileLinksRequest: UpdateProjectConfigRequest = {
1341+
mobileLinksConfig: {
1342+
domain: 'FIREBASE_DYNAMIC_LINK_DOMAIN',
1343+
}
1344+
};
1345+
return getAuth().projectConfigManager().updateProjectConfig(updateMobileLinksRequest)
1346+
.then((projectConfig) => {
1347+
expect(projectConfig?.mobileLinksConfig?.domain).equal('FIREBASE_DYNAMIC_LINK_DOMAIN');
1348+
return getAuth().generateSignInWithEmailLink(email, actionCodeSettingsForFdlLinks);
1349+
}).then((link) => {
1350+
expectFDLLink(link);
1351+
return clientAuth().signInWithEmailLink(email, link);
1352+
}).then((result) => {
1353+
expect(result.user).to.exist;
1354+
expect(result.user!.email).to.equal(email);
1355+
expect(result.user!.emailVerified).to.be.true;
1356+
});
1357+
});
1358+
1359+
it('generateSignInWithEmailLink() should return a FDL sign-in link with empty mobileLinksConfig', function () {
1360+
if (authEmulatorHost) {
1361+
return this.skip(); // Not yet supported in Auth Emulator.
1362+
}
1363+
1364+
const updateMobileLinksRequest: UpdateProjectConfigRequest = {
1365+
mobileLinksConfig: {
1366+
}
1367+
};
1368+
return getAuth().projectConfigManager().updateProjectConfig(updateMobileLinksRequest)
1369+
.then((projectConfig) => {
1370+
expect(projectConfig.mobileLinksConfig).is.empty;
1371+
return getAuth().generateSignInWithEmailLink(email, actionCodeSettingsForFdlLinks);
1372+
}).then((link) => {
1373+
expectFDLLink(link);
1374+
return clientAuth().signInWithEmailLink(email, link);
1375+
}).then((result) => {
1376+
expect(result.user).to.exist;
1377+
expect(result.user!.email).to.equal(email);
1378+
expect(result.user!.emailVerified).to.be.true;
1379+
});
1380+
});
13191381
});
13201382

13211383
describe('Project config management operations', () => {
@@ -3339,7 +3401,7 @@ function getHostName(link: string): string {
33393401
* URL will be of the form, http://abc/__/auth/link?link=<action link url>
33403402
* Coninue URL will be part of action link url
33413403
*
3342-
* @param link
3404+
* @param link The link to parse for continue url
33433405
* @returns
33443406
*/
33453407
function getContinueUrlForInAppRequest(link: string): string {
@@ -3355,6 +3417,21 @@ function getContinueUrlForInAppRequest(link: string): string {
33553417
return continueUrl!;
33563418
}
33573419

3420+
/**
3421+
* Verify if the generated link is generated by FDL
3422+
* We leverage the params created by FDL to test whether a given link is FDL
3423+
*
3424+
* @param link Link to check whether it is FDL
3425+
*/
3426+
function expectFDLLink(link: string): void {
3427+
const parsedUrl = new url.URL(link);
3428+
// For ios, FDL creates a fallback url with param ifl
3429+
// We leverage that to test whether a given link is FDL link
3430+
// Note: This param does not exist when the link is generated for HOSTING_DOMAIN
3431+
const iflParam = parsedUrl.searchParams.get('ifl');
3432+
expect(iflParam).is.not.null;
3433+
}
3434+
33583435
/**
33593436
* Returns the tenant ID corresponding to the link.
33603437
*

0 commit comments

Comments
 (0)