15
15
* limitations under the License.
16
16
*/
17
17
18
- import { expect } from 'chai' ;
18
+ import { expect , use } from 'chai' ;
19
+ import chaiAsPromised from 'chai-as-promised' ;
19
20
import * as sinon from 'sinon' ;
20
21
22
+ import { FirebaseError } from '@firebase/util' ;
23
+
21
24
import {
22
25
mockEndpoint ,
23
26
mockEndpointWithParams
@@ -37,6 +40,8 @@ import { FAKE_TOKEN } from '../recaptcha/recaptcha_enterprise_verifier';
37
40
import { MockGreCAPTCHATopLevel } from '../recaptcha/recaptcha_mock' ;
38
41
import { ApplicationVerifierInternal } from '../../model/application_verifier' ;
39
42
43
+ use ( chaiAsPromised ) ;
44
+
40
45
describe ( 'platform_browser/providers/phone' , ( ) => {
41
46
let auth : TestAuth ;
42
47
let v2Verifier : ApplicationVerifierInternal ;
@@ -104,6 +109,40 @@ describe('platform_browser/providers/phone', () => {
104
109
} ) ;
105
110
} ) ;
106
111
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
+
107
146
it ( 'calls the server without appVerifier when recaptcha enterprise is enabled' , async ( ) => {
108
147
const recaptchaConfigResponseEnforce = {
109
148
recaptchaKey : 'foo/bar/to/site-key' ,
0 commit comments