@@ -751,6 +751,12 @@ describe('core/strategies/email_and_password/createUserWithEmailAndPassword', ()
751
751
const TEST_ALLOWED_NON_ALPHANUMERIC_CHARS = [ '!' , '(' , ')' ] ;
752
752
const TEST_SCHEMA_VERSION = 1 ;
753
753
754
+ const TEST_TENANT_ID = 'tenant-id' ;
755
+ const TEST_REQUIRE_NUMERIC_TENANT_ID = 'other-tenant-id' ;
756
+
757
+ const PASSWORD_ERROR_MSG =
758
+ 'Firebase: The password does not meet the requirements. (auth/password-does-not-meet-requirements).' ;
759
+
754
760
const passwordPolicyResponse = {
755
761
customStrengthOptions : {
756
762
minPasswordLength : TEST_MIN_PASSWORD_LENGTH
@@ -792,20 +798,20 @@ describe('core/strategies/email_and_password/createUserWithEmailAndPassword', ()
792
798
policyEndpointMockWithTenant = mockEndpointWithParams (
793
799
Endpoint . GET_PASSWORD_POLICY ,
794
800
{
795
- tenantId : 'tenant-id'
801
+ tenantId : TEST_TENANT_ID
796
802
} ,
797
803
passwordPolicyResponse
798
804
) ;
799
805
policyEndpointMockWithOtherTenant = mockEndpointWithParams (
800
806
Endpoint . GET_PASSWORD_POLICY ,
801
807
{
802
- tenantId : 'other-tenant-id'
808
+ tenantId : TEST_REQUIRE_NUMERIC_TENANT_ID
803
809
} ,
804
810
passwordPolicyResponseRequireNumeric
805
811
) ;
806
812
} ) ;
807
813
808
- it ( 'does not update the password policy upon successful sign up when there is no existing policy cache' , async ( ) => {
814
+ it ( 'does not update the cached password policy upon successful sign up when there is no existing policy cache' , async ( ) => {
809
815
await expect (
810
816
createUserWithEmailAndPassword ( auth , 'some-email' , 'some-password' )
811
817
) . to . be . fulfilled ;
@@ -814,7 +820,7 @@ describe('core/strategies/email_and_password/createUserWithEmailAndPassword', ()
814
820
expect ( auth . _getPasswordPolicy ( ) ) . to . be . null ;
815
821
} ) ;
816
822
817
- it ( 'does not update the password policy upon successful sign up when there is an existing policy cache' , async ( ) => {
823
+ it ( 'does not update the cached password policy upon successful sign up when there is an existing policy cache' , async ( ) => {
818
824
await auth . _updatePasswordPolicy ( ) ;
819
825
820
826
await expect (
@@ -839,50 +845,44 @@ describe('core/strategies/email_and_password/createUserWithEmailAndPassword', ()
839
845
) ;
840
846
} ) ;
841
847
842
- it ( 'updates the password policy when password does not meet backend requirements' , async ( ) => {
848
+ it ( 'updates the cached password policy when password does not meet backend requirements' , async ( ) => {
843
849
await auth . _updatePasswordPolicy ( ) ;
844
850
expect ( policyEndpointMock . calls . length ) . to . eq ( 1 ) ;
845
851
expect ( auth . _getPasswordPolicy ( ) ) . to . eql ( cachedPasswordPolicy ) ;
846
852
853
+ // Password policy changed after previous fetch.
847
854
policyEndpointMock . response = passwordPolicyResponseRequireNumeric ;
848
855
await expect (
849
856
createUserWithEmailAndPassword ( auth , 'some-email' , 'some-password' )
850
- ) . to . be . rejectedWith (
851
- FirebaseError ,
852
- 'Firebase: The password does not meet the requirements. (auth/password-does-not-meet-requirements).'
853
- ) ;
857
+ ) . to . be . rejectedWith ( FirebaseError , PASSWORD_ERROR_MSG ) ;
854
858
855
859
expect ( policyEndpointMock . calls . length ) . to . eq ( 2 ) ;
856
860
expect ( auth . _getPasswordPolicy ( ) ) . to . eql (
857
861
cachedPasswordPolicyRequireNumeric
858
862
) ;
859
863
} ) ;
860
864
861
- it ( 'does not update the password policy upon error if policy has not previously been fetched' , async ( ) => {
865
+ it ( 'does not update the cached password policy upon error if policy has not previously been fetched' , async ( ) => {
866
+ expect ( auth . _getPasswordPolicy ( ) ) . to . be . null ;
867
+
862
868
await expect (
863
869
createUserWithEmailAndPassword ( auth , 'some-email' , 'some-password' )
864
- ) . to . be . rejectedWith (
865
- FirebaseError ,
866
- 'Firebase: The password does not meet the requirements. (auth/password-does-not-meet-requirements).'
867
- ) ;
870
+ ) . to . be . rejectedWith ( FirebaseError , PASSWORD_ERROR_MSG ) ;
868
871
869
872
expect ( policyEndpointMock . calls . length ) . to . eq ( 0 ) ;
870
873
expect ( auth . _getPasswordPolicy ( ) ) . to . be . null ;
871
874
} ) ;
872
875
873
- it ( 'does not update the password policy upon error if tenant changes and policy has not previously been fetched' , async ( ) => {
874
- auth . tenantId = 'tenant-id' ;
876
+ it ( 'does not update the cached password policy upon error if tenant changes and policy has not previously been fetched' , async ( ) => {
877
+ auth . tenantId = TEST_TENANT_ID ;
875
878
await auth . _updatePasswordPolicy ( ) ;
876
879
expect ( policyEndpointMockWithTenant . calls . length ) . to . eq ( 1 ) ;
877
880
expect ( auth . _getPasswordPolicy ( ) ) . to . eql ( cachedPasswordPolicy ) ;
878
881
879
- auth . tenantId = 'other-tenant-id' ;
882
+ auth . tenantId = TEST_REQUIRE_NUMERIC_TENANT_ID ;
880
883
await expect (
881
884
createUserWithEmailAndPassword ( auth , 'some-email' , 'some-password' )
882
- ) . to . be . rejectedWith (
883
- FirebaseError ,
884
- 'Firebase: The password does not meet the requirements. (auth/password-does-not-meet-requirements).'
885
- ) ;
885
+ ) . to . be . rejectedWith ( FirebaseError , PASSWORD_ERROR_MSG ) ;
886
886
expect ( policyEndpointMockWithOtherTenant . calls . length ) . to . eq ( 0 ) ;
887
887
expect ( auth . _getPasswordPolicy ( ) ) . to . be . undefined ;
888
888
} ) ;
0 commit comments