Skip to content

Commit 11c3963

Browse files
committed
Implement Integration test for passwordless email sign-in via firebase-hosting links.
1 parent 85ebbce commit 11c3963

File tree

2 files changed

+99
-1
lines changed

2 files changed

+99
-1
lines changed

packages/auth/karma.conf.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ function getTestFiles(argv) {
5151
if (argv.prodbackend) {
5252
return [
5353
'test/integration/flows/totp.test.ts',
54-
'test/integration/flows/password_policy.test.ts'
54+
'test/integration/flows/password_policy.test.ts',
55+
'test/integration/flows/hosting_link.test.ts'
5556
];
5657
}
5758
return argv.local
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import { ActionCodeSettings, Auth, sendSignInLinkToEmail } from '@firebase/auth';
2+
import { expect, use } from 'chai';
3+
import {
4+
getTestInstance,
5+
randomEmail
6+
} from '../../helpers/integration/helpers';
7+
import { getEmulatorUrl } from '../../helpers/integration/settings';
8+
import chaiAsPromised from 'chai-as-promised';
9+
import { FirebaseError } from '@firebase/util';
10+
11+
use(chaiAsPromised);
12+
13+
// Assumes mobileLinksConfig.domain is set as "HOSTING_DOMAIN" in the test GCP-project.
14+
describe('Integration test: hosting link validation', () => {
15+
let auth: Auth;
16+
let email: string;
17+
18+
const AUTHORIZED_CUSTOM_DOMAIN = "localhost/action_code_return";
19+
const ANDROID_PACKAGE_NAME = "com.google.firebase.test.thin";
20+
const BASE_SETTINGS: ActionCodeSettings = {
21+
url: 'http://' + AUTHORIZED_CUSTOM_DOMAIN,
22+
handleCodeInApp: true,
23+
android: {packageName: ANDROID_PACKAGE_NAME},
24+
};
25+
const VALID_LINK_DOMAIN = "jscore-sandbox.testdomaindonotuse.com";
26+
const INVALID_LINK_DOMAIN = "invalid.testdomaindonotuse.com";
27+
const INVALID_LINK_DOMAIN_ERROR = "auth/invalid-hosting-link-domain";
28+
const TEST_TENANT_ID = 'passpol-tenant-d7hha';
29+
30+
beforeEach(function () {
31+
auth = getTestInstance();
32+
email = randomEmail();
33+
34+
if (getEmulatorUrl()) {
35+
this.skip();
36+
}
37+
});
38+
39+
it('allows user to sign in with default firebase_hosting_link', async () => {
40+
// Sends email link to user using default hosting link.
41+
await sendSignInLinkToEmail(
42+
auth,
43+
email,
44+
BASE_SETTINGS
45+
);
46+
});
47+
48+
it('allows user to sign in to a tenant with default firebase_hosting_link', async () => {
49+
auth.tenantId = TEST_TENANT_ID;
50+
// Sends email link to user using default hosting link.
51+
await sendSignInLinkToEmail(
52+
auth,
53+
email,
54+
BASE_SETTINGS
55+
);
56+
});
57+
58+
it('allows user to sign in with custom firebase hosting link', async () => {
59+
// Sends email link to user using custom hosting link.
60+
await sendSignInLinkToEmail(
61+
auth,
62+
email,
63+
{
64+
...BASE_SETTINGS,
65+
linkDomain: VALID_LINK_DOMAIN
66+
67+
}
68+
);
69+
});
70+
71+
it('allows user to sign in to a tenant with custom firebase hosting link', async () => {
72+
// Sends email link to user using custom hosting link.
73+
auth.tenantId = TEST_TENANT_ID;
74+
await sendSignInLinkToEmail(
75+
auth,
76+
email,
77+
{
78+
...BASE_SETTINGS,
79+
linkDomain: VALID_LINK_DOMAIN
80+
81+
}
82+
);
83+
});
84+
85+
it('sign in with invalid firebase hosting link throws exception', async () => {
86+
// Throws an exception while sening email link to user using invalid hosting link.
87+
await expect(sendSignInLinkToEmail(
88+
auth,
89+
email,
90+
{
91+
...BASE_SETTINGS,
92+
linkDomain: INVALID_LINK_DOMAIN
93+
94+
}
95+
)).to.be.rejectedWith(FirebaseError, new RegExp(".*" + INVALID_LINK_DOMAIN_ERROR + ".*"));
96+
});
97+
});

0 commit comments

Comments
 (0)