@@ -54,8 +54,17 @@ import { MockGreCAPTCHATopLevel } from '../../platform_browser/recaptcha/recaptc
54
54
use ( chaiAsPromised ) ;
55
55
use ( sinonChai ) ;
56
56
57
+ const TEST_ID_TOKEN = 'id-token' ;
58
+ const TEST_REFRESH_TOKEN = 'refresh-token' ;
59
+ const TEST_TOKEN_EXPIRY_TIME = '1234' ;
60
+
61
+ const TEST_LOCAL_ID = 'local-id' ;
62
+
63
+ const TEST_EMAIL = '[email protected] ' ;
64
+ const TEST_PASSWORD = 'some-password' ;
65
+
57
66
describe ( 'core/strategies/sendPasswordResetEmail' , ( ) => {
58
- const email = '[email protected] ' ;
67
+ const email = TEST_EMAIL ;
59
68
60
69
let auth : TestAuth ;
61
70
@@ -323,7 +332,7 @@ describe('core/strategies/confirmPasswordReset', () => {
323
332
324
333
it ( 'should confirm the password reset and not return the email' , async ( ) => {
325
334
const mock = mockEndpoint ( Endpoint . RESET_PASSWORD , {
326
-
335
+ email : TEST_EMAIL
327
336
} ) ;
328
337
const response = await confirmPasswordReset ( auth , oobCode , newPassword ) ;
329
338
expect ( response ) . to . be . undefined ;
@@ -395,7 +404,7 @@ describe('core/strategies/applyActionCode', () => {
395
404
396
405
describe ( 'core/strategies/checkActionCode' , ( ) => {
397
406
const oobCode = 'oob-code' ;
398
- const email = '[email protected] ' ;
407
+ const email = TEST_EMAIL ;
399
408
const newEmail = '[email protected] ' ;
400
409
401
410
let auth : TestAuth ;
@@ -410,7 +419,7 @@ describe('core/strategies/checkActionCode', () => {
410
419
it ( 'should verify the oob code' , async ( ) => {
411
420
const mock = mockEndpoint ( Endpoint . RESET_PASSWORD , {
412
421
requestType : ActionCodeOperation . PASSWORD_RESET ,
413
-
422
+ email : TEST_EMAIL
414
423
} ) ;
415
424
const response = await checkActionCode ( auth , oobCode ) ;
416
425
expect ( response ) . to . eql ( {
@@ -478,7 +487,7 @@ describe('core/strategies/checkActionCode', () => {
478
487
479
488
describe ( 'core/strategies/verifyPasswordResetCode' , ( ) => {
480
489
const oobCode = 'oob-code' ;
481
- const email = '[email protected] ' ;
490
+ const email = TEST_EMAIL ;
482
491
483
492
let auth : TestAuth ;
484
493
@@ -492,7 +501,7 @@ describe('core/strategies/verifyPasswordResetCode', () => {
492
501
it ( 'should verify the oob code' , async ( ) => {
493
502
const mock = mockEndpoint ( Endpoint . RESET_PASSWORD , {
494
503
requestType : ActionCodeOperation . PASSWORD_RESET ,
495
-
504
+ email : TEST_EMAIL ,
496
505
previousEmail : null
497
506
} ) ;
498
507
const response = await verifyPasswordResetCode ( auth , oobCode ) ;
@@ -535,16 +544,16 @@ describe('core/strategies/verifyPasswordResetCode', () => {
535
544
describe ( 'core/strategies/email_and_password/createUserWithEmailAndPassword' , ( ) => {
536
545
let auth : TestAuth ;
537
546
const serverUser : APIUserInfo = {
538
- localId : 'local-id'
547
+ localId : TEST_LOCAL_ID
539
548
} ;
540
549
541
550
beforeEach ( async ( ) => {
542
551
auth = await testAuth ( ) ;
543
552
mockFetch . setUp ( ) ;
544
553
mockEndpoint ( Endpoint . SIGN_UP , {
545
- idToken : 'id-token' ,
546
- refreshToken : 'refresh-token' ,
547
- expiresIn : '1234' ,
554
+ idToken : TEST_ID_TOKEN ,
555
+ refreshToken : TEST_REFRESH_TOKEN ,
556
+ expiresIn : TEST_TOKEN_EXPIRY_TIME ,
548
557
localId : serverUser . localId !
549
558
} ) ;
550
559
mockEndpoint ( Endpoint . GET_ACCOUNT_INFO , {
@@ -557,13 +566,13 @@ describe('core/strategies/email_and_password/createUserWithEmailAndPassword', ()
557
566
const { _tokenResponse, user, operationType } =
558
567
( await createUserWithEmailAndPassword (
559
568
auth ,
560
- 'some-email' ,
561
- 'some-password'
569
+ TEST_EMAIL ,
570
+ TEST_PASSWORD
562
571
) ) as UserCredentialInternal ;
563
572
expect ( _tokenResponse ) . to . eql ( {
564
- idToken : 'id-token' ,
565
- refreshToken : 'refresh-token' ,
566
- expiresIn : '1234' ,
573
+ idToken : TEST_ID_TOKEN ,
574
+ refreshToken : TEST_REFRESH_TOKEN ,
575
+ expiresIn : TEST_TOKEN_EXPIRY_TIME ,
567
576
localId : serverUser . localId !
568
577
} ) ;
569
578
expect ( operationType ) . to . eq ( OperationType . SIGN_IN ) ;
@@ -622,13 +631,13 @@ describe('core/strategies/email_and_password/createUserWithEmailAndPassword', ()
622
631
const { _tokenResponse, user, operationType } =
623
632
( await createUserWithEmailAndPassword (
624
633
auth ,
625
- 'some-email' ,
626
- 'some-password'
634
+ TEST_EMAIL ,
635
+ TEST_PASSWORD
627
636
) ) as UserCredentialInternal ;
628
637
expect ( _tokenResponse ) . to . eql ( {
629
- idToken : 'id-token' ,
630
- refreshToken : 'refresh-token' ,
631
- expiresIn : '1234' ,
638
+ idToken : TEST_ID_TOKEN ,
639
+ refreshToken : TEST_REFRESH_TOKEN ,
640
+ expiresIn : TEST_TOKEN_EXPIRY_TIME ,
632
641
localId : serverUser . localId !
633
642
} ) ;
634
643
expect ( operationType ) . to . eq ( OperationType . SIGN_IN ) ;
@@ -653,13 +662,13 @@ describe('core/strategies/email_and_password/createUserWithEmailAndPassword', ()
653
662
const { _tokenResponse, user, operationType } =
654
663
( await createUserWithEmailAndPassword (
655
664
auth ,
656
- 'some-email' ,
657
- 'some-password'
665
+ TEST_EMAIL ,
666
+ TEST_PASSWORD
658
667
) ) as UserCredentialInternal ;
659
668
expect ( _tokenResponse ) . to . eql ( {
660
- idToken : 'id-token' ,
661
- refreshToken : 'refresh-token' ,
662
- expiresIn : '1234' ,
669
+ idToken : TEST_ID_TOKEN ,
670
+ refreshToken : TEST_REFRESH_TOKEN ,
671
+ expiresIn : TEST_TOKEN_EXPIRY_TIME ,
663
672
localId : serverUser . localId !
664
673
} ) ;
665
674
expect ( operationType ) . to . eq ( OperationType . SIGN_IN ) ;
@@ -676,8 +685,8 @@ describe('core/strategies/email_and_password/createUserWithEmailAndPassword', ()
676
685
mockEndpointWithParams (
677
686
Endpoint . SIGN_UP ,
678
687
{
679
- email : 'some-email' ,
680
- password : 'some-password' ,
688
+ email : TEST_EMAIL ,
689
+ password : TEST_PASSWORD ,
681
690
clientType : RecaptchaClientType . WEB
682
691
} ,
683
692
{
@@ -693,16 +702,16 @@ describe('core/strategies/email_and_password/createUserWithEmailAndPassword', ()
693
702
mockEndpointWithParams (
694
703
Endpoint . SIGN_UP ,
695
704
{
696
- email : 'some-email' ,
697
- password : 'some-password' ,
705
+ email : TEST_EMAIL ,
706
+ password : TEST_PASSWORD ,
698
707
captchaResp : 'recaptcha-response' ,
699
708
clientType : RecaptchaClientType . WEB ,
700
709
recaptchaVersion : RecaptchaVersion . ENTERPRISE
701
710
} ,
702
711
{
703
- idToken : 'id-token' ,
704
- refreshToken : 'refresh-token' ,
705
- expiresIn : '1234' ,
712
+ idToken : TEST_ID_TOKEN ,
713
+ refreshToken : TEST_REFRESH_TOKEN ,
714
+ expiresIn : TEST_TOKEN_EXPIRY_TIME ,
706
715
localId : serverUser . localId !
707
716
}
708
717
) ;
@@ -731,13 +740,13 @@ describe('core/strategies/email_and_password/createUserWithEmailAndPassword', ()
731
740
const { _tokenResponse, user, operationType } =
732
741
( await createUserWithEmailAndPassword (
733
742
auth ,
734
- 'some-email' ,
735
- 'some-password'
743
+ TEST_EMAIL ,
744
+ TEST_PASSWORD
736
745
) ) as UserCredentialInternal ;
737
746
expect ( _tokenResponse ) . to . eql ( {
738
- idToken : 'id-token' ,
739
- refreshToken : 'refresh-token' ,
740
- expiresIn : '1234' ,
747
+ idToken : TEST_ID_TOKEN ,
748
+ refreshToken : TEST_REFRESH_TOKEN ,
749
+ expiresIn : TEST_TOKEN_EXPIRY_TIME ,
741
750
localId : serverUser . localId !
742
751
} ) ;
743
752
expect ( operationType ) . to . eq ( OperationType . SIGN_IN ) ;
@@ -750,16 +759,16 @@ describe('core/strategies/email_and_password/createUserWithEmailAndPassword', ()
750
759
describe ( 'core/strategies/email_and_password/signInWithEmailAndPassword' , ( ) => {
751
760
let auth : TestAuth ;
752
761
const serverUser : APIUserInfo = {
753
- localId : 'local-id'
762
+ localId : TEST_LOCAL_ID
754
763
} ;
755
764
756
765
beforeEach ( async ( ) => {
757
766
auth = await testAuth ( ) ;
758
767
mockFetch . setUp ( ) ;
759
768
mockEndpoint ( Endpoint . SIGN_IN_WITH_PASSWORD , {
760
- idToken : 'id-token' ,
761
- refreshToken : 'refresh-token' ,
762
- expiresIn : '1234' ,
769
+ idToken : TEST_ID_TOKEN ,
770
+ refreshToken : TEST_REFRESH_TOKEN ,
771
+ expiresIn : TEST_TOKEN_EXPIRY_TIME ,
763
772
localId : serverUser . localId !
764
773
} ) ;
765
774
mockEndpoint ( Endpoint . GET_ACCOUNT_INFO , {
@@ -772,13 +781,13 @@ describe('core/strategies/email_and_password/signInWithEmailAndPassword', () =>
772
781
const { _tokenResponse, user, operationType } =
773
782
( await signInWithEmailAndPassword (
774
783
auth ,
775
- 'some-email' ,
776
- 'some-password'
784
+ TEST_EMAIL ,
785
+ TEST_PASSWORD
777
786
) ) as UserCredentialInternal ;
778
787
expect ( _tokenResponse ) . to . eql ( {
779
- idToken : 'id-token' ,
780
- refreshToken : 'refresh-token' ,
781
- expiresIn : '1234' ,
788
+ idToken : TEST_ID_TOKEN ,
789
+ refreshToken : TEST_REFRESH_TOKEN ,
790
+ expiresIn : TEST_TOKEN_EXPIRY_TIME ,
782
791
localId : serverUser . localId !
783
792
} ) ;
784
793
expect ( operationType ) . to . eq ( OperationType . SIGN_IN ) ;
@@ -829,8 +838,6 @@ describe('password policy cache is updated in auth flows upon error', () => {
829
838
allowedNonAlphanumericCharacters : TEST_ALLOWED_NON_ALPHANUMERIC_STRING ,
830
839
schemaVersion : TEST_SCHEMA_VERSION
831
840
} ;
832
- const TEST_EMAIL = '[email protected] ' ;
833
- const TEST_PASSWORD = 'some-password' ;
834
841
let policyEndpointMock : mockFetch . Route ;
835
842
let policyEndpointMockWithTenant : mockFetch . Route ;
836
843
let policyEndpointMockWithOtherTenant : mockFetch . Route ;
@@ -862,14 +869,14 @@ describe('password policy cache is updated in auth flows upon error', () => {
862
869
863
870
context ( '#createUserWithEmailAndPassword' , ( ) => {
864
871
const TEST_SERVER_USER : APIUserInfo = {
865
- localId : 'local-id'
872
+ localId : TEST_LOCAL_ID
866
873
} ;
867
874
868
875
beforeEach ( ( ) => {
869
876
mockEndpoint ( Endpoint . SIGN_UP , {
870
- idToken : 'id-token' ,
871
- refreshToken : 'refresh-token' ,
872
- expiresIn : '1234' ,
877
+ idToken : TEST_ID_TOKEN ,
878
+ refreshToken : TEST_REFRESH_TOKEN ,
879
+ expiresIn : TEST_TOKEN_EXPIRY_TIME ,
873
880
localId : TEST_SERVER_USER . localId !
874
881
} ) ;
875
882
mockEndpoint ( Endpoint . GET_ACCOUNT_INFO , {
@@ -911,7 +918,7 @@ describe('password policy cache is updated in auth flows upon error', () => {
911
918
) ;
912
919
} ) ;
913
920
914
- it ( 'updates the cached password policy when password does not meet backend requirements' , async ( ) => {
921
+ it ( 'updates the cached password policy when password does not meet backend requirements for the project ' , async ( ) => {
915
922
await auth . _updatePasswordPolicy ( ) ;
916
923
expect ( policyEndpointMock . calls . length ) . to . eq ( 1 ) ;
917
924
expect ( auth . _getPasswordPolicyInternal ( ) ) . to . eql (
@@ -930,6 +937,27 @@ describe('password policy cache is updated in auth flows upon error', () => {
930
937
) ;
931
938
} ) ;
932
939
940
+ it ( 'updates the cached password policy when password does not meet backend requirements for the tenant' , async ( ) => {
941
+ auth . tenantId = TEST_TENANT_ID ;
942
+ await auth . _updatePasswordPolicy ( ) ;
943
+ expect ( policyEndpointMockWithTenant . calls . length ) . to . eq ( 1 ) ;
944
+ expect ( auth . _getPasswordPolicyInternal ( ) ) . to . eql (
945
+ CACHED_PASSWORD_POLICY
946
+ ) ;
947
+
948
+ // Password policy changed after previous fetch.
949
+ policyEndpointMockWithTenant . response =
950
+ PASSWORD_POLICY_RESPONSE_REQUIRE_NUMERIC ;
951
+ await expect (
952
+ createUserWithEmailAndPassword ( auth , TEST_EMAIL , TEST_PASSWORD )
953
+ ) . to . be . rejectedWith ( FirebaseError , PASSWORD_ERROR_MSG ) ;
954
+
955
+ expect ( policyEndpointMockWithTenant . calls . length ) . to . eq ( 2 ) ;
956
+ expect ( auth . _getPasswordPolicyInternal ( ) ) . to . eql (
957
+ CACHED_PASSWORD_POLICY_REQUIRE_NUMERIC
958
+ ) ;
959
+ } ) ;
960
+
933
961
it ( 'does not update the cached password policy upon error if policy has not previously been fetched' , async ( ) => {
934
962
expect ( auth . _getPasswordPolicyInternal ( ) ) . to . be . null ;
935
963
@@ -1000,7 +1028,7 @@ describe('password policy cache is updated in auth flows upon error', () => {
1000
1028
) ;
1001
1029
} ) ;
1002
1030
1003
- it ( 'updates the cached password policy when password does not meet backend requirements' , async ( ) => {
1031
+ it ( 'updates the cached password policy when password does not meet backend requirements for the project ' , async ( ) => {
1004
1032
await auth . _updatePasswordPolicy ( ) ;
1005
1033
expect ( policyEndpointMock . calls . length ) . to . eq ( 1 ) ;
1006
1034
expect ( auth . _getPasswordPolicyInternal ( ) ) . to . eql (
@@ -1019,6 +1047,27 @@ describe('password policy cache is updated in auth flows upon error', () => {
1019
1047
) ;
1020
1048
} ) ;
1021
1049
1050
+ it ( 'updates the cached password policy when password does not meet backend requirements for the tenant' , async ( ) => {
1051
+ auth . tenantId = TEST_TENANT_ID ;
1052
+ await auth . _updatePasswordPolicy ( ) ;
1053
+ expect ( policyEndpointMockWithTenant . calls . length ) . to . eq ( 1 ) ;
1054
+ expect ( auth . _getPasswordPolicyInternal ( ) ) . to . eql (
1055
+ CACHED_PASSWORD_POLICY
1056
+ ) ;
1057
+
1058
+ // Password policy changed after previous fetch.
1059
+ policyEndpointMockWithTenant . response =
1060
+ PASSWORD_POLICY_RESPONSE_REQUIRE_NUMERIC ;
1061
+ await expect (
1062
+ confirmPasswordReset ( auth , TEST_OOB_CODE , TEST_PASSWORD )
1063
+ ) . to . be . rejectedWith ( FirebaseError , PASSWORD_ERROR_MSG ) ;
1064
+
1065
+ expect ( policyEndpointMockWithTenant . calls . length ) . to . eq ( 2 ) ;
1066
+ expect ( auth . _getPasswordPolicyInternal ( ) ) . to . eql (
1067
+ CACHED_PASSWORD_POLICY_REQUIRE_NUMERIC
1068
+ ) ;
1069
+ } ) ;
1070
+
1022
1071
it ( 'does not update the cached password policy upon error if policy has not previously been fetched' , async ( ) => {
1023
1072
expect ( auth . _getPasswordPolicyInternal ( ) ) . to . be . null ;
1024
1073
0 commit comments