@@ -35,14 +35,20 @@ import { RecaptchaVerifier } from '../../platform_browser/recaptcha/recaptcha_ve
35
35
import { PhoneAuthProvider } from './phone' ;
36
36
import { FAKE_TOKEN } from '../recaptcha/recaptcha_enterprise_verifier' ;
37
37
import { MockGreCAPTCHATopLevel } from '../recaptcha/recaptcha_mock' ;
38
+ import { ApplicationVerifierInternal } from '../../model/application_verifier' ;
38
39
39
40
describe ( 'platform_browser/providers/phone' , ( ) => {
40
41
let auth : TestAuth ;
42
+ let v2Verifier : ApplicationVerifierInternal ;
41
43
42
44
beforeEach ( async ( ) => {
43
45
fetch . setUp ( ) ;
44
46
auth = await testAuth ( ) ;
45
47
auth . settings . appVerificationDisabledForTesting = false ;
48
+ v2Verifier = new RecaptchaVerifier ( auth , document . createElement ( 'div' ) , { } ) ;
49
+ sinon
50
+ . stub ( v2Verifier , 'verify' )
51
+ . returns ( Promise . resolve ( 'verification-code' ) ) ;
46
52
} ) ;
47
53
48
54
afterEach ( ( ) => {
@@ -83,14 +89,52 @@ describe('platform_browser/providers/phone', () => {
83
89
sessionInfo : 'verification-id'
84
90
} ) ;
85
91
86
- const v2Verifier = new RecaptchaVerifier (
87
- auth ,
88
- document . createElement ( 'div' ) ,
89
- { }
92
+ const provider = new PhoneAuthProvider ( auth ) ;
93
+ const result = await provider . verifyPhoneNumber (
94
+ '+15105550000' ,
95
+ v2Verifier
90
96
) ;
97
+ expect ( result ) . to . eq ( 'verification-id' ) ;
98
+ expect ( route . calls [ 0 ] . request ) . to . eql ( {
99
+ phoneNumber : '+15105550000' ,
100
+ recaptchaToken : 'verification-code' ,
101
+ captchaResponse : FAKE_TOKEN ,
102
+ clientType : RecaptchaClientType . WEB ,
103
+ recaptchaVersion : RecaptchaVersion . ENTERPRISE
104
+ } ) ;
105
+ } ) ;
106
+
107
+ it ( 'calls the server when recaptcha enterprise is enabled' , async ( ) => {
108
+ const recaptchaConfigResponseEnforce = {
109
+ recaptchaKey : 'foo/bar/to/site-key' ,
110
+ recaptchaEnforcementState : [
111
+ {
112
+ provider : RecaptchaAuthProvider . PHONE_PROVIDER ,
113
+ enforcementState : EnforcementState . ENFORCE
114
+ }
115
+ ]
116
+ } ;
117
+ const recaptcha = new MockGreCAPTCHATopLevel ( ) ;
118
+ if ( typeof window === 'undefined' ) {
119
+ return ;
120
+ }
121
+ window . grecaptcha = recaptcha ;
91
122
sinon
92
- . stub ( v2Verifier , 'verify' )
93
- . returns ( Promise . resolve ( 'verification-code' ) ) ;
123
+ . stub ( recaptcha . enterprise , 'execute' )
124
+ . returns ( Promise . resolve ( 'enterprise-token' ) ) ;
125
+
126
+ mockEndpointWithParams (
127
+ Endpoint . GET_RECAPTCHA_CONFIG ,
128
+ {
129
+ clientType : RecaptchaClientType . WEB ,
130
+ version : RecaptchaVersion . ENTERPRISE
131
+ } ,
132
+ recaptchaConfigResponseEnforce
133
+ ) ;
134
+
135
+ const route = mockEndpoint ( Endpoint . SEND_VERIFICATION_CODE , {
136
+ sessionInfo : 'verification-id'
137
+ } ) ;
94
138
95
139
const provider = new PhoneAuthProvider ( auth ) ;
96
140
const result = await provider . verifyPhoneNumber (
@@ -100,8 +144,7 @@ describe('platform_browser/providers/phone', () => {
100
144
expect ( result ) . to . eq ( 'verification-id' ) ;
101
145
expect ( route . calls [ 0 ] . request ) . to . eql ( {
102
146
phoneNumber : '+15105550000' ,
103
- recaptchaToken : 'verification-code' ,
104
- captchaResponse : FAKE_TOKEN ,
147
+ captchaResponse : 'enterprise-token' ,
105
148
clientType : RecaptchaClientType . WEB ,
106
149
recaptchaVersion : RecaptchaVersion . ENTERPRISE
107
150
} ) ;
0 commit comments