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' ;
1920import * as sinon from 'sinon' ;
2021
22+ import { FirebaseError } from '@firebase/util' ;
23+
2124import {
2225 mockEndpoint ,
2326 mockEndpointWithParams
@@ -37,6 +40,8 @@ import { FAKE_TOKEN } from '../recaptcha/recaptcha_enterprise_verifier';
3740import { MockGreCAPTCHATopLevel } from '../recaptcha/recaptcha_mock' ;
3841import { ApplicationVerifierInternal } from '../../model/application_verifier' ;
3942
43+ use ( chaiAsPromised ) ;
44+
4045describe ( 'platform_browser/providers/phone' , ( ) => {
4146 let auth : TestAuth ;
4247 let v2Verifier : ApplicationVerifierInternal ;
@@ -104,6 +109,83 @@ 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+
146+ it ( 'calls the server without appVerifier when recaptcha enterprise is enabled' , async ( ) => {
147+ const recaptchaConfigResponseEnforce = {
148+ recaptchaKey : 'foo/bar/to/site-key' ,
149+ recaptchaEnforcementState : [
150+ {
151+ provider : RecaptchaAuthProvider . PHONE_PROVIDER ,
152+ enforcementState : EnforcementState . ENFORCE
153+ }
154+ ]
155+ } ;
156+ const recaptcha = new MockGreCAPTCHATopLevel ( ) ;
157+ if ( typeof window === 'undefined' ) {
158+ return ;
159+ }
160+ window . grecaptcha = recaptcha ;
161+ sinon
162+ . stub ( recaptcha . enterprise , 'execute' )
163+ . returns ( Promise . resolve ( 'enterprise-token' ) ) ;
164+
165+ mockEndpointWithParams (
166+ Endpoint . GET_RECAPTCHA_CONFIG ,
167+ {
168+ clientType : RecaptchaClientType . WEB ,
169+ version : RecaptchaVersion . ENTERPRISE
170+ } ,
171+ recaptchaConfigResponseEnforce
172+ ) ;
173+
174+ const route = mockEndpoint ( Endpoint . SEND_VERIFICATION_CODE , {
175+ sessionInfo : 'verification-id'
176+ } ) ;
177+
178+ const provider = new PhoneAuthProvider ( auth ) ;
179+ const result = await provider . verifyPhoneNumber ( '+15105550000' ) ;
180+ expect ( result ) . to . eq ( 'verification-id' ) ;
181+ expect ( route . calls [ 0 ] . request ) . to . eql ( {
182+ phoneNumber : '+15105550000' ,
183+ captchaResponse : 'enterprise-token' ,
184+ clientType : RecaptchaClientType . WEB ,
185+ recaptchaVersion : RecaptchaVersion . ENTERPRISE
186+ } ) ;
187+ } ) ;
188+
107189 it ( 'calls the server when recaptcha enterprise is enabled' , async ( ) => {
108190 const recaptchaConfigResponseEnforce = {
109191 recaptchaKey : 'foo/bar/to/site-key' ,
0 commit comments