applied hlint suggestions
This commit is contained in:
parent
2e8a638756
commit
14e367bd43
11
app/Main.hs
11
app/Main.hs
@ -28,6 +28,7 @@ import Control.Lens (makeLenses, set, view)
|
||||
import qualified Control.Monad.Trans.State as S
|
||||
import Control.Monad (join)
|
||||
import Control.Monad.Trans.Class (lift)
|
||||
import Data.Foldable (mapM_)
|
||||
import Data.Maybe (fromJust)
|
||||
import qualified System.Console.HCL as R
|
||||
|
||||
@ -38,11 +39,7 @@ data Status = Status
|
||||
makeLenses ''Status
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
ms <- R.runRequest setup
|
||||
case ms of
|
||||
Nothing -> return ()
|
||||
Just s -> S.evalStateT mainMenu s
|
||||
main = R.runRequest setup >>= mapM_ (S.evalStateT mainMenu)
|
||||
|
||||
setup :: R.Request Status
|
||||
setup = fmap Status getMasterPass
|
||||
@ -58,7 +55,7 @@ getMasterPass = do
|
||||
else return p1
|
||||
|
||||
mainMenu :: S.StateT Status IO ()
|
||||
mainMenu = do
|
||||
mainMenu =
|
||||
menu "Main Menu"
|
||||
[ ( "change master password", changeMasterPass )
|
||||
, ( "lock session", lockSession )
|
||||
@ -76,7 +73,7 @@ lockSession :: S.StateT Status IO ()
|
||||
lockSession = do
|
||||
lift $ putStrLn "\nsession locked"
|
||||
pass <- S.gets $ view masterPass
|
||||
mx <- lift $ R.runRequest $ R.prompt "password: " $ R.reqPassword
|
||||
mx <- lift $ R.runRequest $ R.prompt "password: " R.reqPassword
|
||||
case mx of
|
||||
Nothing -> lockSession
|
||||
Just x -> if x == pass
|
||||
|
@ -72,7 +72,7 @@ validatePWPolicy
|
||||
-- ^ the policy being validated
|
||||
-> Bool
|
||||
-- ^ indicates whether or not the policy is valid
|
||||
validatePWPolicy x = all id
|
||||
validatePWPolicy x = and
|
||||
[ needed <= x^.pwLength
|
||||
, x^.pwLength >= 0
|
||||
, x^.pwUpper >= 0
|
||||
@ -91,7 +91,7 @@ applyPWPolicy
|
||||
-- ^ the policy
|
||||
-> Bool
|
||||
-- ^ @"True"@ if the password meets the policy, @"False"@ otherwise
|
||||
applyPWPolicy pw policy = all id
|
||||
applyPWPolicy pw policy = and
|
||||
[ length pw <= policy^.pwLength
|
||||
, length (filter isUpper pw) >= policy^.pwUpper
|
||||
, length (filter isLower pw) >= policy^.pwLower
|
||||
|
@ -28,18 +28,18 @@ import Test.HUnit (Test(..), (~?=))
|
||||
import Password
|
||||
|
||||
tests = TestLabel "applyPWPolicy" $ TestList $ map test'
|
||||
[ ( "default pass", "password", id, True )
|
||||
, ( "too long", take 99 $ repeat 'x', id, False )
|
||||
, ( "insufficient upper", "password", set pwUpper 1, False )
|
||||
, ( "sufficient upper", "Password", set pwUpper 1, True )
|
||||
, ( "insufficient lower", "PASSWORD", set pwLower 1, False )
|
||||
, ( "sufficient lower", "password", set pwLower 1, True )
|
||||
, ( "insufficient digits", "password", set pwDigits 1, False )
|
||||
, ( "sufficient digits", "password1", set pwDigits 1, True )
|
||||
, ( "insufficient special", "Password1", spec (Just 1), False )
|
||||
, ( "sufficient special", "Password1/", spec (Just 1), True )
|
||||
, ( "illegal special", "Password1/", spec Nothing, False )
|
||||
, ( "bad policy", "password", badPolicy, False )
|
||||
[ ( "default pass", "password", id, True )
|
||||
, ( "too long", replicate 99 'x', id, False )
|
||||
, ( "insufficient upper", "password", set pwUpper 1, False )
|
||||
, ( "sufficient upper", "Password", set pwUpper 1, True )
|
||||
, ( "insufficient lower", "PASSWORD", set pwLower 1, False )
|
||||
, ( "sufficient lower", "password", set pwLower 1, True )
|
||||
, ( "insufficient digits", "password", set pwDigits 1, False )
|
||||
, ( "sufficient digits", "password1", set pwDigits 1, True )
|
||||
, ( "insufficient special", "Password1", spec (Just 1), False )
|
||||
, ( "sufficient special", "Password1/", spec (Just 1), True )
|
||||
, ( "illegal special", "Password1/", spec Nothing, False )
|
||||
, ( "bad policy", "password", badPolicy, False )
|
||||
]
|
||||
|
||||
test' (label, pw, f, expect) = TestLabel label $
|
||||
|
Loading…
x
Reference in New Issue
Block a user