check for negative values on validion
This commit is contained in:
parent
36e2ac9883
commit
29bbdccc53
|
@ -71,7 +71,14 @@ validatePWPolicy
|
||||||
-- ^ the policy being validated
|
-- ^ the policy being validated
|
||||||
-> Bool
|
-> Bool
|
||||||
-- ^ indicates whether or not the policy is valid
|
-- ^ indicates whether or not the policy is valid
|
||||||
validatePWPolicy x = needed <= x^.pwLength where
|
validatePWPolicy x = all id
|
||||||
|
[ needed <= x^.pwLength
|
||||||
|
, x^.pwLength >= 0
|
||||||
|
, x^.pwUpper >= 0
|
||||||
|
, x^.pwLower >= 0
|
||||||
|
, x^.pwDigits >= 0
|
||||||
|
, fromMaybe 0 (x^.pwSpecial) >= 0
|
||||||
|
] where
|
||||||
needed = x^.pwUpper + x^.pwLower + x^.pwDigits + special
|
needed = x^.pwUpper + x^.pwLower + x^.pwDigits + special
|
||||||
special = fromMaybe 0 $ x^.pwSpecial
|
special = fromMaybe 0 $ x^.pwSpecial
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,11 @@ tests = TestLabel "validatePWPolicy" $ TestList $ map test'
|
||||||
, ( "short", set pwLength 8, True )
|
, ( "short", set pwLength 8, True )
|
||||||
, ( "short valid", shortValid, True )
|
, ( "short valid", shortValid, True )
|
||||||
, ( "short invalid", shortInvalid, False )
|
, ( "short invalid", shortInvalid, False )
|
||||||
|
, ( "negative length", set pwLength (-1), False )
|
||||||
|
, ( "negative upper", set pwUpper (-1), False )
|
||||||
|
, ( "negative lower", set pwLower (-1), False )
|
||||||
|
, ( "negative digits", set pwDigits (-1), False )
|
||||||
|
, ( "negative special", set pwSpecial (Just (-1)), False )
|
||||||
]
|
]
|
||||||
|
|
||||||
test' (label, f, expect) = TestLabel label $
|
test' (label, f, expect) = TestLabel label $
|
||||||
|
|
Loading…
Reference in New Issue
Block a user