@@ -26,6 +26,9 @@ import * as identity from "../../../src/common/providers/identity";
26
26
27
27
const EVENT = "EVENT_TYPE" ;
28
28
const now = new Date ( ) ;
29
+ const TEST_NAME = "John Doe" ;
30
+ const ALLOW = "ALLOW" ;
31
+ const BLOCK = "BLOCK" ;
29
32
30
33
describe ( "identity" , ( ) => {
31
34
describe ( "userRecordConstructor" , ( ) => {
@@ -232,14 +235,14 @@ describe("identity", () => {
232
235
describe ( "parseProviderData" , ( ) => {
233
236
const decodedUserInfo = {
234
237
provider_id : "google.com" ,
235
- display_name : "John Doe" ,
238
+ display_name : TEST_NAME ,
236
239
photo_url : "https://lh3.googleusercontent.com/1234567890/photo.jpg" ,
237
240
uid : "1234567890" ,
238
241
239
242
} ;
240
243
const userInfo = {
241
244
providerId : "google.com" ,
242
- displayName : "John Doe" ,
245
+ displayName : TEST_NAME ,
243
246
photoURL : "https://lh3.googleusercontent.com/1234567890/photo.jpg" ,
244
247
uid : "1234567890" ,
245
248
@@ -340,12 +343,12 @@ describe("identity", () => {
340
343
uid : "abcdefghijklmnopqrstuvwxyz" ,
341
344
342
345
email_verified : true ,
343
- display_name : "John Doe" ,
346
+ display_name : TEST_NAME ,
344
347
phone_number : "+11234567890" ,
345
348
provider_data : [
346
349
{
347
350
provider_id : "google.com" ,
348
- display_name : "John Doe" ,
351
+ display_name : TEST_NAME ,
349
352
photo_url : "https://lh3.googleusercontent.com/1234567890/photo.jpg" ,
350
353
351
354
uid : "1234567890" ,
@@ -366,7 +369,7 @@ describe("identity", () => {
366
369
provider_id : "password" ,
367
370
368
371
369
- display_name : "John Doe" ,
372
+ display_name : TEST_NAME ,
370
373
} ,
371
374
] ,
372
375
password_hash : "passwordHash" ,
@@ -407,11 +410,11 @@ describe("identity", () => {
407
410
phoneNumber : "+11234567890" ,
408
411
emailVerified : true ,
409
412
disabled : false ,
410
- displayName : "John Doe" ,
413
+ displayName : TEST_NAME ,
411
414
providerData : [
412
415
{
413
416
providerId : "google.com" ,
414
- displayName : "John Doe" ,
417
+ displayName : TEST_NAME ,
415
418
photoURL : "https://lh3.googleusercontent.com/1234567890/photo.jpg" ,
416
419
417
420
uid : "1234567890" ,
@@ -435,7 +438,7 @@ describe("identity", () => {
435
438
} ,
436
439
{
437
440
providerId : "password" ,
438
- displayName : "John Doe" ,
441
+ displayName : TEST_NAME ,
439
442
photoURL : undefined ,
440
443
441
444
@@ -489,8 +492,9 @@ describe("identity", () => {
489
492
} ) ;
490
493
491
494
describe ( "parseAuthEventContext" , ( ) => {
495
+ const TEST_RECAPTCHA_SCORE = 0.9 ;
492
496
const rawUserInfo = {
493
- name : "John Doe" ,
497
+ name : TEST_NAME ,
494
498
granted_scopes :
495
499
"openid https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile" ,
496
500
id : "123456789" ,
@@ -516,6 +520,7 @@ describe("identity", () => {
516
520
user_agent : "USER_AGENT" ,
517
521
locale : "en" ,
518
522
raw_user_info : JSON . stringify ( rawUserInfo ) ,
523
+ recaptcha_score : TEST_RECAPTCHA_SCORE ,
519
524
} ;
520
525
const context = {
521
526
locale : "en" ,
@@ -534,6 +539,7 @@ describe("identity", () => {
534
539
profile : rawUserInfo ,
535
540
username : undefined ,
536
541
isNewUser : false ,
542
+ recaptchaScore : TEST_RECAPTCHA_SCORE ,
537
543
} ,
538
544
credential : null ,
539
545
params : { } ,
@@ -563,6 +569,7 @@ describe("identity", () => {
563
569
oauth_refresh_token : "REFRESH_TOKEN" ,
564
570
oauth_token_secret : "OAUTH_TOKEN_SECRET" ,
565
571
oauth_expires_in : 3600 ,
572
+ recaptcha_score : TEST_RECAPTCHA_SCORE ,
566
573
} ;
567
574
const context = {
568
575
locale : "en" ,
@@ -581,6 +588,7 @@ describe("identity", () => {
581
588
profile : rawUserInfo ,
582
589
username : undefined ,
583
590
isNewUser : false ,
591
+ recaptchaScore : TEST_RECAPTCHA_SCORE ,
584
592
} ,
585
593
credential : {
586
594
claims : undefined ,
@@ -619,14 +627,14 @@ describe("identity", () => {
619
627
uid : "abcdefghijklmnopqrstuvwxyz" ,
620
628
621
629
email_verified : true ,
622
- display_name : "John Doe" ,
630
+ display_name : TEST_NAME ,
623
631
phone_number : "+11234567890" ,
624
632
provider_data : [
625
633
{
626
634
provider_id : "oidc.provider" ,
627
635
628
636
629
- display_name : "John Doe" ,
637
+ display_name : TEST_NAME ,
630
638
} ,
631
639
] ,
632
640
photo_url : "https://lh3.googleusercontent.com/1234567890/photo.jpg" ,
@@ -647,6 +655,7 @@ describe("identity", () => {
647
655
oauth_token_secret : "OAUTH_TOKEN_SECRET" ,
648
656
oauth_expires_in : 3600 ,
649
657
raw_user_info : JSON . stringify ( rawUserInfo ) ,
658
+ recaptcha_score : TEST_RECAPTCHA_SCORE ,
650
659
} ;
651
660
const context = {
652
661
locale : "en" ,
@@ -665,6 +674,7 @@ describe("identity", () => {
665
674
providerId : "oidc.provider" ,
666
675
profile : rawUserInfo ,
667
676
isNewUser : true ,
677
+ recaptchaScore : TEST_RECAPTCHA_SCORE ,
668
678
} ,
669
679
credential : {
670
680
claims : undefined ,
@@ -762,4 +772,52 @@ describe("identity", () => {
762
772
) ;
763
773
} ) ;
764
774
} ) ;
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
+ } ) ;
765
823
} ) ;
0 commit comments