Skip to content

Commit c365447

Browse files
committed
Add more unit tests for when ApplicationVerifier is not available
1 parent 873fb89 commit c365447

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

packages/auth/src/platform_browser/providers/phone.test.ts

+40-1
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { expect } from 'chai';
18+
import { expect, use } from 'chai';
19+
import chaiAsPromised from 'chai-as-promised';
1920
import * as sinon from 'sinon';
2021

22+
import { FirebaseError } from '@firebase/util';
23+
2124
import {
2225
mockEndpoint,
2326
mockEndpointWithParams
@@ -37,6 +40,8 @@ import { FAKE_TOKEN } from '../recaptcha/recaptcha_enterprise_verifier';
3740
import { MockGreCAPTCHATopLevel } from '../recaptcha/recaptcha_mock';
3841
import { ApplicationVerifierInternal } from '../../model/application_verifier';
3942

43+
use(chaiAsPromised);
44+
4045
describe('platform_browser/providers/phone', () => {
4146
let auth: TestAuth;
4247
let v2Verifier: ApplicationVerifierInternal;
@@ -104,6 +109,40 @@ describe('platform_browser/providers/phone', () => {
104109
});
105110
});
106111

112+
it('throws an error if verify without appVerifier when recaptcha enterprise is disabled', async () => {
113+
const recaptchaConfigResponseOff = {
114+
recaptchaKey: 'foo/bar/to/site-key',
115+
recaptchaEnforcementState: [
116+
{
117+
provider: RecaptchaAuthProvider.PHONE_PROVIDER,
118+
enforcementState: EnforcementState.OFF
119+
}
120+
]
121+
};
122+
const recaptcha = new MockGreCAPTCHATopLevel();
123+
if (typeof window === 'undefined') {
124+
return;
125+
}
126+
window.grecaptcha = recaptcha;
127+
sinon
128+
.stub(recaptcha.enterprise, 'execute')
129+
.returns(Promise.resolve('enterprise-token'));
130+
131+
mockEndpointWithParams(
132+
Endpoint.GET_RECAPTCHA_CONFIG,
133+
{
134+
clientType: RecaptchaClientType.WEB,
135+
version: RecaptchaVersion.ENTERPRISE
136+
},
137+
recaptchaConfigResponseOff
138+
);
139+
140+
const provider = new PhoneAuthProvider(auth);
141+
await expect(
142+
provider.verifyPhoneNumber('+15105550000')
143+
).to.be.rejectedWith(FirebaseError, 'auth/argument-error');
144+
});
145+
107146
it('calls the server without appVerifier when recaptcha enterprise is enabled', async () => {
108147
const recaptchaConfigResponseEnforce = {
109148
recaptchaKey: 'foo/bar/to/site-key',

packages/auth/src/platform_browser/strategies/phone.test.ts

+23
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,17 @@ describe('platform_browser/strategies/phone', () => {
196196
});
197197
});
198198

199+
it('throws an error if verify phone number without a v2 RecaptchaVerifier when recaptcha enterprise is disabled', async () => {
200+
if (typeof window === 'undefined') {
201+
return;
202+
}
203+
mockRecaptchaEnterpriseEnablement(EnforcementState.OFF);
204+
205+
await expect(
206+
signInWithPhoneNumber(auth, '+15105550000')
207+
).to.be.rejectedWith(FirebaseError, 'auth/argument-error');
208+
});
209+
199210
context('ConfirmationResult', () => {
200211
it('result contains verification id baked in', async () => {
201212
if (typeof window === 'undefined') {
@@ -534,6 +545,18 @@ describe('platform_browser/strategies/phone', () => {
534545
});
535546
});
536547

548+
it('throws error if calls verify phone number without v2 RecaptchaVerifier when recaptcha enterprise is disabled', async () => {
549+
if (typeof window === 'undefined') {
550+
return;
551+
}
552+
mockRecaptchaEnterpriseEnablement(EnforcementState.OFF);
553+
554+
await expect(_verifyPhoneNumber(auth, 'number')).to.be.rejectedWith(
555+
FirebaseError,
556+
'auth/argument-error'
557+
);
558+
});
559+
537560
it('calls fallback to recaptcha v2 flow when receiving MISSING_RECAPTCHA_TOKEN error in recaptcha enterprise audit mode', async () => {
538561
if (typeof window === 'undefined') {
539562
return;

0 commit comments

Comments
 (0)