@@ -26,6 +26,9 @@ import * as identity from "../../../src/common/providers/identity";
2626
2727const EVENT = "EVENT_TYPE" ;
2828const now = new Date ( ) ;
29+ const TEST_NAME = "John Doe" ;
30+ const ALLOW = "ALLOW" ;
31+ const BLOCK = "BLOCK" ;
2932
3033describe ( "identity" , ( ) => {
3134 describe ( "userRecordConstructor" , ( ) => {
@@ -232,14 +235,14 @@ describe("identity", () => {
232235 describe ( "parseProviderData" , ( ) => {
233236 const decodedUserInfo = {
234237 provider_id : "google.com" ,
235- display_name : "John Doe" ,
238+ display_name : TEST_NAME ,
236239 photo_url : "https://lh3.googleusercontent.com/1234567890/photo.jpg" ,
237240 uid : "1234567890" ,
238241 email : "user@gmail.com" ,
239242 } ;
240243 const userInfo = {
241244 providerId : "google.com" ,
242- displayName : "John Doe" ,
245+ displayName : TEST_NAME ,
243246 photoURL : "https://lh3.googleusercontent.com/1234567890/photo.jpg" ,
244247 uid : "1234567890" ,
245248 email : "user@gmail.com" ,
@@ -340,12 +343,12 @@ describe("identity", () => {
340343 uid : "abcdefghijklmnopqrstuvwxyz" ,
341344 email : "user@gmail.com" ,
342345 email_verified : true ,
343- display_name : "John Doe" ,
346+ display_name : TEST_NAME ,
344347 phone_number : "+11234567890" ,
345348 provider_data : [
346349 {
347350 provider_id : "google.com" ,
348- display_name : "John Doe" ,
351+ display_name : TEST_NAME ,
349352 photo_url : "https://lh3.googleusercontent.com/1234567890/photo.jpg" ,
350353 email : "user@gmail.com" ,
351354 uid : "1234567890" ,
@@ -366,7 +369,7 @@ describe("identity", () => {
366369 provider_id : "password" ,
367370 email : "user@gmail.com" ,
368371 uid : "user@gmail.com" ,
369- display_name : "John Doe" ,
372+ display_name : TEST_NAME ,
370373 } ,
371374 ] ,
372375 password_hash : "passwordHash" ,
@@ -407,11 +410,11 @@ describe("identity", () => {
407410 phoneNumber : "+11234567890" ,
408411 emailVerified : true ,
409412 disabled : false ,
410- displayName : "John Doe" ,
413+ displayName : TEST_NAME ,
411414 providerData : [
412415 {
413416 providerId : "google.com" ,
414- displayName : "John Doe" ,
417+ displayName : TEST_NAME ,
415418 photoURL : "https://lh3.googleusercontent.com/1234567890/photo.jpg" ,
416419 email : "user@gmail.com" ,
417420 uid : "1234567890" ,
@@ -435,7 +438,7 @@ describe("identity", () => {
435438 } ,
436439 {
437440 providerId : "password" ,
438- displayName : "John Doe" ,
441+ displayName : TEST_NAME ,
439442 photoURL : undefined ,
440443 email : "user@gmail.com" ,
441444 uid : "user@gmail.com" ,
@@ -489,8 +492,9 @@ describe("identity", () => {
489492 } ) ;
490493
491494 describe ( "parseAuthEventContext" , ( ) => {
495+ const TEST_RECAPTCHA_SCORE = 0.9 ;
492496 const rawUserInfo = {
493- name : "John Doe" ,
497+ name : TEST_NAME ,
494498 granted_scopes :
495499 "openid https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile" ,
496500 id : "123456789" ,
@@ -516,6 +520,7 @@ describe("identity", () => {
516520 user_agent : "USER_AGENT" ,
517521 locale : "en" ,
518522 raw_user_info : JSON . stringify ( rawUserInfo ) ,
523+ recaptcha_score : TEST_RECAPTCHA_SCORE ,
519524 } ;
520525 const context = {
521526 locale : "en" ,
@@ -534,6 +539,7 @@ describe("identity", () => {
534539 profile : rawUserInfo ,
535540 username : undefined ,
536541 isNewUser : false ,
542+ recaptchaScore : TEST_RECAPTCHA_SCORE ,
537543 } ,
538544 credential : null ,
539545 params : { } ,
@@ -563,6 +569,7 @@ describe("identity", () => {
563569 oauth_refresh_token : "REFRESH_TOKEN" ,
564570 oauth_token_secret : "OAUTH_TOKEN_SECRET" ,
565571 oauth_expires_in : 3600 ,
572+ recaptcha_score : TEST_RECAPTCHA_SCORE ,
566573 } ;
567574 const context = {
568575 locale : "en" ,
@@ -581,6 +588,7 @@ describe("identity", () => {
581588 profile : rawUserInfo ,
582589 username : undefined ,
583590 isNewUser : false ,
591+ recaptchaScore : TEST_RECAPTCHA_SCORE ,
584592 } ,
585593 credential : {
586594 claims : undefined ,
@@ -619,14 +627,14 @@ describe("identity", () => {
619627 uid : "abcdefghijklmnopqrstuvwxyz" ,
620628 email : "user@gmail.com" ,
621629 email_verified : true ,
622- display_name : "John Doe" ,
630+ display_name : TEST_NAME ,
623631 phone_number : "+11234567890" ,
624632 provider_data : [
625633 {
626634 provider_id : "oidc.provider" ,
627635 email : "user@gmail.com" ,
628636 uid : "user@gmail.com" ,
629- display_name : "John Doe" ,
637+ display_name : TEST_NAME ,
630638 } ,
631639 ] ,
632640 photo_url : "https://lh3.googleusercontent.com/1234567890/photo.jpg" ,
@@ -647,6 +655,7 @@ describe("identity", () => {
647655 oauth_token_secret : "OAUTH_TOKEN_SECRET" ,
648656 oauth_expires_in : 3600 ,
649657 raw_user_info : JSON . stringify ( rawUserInfo ) ,
658+ recaptcha_score : TEST_RECAPTCHA_SCORE ,
650659 } ;
651660 const context = {
652661 locale : "en" ,
@@ -665,6 +674,7 @@ describe("identity", () => {
665674 providerId : "oidc.provider" ,
666675 profile : rawUserInfo ,
667676 isNewUser : true ,
677+ recaptchaScore : TEST_RECAPTCHA_SCORE ,
668678 } ,
669679 credential : {
670680 claims : undefined ,
@@ -762,4 +772,52 @@ describe("identity", () => {
762772 ) ;
763773 } ) ;
764774 } ) ;
775+
776+ describe ( "generateResponsePayload" , ( ) => {
777+ const DISPLAY_NAME_FIELD = "displayName" ;
778+ const TEST_RESPONSE = {
779+ displayName : TEST_NAME ,
780+ recaptchaActionOverride : BLOCK ,
781+ } as identity . BeforeCreateResponse ;
782+
783+ const EXPECT_PAYLOAD = {
784+ userRecord : { displayName : TEST_NAME , updateMask : DISPLAY_NAME_FIELD } ,
785+ recaptchaActionOverride : BLOCK ,
786+ } ;
787+
788+ const TEST_RESPONSE_RECAPTCHA_ALLOW = {
789+ recaptchaActionOverride : ALLOW ,
790+ } as identity . BeforeCreateResponse ;
791+
792+ const EXPECT_PAYLOAD_RECAPTCHA_ALLOW = {
793+ recaptchaActionOverride : ALLOW ,
794+ } ;
795+
796+ const TEST_RESPONSE_RECAPTCHA_UNDEFINED = {
797+ displayName : TEST_NAME ,
798+ } as identity . BeforeSignInResponse ;
799+
800+ const EXPECT_PAYLOAD_UNDEFINED = {
801+ userRecord : { displayName : TEST_NAME , updateMask : DISPLAY_NAME_FIELD } ,
802+ } ;
803+ it ( "should return empty object on undefined response" , ( ) => {
804+ expect ( identity . generateResponsePayload ( ) ) . to . eql ( { } ) ;
805+ } ) ;
806+
807+ it ( "should exclude recaptchaActionOverride field from updateMask" , ( ) => {
808+ expect ( identity . generateResponsePayload ( TEST_RESPONSE ) ) . to . deep . equal ( EXPECT_PAYLOAD ) ;
809+ } ) ;
810+
811+ it ( "should return recaptchaActionOverride when it is true on response" , ( ) => {
812+ expect ( identity . generateResponsePayload ( TEST_RESPONSE_RECAPTCHA_ALLOW ) ) . to . deep . equal (
813+ EXPECT_PAYLOAD_RECAPTCHA_ALLOW
814+ ) ;
815+ } ) ;
816+
817+ it ( "should not return recaptchaActionOverride if undefined" , ( ) => {
818+ const payload = identity . generateResponsePayload ( TEST_RESPONSE_RECAPTCHA_UNDEFINED ) ;
819+ expect ( payload . hasOwnProperty ( "recaptchaActionOverride" ) ) . to . be . false ;
820+ expect ( payload ) . to . deep . equal ( EXPECT_PAYLOAD_UNDEFINED ) ;
821+ } ) ;
822+ } ) ;
765823} ) ;
0 commit comments