|
| 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