Skip to content

Commit ac1be58

Browse files
committed
better unit-tests for Password validator
1 parent 4016e32 commit ac1be58

1 file changed

Lines changed: 47 additions & 17 deletions

File tree

src/validators/password.art

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,32 @@ define :passwordValidator is :validator [
7474
"C0mpl3x!@#$"
7575
"ABcdEF6#"
7676

77-
; Edge cases that should
78-
["Password123!", [min: 8]]
79-
["Ab1!defgh", [special: 1]]
80-
["Ab1!=xxxxxxx", [max: 28]] ; long but valid
81-
["Ab1! xyz!", [spaces: true]] ; with spaces
82-
["Ab1!münich", [unicode: true]] ; with unicode
77+
; Edge cases that should pass
78+
["Password123!", [min: 8]]
79+
["Ab1!defgh", [special: 1]]
80+
["Ab1!=xxxxxxx", [max: 28]] ; long but valid
81+
["Ab1! xyz!", [spaces: true]] ; with spaces
82+
["Ab1!münich", [unicode: true]] ; with unicode
8383

8484
; Modified requirements
85-
["ab1!", [upper: 0, min: 4]] ; no uppercase required
86-
["AB1!", [lower: 0, min: 4]] ; no lowercase required
87-
["ABCabc!", [num: 0, min: 7]] ; no numbers required
88-
["ABCabc123", [special: 0]] ; no special chars required
85+
["ab1!", [upper: 0, min: 4]] ; no uppercase required
86+
["AB1!", [lower: 0, min: 4]] ; no lowercase required
87+
["ABCabc!", [num: 0, min: 7]] ; no numbers required
88+
["ABCabc123", [special: 0]] ; no special chars required
89+
90+
; Multiple special characters
91+
"P@ssw#rd123!"
92+
93+
; Maximum combinations
94+
["Ab1!@#$%^&", [special: 5]] ; multiple special chars required
95+
["AABBCc123!", [upper: 4]] ; multiple uppercase required
96+
["aabbCC123!", [lower: 4]] ; multiple lowercase required
97+
["AbC!12345", [num: 5]] ; multiple numbers required
98+
99+
; Mixed modifications
100+
["Ab123456", [special: 0, min: 8]] ; no special, but longer
101+
["ABCDEF12!", [lower: 0, num: 2]] ; no lowercase, more numbers
102+
["Aa1!@#$ xyz", [spaces: true, special: 4]] ; spaces and more special
89103
]
90104

91105
invalid: [
@@ -100,15 +114,31 @@ define :passwordValidator is :validator [
100114
"ABCDabcd123" ; no special chars
101115

102116
; Space/Unicode violations
103-
["Pass word1!", [spaces: false]] ; contains space
104-
["Pass münich!", [unicode: false]] ; contains unicode
117+
["Pass word1!", [spaces: false]] ; contains space
118+
["Pass münich!", [unicode: false]] ; contains unicode
105119

106120
; Not meeting minimums
107-
["Aa1!", [min: 8]] ; too short for min:8
108-
["Aa1!bcde", [upper: 2]] ; not enough uppercase
109-
["Aa1!bcdE", [lower: 5]] ; not enough lowercase
110-
["Aa1!bcde", [num: 3]] ; not enough numbers
111-
["Aa1!bcde", [special: 2]] ; not enough special chars
121+
["Aa1!", [min: 8]] ; too short for min:8
122+
["Aa1!bcde", [upper: 2]] ; not enough uppercase
123+
["Aa1!bcdE", [lower: 5]] ; not enough lowercase
124+
["Aa1!bcde", [num: 3]] ; not enough numbers
125+
["Aa1!bcde", [special: 2]] ; not enough special chars
126+
127+
; Complex requirement failures
128+
["Ab1!@", [min: 10]] ; too short for custom min
129+
["Ab1!abcdefghijk", [max: 10]] ; too long for custom max
130+
["AAb1!cde", [lower: 6]] ; not enough lowercase
131+
["aab1!CD", [upper: 3]] ; not enough uppercase
132+
["Aa!bcd", [num: 3]] ; not enough numbers
133+
["Ab1cdef", [special: 3]] ; not enough special chars
134+
["Ab1!@x y", [spaces: false, special: 3]] ; spaces not allowed & not enough special
135+
["Ab1!@αβ", [unicode: false, special: 3]] ; unicode not allowed & not enough special
136+
137+
; Combined requirement failures
138+
["Ab1!", [min: 8, upper: 2]] ; multiple failures
139+
["abcd123!", [upper: 2, special: 2]] ; multiple failures
140+
["ABCD123!", [lower: 2, special: 2]] ; multiple failures
141+
["Aa!cdef", [num: 2, special: 2]] ; multiple failures
112142
]
113143
]
114144
]

0 commit comments

Comments
 (0)