Skip to content

Commit

Permalink
better unit-tests for Password validator
Browse files Browse the repository at this point in the history
  • Loading branch information
drkameleon committed Nov 28, 2024
1 parent 4016e32 commit ac1be58
Showing 1 changed file with 47 additions and 17 deletions.
64 changes: 47 additions & 17 deletions src/validators/password.art
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,32 @@ define :passwordValidator is :validator [
"C0mpl3x!@#$"
"ABcdEF6#"

; Edge cases that should
["Password123!", [min: 8]]
["Ab1!defgh", [special: 1]]
["Ab1!=xxxxxxx", [max: 28]] ; long but valid
["Ab1! xyz!", [spaces: true]] ; with spaces
["Ab1!münich", [unicode: true]] ; with unicode
; Edge cases that should pass
["Password123!", [min: 8]]
["Ab1!defgh", [special: 1]]
["Ab1!=xxxxxxx", [max: 28]] ; long but valid
["Ab1! xyz!", [spaces: true]] ; with spaces
["Ab1!münich", [unicode: true]] ; with unicode

; Modified requirements
["ab1!", [upper: 0, min: 4]] ; no uppercase required
["AB1!", [lower: 0, min: 4]] ; no lowercase required
["ABCabc!", [num: 0, min: 7]] ; no numbers required
["ABCabc123", [special: 0]] ; no special chars required
["ab1!", [upper: 0, min: 4]] ; no uppercase required
["AB1!", [lower: 0, min: 4]] ; no lowercase required
["ABCabc!", [num: 0, min: 7]] ; no numbers required
["ABCabc123", [special: 0]] ; no special chars required

; Multiple special characters
"P@ssw#rd123!"

; Maximum combinations
["Ab1!@#$%^&", [special: 5]] ; multiple special chars required
["AABBCc123!", [upper: 4]] ; multiple uppercase required
["aabbCC123!", [lower: 4]] ; multiple lowercase required
["AbC!12345", [num: 5]] ; multiple numbers required

; Mixed modifications
["Ab123456", [special: 0, min: 8]] ; no special, but longer
["ABCDEF12!", [lower: 0, num: 2]] ; no lowercase, more numbers
["Aa1!@#$ xyz", [spaces: true, special: 4]] ; spaces and more special
]

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

; Space/Unicode violations
["Pass word1!", [spaces: false]] ; contains space
["Pass münich!", [unicode: false]] ; contains unicode
["Pass word1!", [spaces: false]] ; contains space
["Pass münich!", [unicode: false]] ; contains unicode

; Not meeting minimums
["Aa1!", [min: 8]] ; too short for min:8
["Aa1!bcde", [upper: 2]] ; not enough uppercase
["Aa1!bcdE", [lower: 5]] ; not enough lowercase
["Aa1!bcde", [num: 3]] ; not enough numbers
["Aa1!bcde", [special: 2]] ; not enough special chars
["Aa1!", [min: 8]] ; too short for min:8
["Aa1!bcde", [upper: 2]] ; not enough uppercase
["Aa1!bcdE", [lower: 5]] ; not enough lowercase
["Aa1!bcde", [num: 3]] ; not enough numbers
["Aa1!bcde", [special: 2]] ; not enough special chars

; Complex requirement failures
["Ab1!@", [min: 10]] ; too short for custom min
["Ab1!abcdefghijk", [max: 10]] ; too long for custom max
["AAb1!cde", [lower: 6]] ; not enough lowercase
["aab1!CD", [upper: 3]] ; not enough uppercase
["Aa!bcd", [num: 3]] ; not enough numbers
["Ab1cdef", [special: 3]] ; not enough special chars
["Ab1!@x y", [spaces: false, special: 3]] ; spaces not allowed & not enough special
["Ab1!@αβ", [unicode: false, special: 3]] ; unicode not allowed & not enough special

; Combined requirement failures
["Ab1!", [min: 8, upper: 2]] ; multiple failures
["abcd123!", [upper: 2, special: 2]] ; multiple failures
["ABCD123!", [lower: 2, special: 2]] ; multiple failures
["Aa!cdef", [num: 2, special: 2]] ; multiple failures
]
]
]
Expand Down

0 comments on commit ac1be58

Please sign in to comment.