removed applyPWPolicy

This commit is contained in:
Jonathan Lamothe 2018-12-17 14:30:32 -05:00
parent 14e367bd43
commit 2b9bedced5
3 changed files with 1 additions and 73 deletions

@ -33,7 +33,7 @@ module Password (
-- ** Default Instances -- ** Default Instances
newPWPolicy, newPWPolicy,
-- * Functions -- * Functions
validatePWPolicy, applyPWPolicy validatePWPolicy
) where ) where
import Control.Lens (makeLenses, (^.)) import Control.Lens (makeLenses, (^.))
@ -83,22 +83,4 @@ validatePWPolicy x = and
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
-- | checks whether or not a password meets a given password policy
applyPWPolicy
:: String
-- ^ the password
-> PWPolicy
-- ^ the policy
-> Bool
-- ^ @"True"@ if the password meets the policy, @"False"@ otherwise
applyPWPolicy pw policy = and
[ length pw <= policy^.pwLength
, length (filter isUpper pw) >= policy^.pwUpper
, length (filter isLower pw) >= policy^.pwLower
, length (filter isDigit pw) >= policy^.pwDigits
, length (filter (not . isAlphaNum) pw) >=
fromMaybe (succ $ policy^.pwLength) (policy^.pwSpecial)
, validatePWPolicy policy
]
--jl --jl

@ -26,7 +26,6 @@ import Control.Monad (when)
import System.Exit (exitFailure) import System.Exit (exitFailure)
import Test.HUnit (errors, failures, runTestTT, Test(TestList)) import Test.HUnit (errors, failures, runTestTT, Test(TestList))
import qualified Spec.ApplyPWPolicy as ApplyPWPolicy
import qualified Spec.PWPolicy as PWPolicy import qualified Spec.PWPolicy as PWPolicy
import qualified Spec.ValidatePWPolicy as ValidatePWPolicy import qualified Spec.ValidatePWPolicy as ValidatePWPolicy
@ -38,7 +37,6 @@ main = do
tests = TestList tests = TestList
[ PWPolicy.tests [ PWPolicy.tests
, ValidatePWPolicy.tests , ValidatePWPolicy.tests
, ApplyPWPolicy.tests
] ]
--jl --jl

@ -1,52 +0,0 @@
{-
passman
Copyright (C) 2018 Jonathan Lamothe
<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.ApplyPWPolicy (tests) where
import Control.Lens (set)
import Test.HUnit (Test(..), (~?=))
import Password
tests = TestLabel "applyPWPolicy" $ TestList $ map test'
[ ( "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 $
applyPWPolicy pw (f newPWPolicy) ~?= expect
spec = set pwSpecial
badPolicy = set pwUpper (-1)
--jl