@@ -797,6 +797,7 @@ describe('core/auth/auth_impl', () => {
797
797
const TEST_UNSUPPORTED_SCHEMA_VERSION = 0 ;
798
798
799
799
const TEST_TENANT_ID = 'tenant-id' ;
800
+ const TEST_TENANT_ID_REQUIRE_ALL = 'tenant-id-require-all' ;
800
801
const TEST_TENANT_ID_UNSUPPORTED_POLICY_VERSION =
801
802
'tenant-id-with-unsupported-policy-version' ;
802
803
@@ -822,6 +823,18 @@ describe('core/auth/auth_impl', () => {
822
823
allowedNonAlphanumericCharacters : TEST_ALLOWED_NON_ALPHANUMERIC_CHARS ,
823
824
schemaVersion : TEST_SCHEMA_VERSION
824
825
} ;
826
+ const passwordPolicyResponseRequireAll : GetPasswordPolicyResponse = {
827
+ customStrengthOptions : {
828
+ minPasswordLength : TEST_MIN_PASSWORD_LENGTH ,
829
+ maxPasswordLength : TEST_MAX_PASSWORD_LENGTH ,
830
+ containsLowercaseLetter : true ,
831
+ containsUppercaseLetter : true ,
832
+ containsNumericCharacter : true ,
833
+ containsNonAlphanumericCharacter : true
834
+ } ,
835
+ allowedNonAlphanumericCharacters : TEST_ALLOWED_NON_ALPHANUMERIC_CHARS ,
836
+ schemaVersion : TEST_SCHEMA_VERSION
837
+ } ;
825
838
const passwordPolicyResponseUnsupportedVersion = {
826
839
customStrengthOptions : {
827
840
maxPasswordLength : TEST_MAX_PASSWORD_LENGTH ,
@@ -833,6 +846,8 @@ describe('core/auth/auth_impl', () => {
833
846
const cachedPasswordPolicy : PasswordPolicyInternal = passwordPolicyResponse ;
834
847
const cachedPasswordPolicyRequireNumeric : PasswordPolicyInternal =
835
848
passwordPolicyResponseRequireNumeric ;
849
+ const cachedPasswordPolicyRequireAll : PasswordPolicyInternal =
850
+ passwordPolicyResponseRequireAll ;
836
851
const cachedPasswordPolicyUnsupportedVersion : PasswordPolicyInternal =
837
852
passwordPolicyResponseUnsupportedVersion ;
838
853
@@ -850,6 +865,13 @@ describe('core/auth/auth_impl', () => {
850
865
} ,
851
866
passwordPolicyResponseRequireNumeric
852
867
) ;
868
+ mockEndpointWithParams (
869
+ Endpoint . GET_PASSWORD_POLICY ,
870
+ {
871
+ tenantId : TEST_TENANT_ID_REQUIRE_ALL
872
+ } ,
873
+ passwordPolicyResponseRequireAll
874
+ ) ;
853
875
mockEndpointWithParams (
854
876
Endpoint . GET_PASSWORD_POLICY ,
855
877
{
@@ -974,6 +996,114 @@ describe('core/auth/auth_impl', () => {
974
996
expect ( status ) . to . eql ( expectedValidationStatus ) ;
975
997
} ) ;
976
998
999
+ it ( 'password that is too short is considered invalid' , async ( ) => {
1000
+ const expectedValidationStatus : PasswordValidationStatus = {
1001
+ isValid : false ,
1002
+ meetsMinPasswordLength : false ,
1003
+ meetsMaxPasswordLength : true ,
1004
+ containsLowercaseLetter : true ,
1005
+ containsUppercaseLetter : true ,
1006
+ containsNumericCharacter : true ,
1007
+ containsNonAlphanumericCharacter : true ,
1008
+ passwordPolicy : cachedPasswordPolicyRequireAll
1009
+ } ;
1010
+
1011
+ auth = await testAuth ( ) ;
1012
+ auth . tenantId = TEST_TENANT_ID_REQUIRE_ALL ;
1013
+ const status = await auth . validatePassword ( 'P4ss!' ) ;
1014
+ expect ( status ) . to . eql ( expectedValidationStatus ) ;
1015
+ } ) ;
1016
+
1017
+ it ( 'password that is too long is considered invalid' , async ( ) => {
1018
+ const expectedValidationStatus : PasswordValidationStatus = {
1019
+ isValid : false ,
1020
+ meetsMinPasswordLength : true ,
1021
+ meetsMaxPasswordLength : false ,
1022
+ containsLowercaseLetter : true ,
1023
+ containsUppercaseLetter : true ,
1024
+ containsNumericCharacter : true ,
1025
+ containsNonAlphanumericCharacter : true ,
1026
+ passwordPolicy : cachedPasswordPolicyRequireAll
1027
+ } ;
1028
+
1029
+ auth = await testAuth ( ) ;
1030
+ auth . tenantId = TEST_TENANT_ID_REQUIRE_ALL ;
1031
+ const status = await auth . validatePassword ( 'Password01234!' ) ;
1032
+ expect ( status ) . to . eql ( expectedValidationStatus ) ;
1033
+ } ) ;
1034
+
1035
+ it ( 'password that does not contain a lowercase letter is considered invalid' , async ( ) => {
1036
+ const expectedValidationStatus : PasswordValidationStatus = {
1037
+ isValid : false ,
1038
+ meetsMinPasswordLength : true ,
1039
+ meetsMaxPasswordLength : true ,
1040
+ containsLowercaseLetter : false ,
1041
+ containsUppercaseLetter : true ,
1042
+ containsNumericCharacter : true ,
1043
+ containsNonAlphanumericCharacter : true ,
1044
+ passwordPolicy : cachedPasswordPolicyRequireAll
1045
+ } ;
1046
+
1047
+ auth = await testAuth ( ) ;
1048
+ auth . tenantId = TEST_TENANT_ID_REQUIRE_ALL ;
1049
+ const status = await auth . validatePassword ( 'P4SSWORD!' ) ;
1050
+ expect ( status ) . to . eql ( expectedValidationStatus ) ;
1051
+ } ) ;
1052
+
1053
+ it ( 'password that does not contain an uppercase letter is considered invalid' , async ( ) => {
1054
+ const expectedValidationStatus : PasswordValidationStatus = {
1055
+ isValid : false ,
1056
+ meetsMinPasswordLength : true ,
1057
+ meetsMaxPasswordLength : true ,
1058
+ containsLowercaseLetter : true ,
1059
+ containsUppercaseLetter : false ,
1060
+ containsNumericCharacter : true ,
1061
+ containsNonAlphanumericCharacter : true ,
1062
+ passwordPolicy : cachedPasswordPolicyRequireAll
1063
+ } ;
1064
+
1065
+ auth = await testAuth ( ) ;
1066
+ auth . tenantId = TEST_TENANT_ID_REQUIRE_ALL ;
1067
+ const status = await auth . validatePassword ( 'p4ssword!' ) ;
1068
+ expect ( status ) . to . eql ( expectedValidationStatus ) ;
1069
+ } ) ;
1070
+
1071
+ it ( 'password that does not contain a numeric character is considered invalid' , async ( ) => {
1072
+ const expectedValidationStatus : PasswordValidationStatus = {
1073
+ isValid : false ,
1074
+ meetsMinPasswordLength : true ,
1075
+ meetsMaxPasswordLength : true ,
1076
+ containsLowercaseLetter : true ,
1077
+ containsUppercaseLetter : true ,
1078
+ containsNumericCharacter : false ,
1079
+ containsNonAlphanumericCharacter : true ,
1080
+ passwordPolicy : cachedPasswordPolicyRequireAll
1081
+ } ;
1082
+
1083
+ auth = await testAuth ( ) ;
1084
+ auth . tenantId = TEST_TENANT_ID_REQUIRE_ALL ;
1085
+ const status = await auth . validatePassword ( 'Password!' ) ;
1086
+ expect ( status ) . to . eql ( expectedValidationStatus ) ;
1087
+ } ) ;
1088
+
1089
+ it ( 'password that does not contain a non-alphanumeric character is considered invalid' , async ( ) => {
1090
+ const expectedValidationStatus : PasswordValidationStatus = {
1091
+ isValid : false ,
1092
+ meetsMinPasswordLength : true ,
1093
+ meetsMaxPasswordLength : true ,
1094
+ containsLowercaseLetter : true ,
1095
+ containsUppercaseLetter : true ,
1096
+ containsNumericCharacter : true ,
1097
+ containsNonAlphanumericCharacter : false ,
1098
+ passwordPolicy : cachedPasswordPolicyRequireAll
1099
+ } ;
1100
+
1101
+ auth = await testAuth ( ) ;
1102
+ auth . tenantId = TEST_TENANT_ID_REQUIRE_ALL ;
1103
+ const status = await auth . validatePassword ( 'P4ssword' ) ;
1104
+ expect ( status ) . to . eql ( expectedValidationStatus ) ;
1105
+ } ) ;
1106
+
977
1107
it ( 'should use the password policy associated with the tenant ID when the tenant ID switches' , async ( ) => {
978
1108
let expectedValidationStatus : PasswordValidationStatus = {
979
1109
isValid : true ,
0 commit comments