@@ -184,32 +184,17 @@ describe('core/credentials/email', () => {
184184 } ) ;
185185 } ) ;
186186
187- it ( 'calls sign in with password with recaptcha forced refresh succeed ' , async ( ) => {
187+ it ( 'calls sign in with password with recaptcha forced refresh' , async ( ) => {
188188 if ( typeof window === 'undefined' ) {
189189 return ;
190190 }
191- // Mock recaptcha js loading method and manually set window.recaptcha
191+ // Mock recaptcha js loading method but not set window.recaptcha to simulate recaptcha token retrieval failure
192192 sinon
193193 . stub ( jsHelpers , '_loadJS' )
194194 . returns ( Promise . resolve ( new Event ( '' ) ) ) ;
195- const recaptcha = new MockGreCAPTCHATopLevel ( ) ;
196- window . grecaptcha = recaptcha ;
197- const stub = sinon . stub ( recaptcha . enterprise , 'execute' ) ;
198-
199- // First verification should fail with 'wrong-site-key'
200- stub
201- . withArgs ( 'wrong-site-key' , {
202- action : RecaptchaActionName . SIGN_IN_WITH_PASSWORD
203- } )
204- . rejects ( ) ;
205- // Second verifcation should succeed with site key refreshed
206- stub
207- . withArgs ( 'site-key' , {
208- action : RecaptchaActionName . SIGN_IN_WITH_PASSWORD
209- } )
210- . returns ( Promise . resolve ( 'recaptcha-response' ) ) ;
195+ window . grecaptcha = undefined ;
211196
212- mockEndpointWithParams (
197+ const getRecaptchaConfigMock = mockEndpointWithParams (
213198 Endpoint . GET_RECAPTCHA_CONFIG ,
214199 {
215200 clientType : RecaptchaClientType . WEB ,
@@ -218,21 +203,14 @@ describe('core/credentials/email', () => {
218203 recaptchaConfigResponseEnforce
219204 ) ;
220205 await auth . initializeRecaptchaConfig ( ) ;
221- auth . _agentRecaptchaConfig ! . siteKey = 'wrong -site-key' ;
206+ auth . _agentRecaptchaConfig ! . siteKey = 'cached -site-key' ;
222207
223- const idTokenResponse = await credential . _getIdTokenResponse ( auth ) ;
224- expect ( idTokenResponse . idToken ) . to . eq ( 'id-token' ) ;
225- expect ( idTokenResponse . refreshToken ) . to . eq ( 'refresh-token' ) ;
226- expect ( idTokenResponse . expiresIn ) . to . eq ( '1234' ) ;
227- expect ( idTokenResponse . localId ) . to . eq ( serverUser . localId ) ;
228- expect ( apiMock . calls [ 0 ] . request ) . to . eql ( {
229- captchaResponse : 'recaptcha-response' ,
230- clientType : RecaptchaClientType . WEB ,
231- email : 'some-email' ,
232- password : 'some-password' ,
233- recaptchaVersion : RecaptchaVersion . ENTERPRISE ,
234- returnSecureToken : true
235- } ) ;
208+ await expect ( credential . _getIdTokenResponse ( auth ) ) . to . be . rejectedWith (
209+ 'No reCAPTCHA enterprise script loaded.'
210+ ) ;
211+ // Should call getRecaptchaConfig once to refresh the cached recaptcha config
212+ expect ( getRecaptchaConfigMock . calls . length ) . to . eq ( 2 ) ;
213+ expect ( auth . _agentRecaptchaConfig ?. siteKey ) . to . eq ( 'site-key' ) ;
236214 } ) ;
237215
238216 it ( 'calls fallback to recaptcha flow when receiving MISSING_RECAPTCHA_TOKEN error' , async ( ) => {
0 commit comments