@@ -788,44 +788,67 @@ describe('core/auth/auth_impl', () => {
788
788
} ) ;
789
789
790
790
context ( 'passwordPolicy' , ( ) => {
791
+ const TEST_ALLOWED_NON_ALPHANUMERIC_CHARS = [ '!' , '(' , ')' ] ;
792
+ const TEST_MIN_PASSWORD_LENGTH = 6 ;
793
+
791
794
const passwordPolicyResponse = {
792
795
customStrengthOptions : {
793
- minPasswordLength : 6
796
+ minPasswordLength : TEST_MIN_PASSWORD_LENGTH
794
797
} ,
795
- allowedNonAlphanumericCharacters : [ '!' , '(' , ')' ] ,
798
+ allowedNonAlphanumericCharacters : TEST_ALLOWED_NON_ALPHANUMERIC_CHARS ,
796
799
schemaVersion : 1
797
800
} ;
798
801
const passwordPolicyResponseRequireNumeric = {
799
802
customStrengthOptions : {
800
- minPasswordLength : 6 ,
803
+ minPasswordLength : TEST_MIN_PASSWORD_LENGTH ,
801
804
containsNumericCharacter : true
802
805
} ,
803
- allowedNonAlphanumericCharacters : [ '!' , '(' , ')' ] ,
806
+ allowedNonAlphanumericCharacters : TEST_ALLOWED_NON_ALPHANUMERIC_CHARS ,
804
807
schemaVersion : 1
805
808
} ;
806
809
const passwordPolicyResponseUnsupportedVersion = {
807
810
customStrengthOptions : {
808
- maxPasswordLength : 9
811
+ maxPasswordLength : TEST_MIN_PASSWORD_LENGTH ,
812
+ unsupportedPasswordPolicyProperty : 10
809
813
} ,
810
- allowedNonAlphanumericCharacters : [ '!' ] ,
814
+ allowedNonAlphanumericCharacters : TEST_ALLOWED_NON_ALPHANUMERIC_CHARS ,
811
815
schemaVersion : 0
812
816
} ;
813
817
const cachedPasswordPolicy = {
814
818
customStrengthOptions : {
815
- minPasswordLength : 6
819
+ minPasswordLength : TEST_MIN_PASSWORD_LENGTH
816
820
} ,
817
- allowedNonAlphanumericCharacters : [ '!' , '(' , ')' ]
821
+ allowedNonAlphanumericCharacters : TEST_ALLOWED_NON_ALPHANUMERIC_CHARS
818
822
} ;
819
823
const cachedPasswordPolicyRequireNumeric = {
820
824
customStrengthOptions : {
821
- minPasswordLength : 6 ,
825
+ minPasswordLength : TEST_MIN_PASSWORD_LENGTH ,
822
826
containsNumericCharacter : true
823
827
} ,
824
- allowedNonAlphanumericCharacters : [ '!' , '(' , ')' ]
828
+ allowedNonAlphanumericCharacters : TEST_ALLOWED_NON_ALPHANUMERIC_CHARS
825
829
} ;
826
830
827
831
beforeEach ( async ( ) => {
828
832
mockFetch . setUp ( ) ;
833
+ mockEndpointWithParams (
834
+ Endpoint . GET_PASSWORD_POLICY ,
835
+ { } ,
836
+ passwordPolicyResponse
837
+ ) ;
838
+ mockEndpointWithParams (
839
+ Endpoint . GET_PASSWORD_POLICY ,
840
+ {
841
+ tenantId : 'tenant-id'
842
+ } ,
843
+ passwordPolicyResponseRequireNumeric
844
+ ) ;
845
+ mockEndpointWithParams (
846
+ Endpoint . GET_PASSWORD_POLICY ,
847
+ {
848
+ tenantId : 'tenant-id-with-unsupported-policy-version'
849
+ } ,
850
+ passwordPolicyResponseUnsupportedVersion
851
+ ) ;
829
852
} ) ;
830
853
831
854
afterEach ( ( ) => {
@@ -835,11 +858,6 @@ describe('core/auth/auth_impl', () => {
835
858
it ( 'password policy should be set for project if tenant ID is null' , async ( ) => {
836
859
auth = await testAuth ( ) ;
837
860
auth . tenantId = null ;
838
- mockEndpointWithParams (
839
- Endpoint . GET_PASSWORD_POLICY ,
840
- { } ,
841
- passwordPolicyResponse
842
- ) ;
843
861
await auth . _updatePasswordPolicy ( ) ;
844
862
845
863
expect ( auth . _getPasswordPolicy ( ) ) . to . eql ( cachedPasswordPolicy ) ;
@@ -848,13 +866,6 @@ describe('core/auth/auth_impl', () => {
848
866
it ( 'password policy should be set for tenant if tenant ID is not null' , async ( ) => {
849
867
auth = await testAuth ( ) ;
850
868
auth . tenantId = 'tenant-id' ;
851
- mockEndpointWithParams (
852
- Endpoint . GET_PASSWORD_POLICY ,
853
- {
854
- tenantId : 'tenant-id'
855
- } ,
856
- passwordPolicyResponseRequireNumeric
857
- ) ;
858
869
await auth . _updatePasswordPolicy ( ) ;
859
870
860
871
expect ( auth . _getPasswordPolicy ( ) ) . to . eql (
@@ -865,20 +876,9 @@ describe('core/auth/auth_impl', () => {
865
876
it ( 'password policy should dynamically switch if tenant ID switches.' , async ( ) => {
866
877
auth = await testAuth ( ) ;
867
878
auth . tenantId = null ;
868
- mockEndpointWithParams (
869
- Endpoint . GET_PASSWORD_POLICY ,
870
- { } ,
871
- passwordPolicyResponse
872
- ) ;
873
879
await auth . _updatePasswordPolicy ( ) ;
880
+
874
881
auth . tenantId = 'tenant-id' ;
875
- mockEndpointWithParams (
876
- Endpoint . GET_PASSWORD_POLICY ,
877
- {
878
- tenantId : 'tenant-id'
879
- } ,
880
- passwordPolicyResponseRequireNumeric
881
- ) ;
882
882
await auth . _updatePasswordPolicy ( ) ;
883
883
884
884
auth . tenantId = null ;
@@ -893,17 +893,12 @@ describe('core/auth/auth_impl', () => {
893
893
894
894
it ( 'password policy should not be set when the schema version is not supported' , async ( ) => {
895
895
auth = await testAuth ( ) ;
896
- auth . tenantId = null ;
897
- mockEndpointWithParams (
898
- Endpoint . GET_PASSWORD_POLICY ,
899
- { } ,
900
- passwordPolicyResponseUnsupportedVersion
901
- ) ;
896
+ auth . tenantId = 'tenant-id-with-unsupported-policy-version' ;
902
897
await expect ( auth . _updatePasswordPolicy ( ) ) . to . be . rejectedWith (
903
- AuthErrorCode . PASSWORD_POLICY_VERSION_MISMATCH
898
+ AuthErrorCode . UNSUPPORTED_PASSWORD_POLICY_SCHEMA_VERSION
904
899
) ;
905
900
906
- expect ( auth . _getPasswordPolicy ( ) ) . to . be . null ;
901
+ expect ( auth . _getPasswordPolicy ( ) ) . to . be . undefined ;
907
902
} ) ;
908
903
} ) ;
909
904
} ) ;
0 commit comments