2018-12-12 18:41:34 -05:00
|
|
|
{-
|
|
|
|
|
|
|
|
passman
|
2020-12-14 22:10:14 -05:00
|
|
|
Copyright (C) 2018-2020 Jonathan Lamothe
|
2018-12-12 18:41:34 -05:00
|
|
|
<jlamothe1980@gmail.com>
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as
|
|
|
|
published by the Free Software Foundation, either version 3 of the
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this program. If not, see
|
|
|
|
<https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Spec.ValidatePWPolicy (tests) where
|
|
|
|
|
|
|
|
import Control.Lens (set)
|
|
|
|
import Test.HUnit (Test(..), (~?=))
|
|
|
|
|
|
|
|
import Password
|
|
|
|
|
2020-02-28 01:23:44 -05:00
|
|
|
tests :: Test
|
2018-12-12 18:41:34 -05:00
|
|
|
tests = TestLabel "validatePWPolicy" $ TestList $ map test'
|
2018-12-13 11:48:37 -05:00
|
|
|
[ ( "default", id, True )
|
|
|
|
, ( "no special chars", set pwSpecial Nothing, True )
|
|
|
|
, ( "valid minimums", validMins, True )
|
|
|
|
, ( "excessive upper", set pwUpper 99, False )
|
|
|
|
, ( "excessive lower", set pwLower 99, False )
|
|
|
|
, ( "excessive digits", set pwDigits 99, False )
|
|
|
|
, ( "excessive total", excessive, False )
|
|
|
|
, ( "short", set pwLength 8, True )
|
|
|
|
, ( "short valid", shortValid, True )
|
|
|
|
, ( "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 )
|
2018-12-12 18:41:34 -05:00
|
|
|
]
|
|
|
|
|
2020-02-28 01:23:44 -05:00
|
|
|
test' :: (String, PWPolicy -> PWPolicy, Bool) -> Test
|
2018-12-13 11:15:26 -05:00
|
|
|
test' (label, f, expect) = TestLabel label $
|
|
|
|
validatePWPolicy x ~?= expect where
|
2018-12-12 18:41:34 -05:00
|
|
|
x = f newPWPolicy
|
|
|
|
|
2020-02-28 01:23:44 -05:00
|
|
|
validMins :: PWPolicy -> PWPolicy
|
2018-12-12 18:41:34 -05:00
|
|
|
validMins = setAll 1
|
|
|
|
|
2020-02-28 01:23:44 -05:00
|
|
|
excessive :: PWPolicy -> PWPolicy
|
2018-12-12 18:41:34 -05:00
|
|
|
excessive = setAll 5
|
|
|
|
|
2020-02-28 01:23:44 -05:00
|
|
|
shortValid :: PWPolicy -> PWPolicy
|
2018-12-12 18:41:34 -05:00
|
|
|
shortValid = set pwLength 8 . setAll 2
|
|
|
|
|
2020-02-28 01:23:44 -05:00
|
|
|
shortInvalid :: PWPolicy -> PWPolicy
|
2018-12-12 18:41:34 -05:00
|
|
|
shortInvalid = set pwLength 8 . set pwUpper 9
|
|
|
|
|
2020-02-28 01:23:44 -05:00
|
|
|
setAll :: Int -> PWPolicy -> PWPolicy
|
2018-12-12 18:41:34 -05:00
|
|
|
setAll x = set pwUpper x .
|
|
|
|
set pwLower x .
|
|
|
|
set pwDigits x .
|
|
|
|
set pwSpecial (Just x)
|
|
|
|
|
|
|
|
--jl
|