From 2b9bedced5795a0e4c53fce88290d9c29fabf8c2 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Mon, 17 Dec 2018 14:30:32 -0500 Subject: [PATCH] removed applyPWPolicy --- src/Password.hs | 20 +-------------- test/Spec.hs | 2 -- test/Spec/ApplyPWPolicy.hs | 52 -------------------------------------- 3 files changed, 1 insertion(+), 73 deletions(-) delete mode 100644 test/Spec/ApplyPWPolicy.hs diff --git a/src/Password.hs b/src/Password.hs index cd1867a..72da4af 100644 --- a/src/Password.hs +++ b/src/Password.hs @@ -33,7 +33,7 @@ module Password ( -- ** Default Instances newPWPolicy, -- * Functions - validatePWPolicy, applyPWPolicy + validatePWPolicy ) where import Control.Lens (makeLenses, (^.)) @@ -83,22 +83,4 @@ validatePWPolicy x = and needed = x^.pwUpper + x^.pwLower + x^.pwDigits + special 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 diff --git a/test/Spec.hs b/test/Spec.hs index f7cd570..129f281 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -26,7 +26,6 @@ import Control.Monad (when) import System.Exit (exitFailure) import Test.HUnit (errors, failures, runTestTT, Test(TestList)) -import qualified Spec.ApplyPWPolicy as ApplyPWPolicy import qualified Spec.PWPolicy as PWPolicy import qualified Spec.ValidatePWPolicy as ValidatePWPolicy @@ -38,7 +37,6 @@ main = do tests = TestList [ PWPolicy.tests , ValidatePWPolicy.tests - , ApplyPWPolicy.tests ] --jl diff --git a/test/Spec/ApplyPWPolicy.hs b/test/Spec/ApplyPWPolicy.hs deleted file mode 100644 index ddb2ade..0000000 --- a/test/Spec/ApplyPWPolicy.hs +++ /dev/null @@ -1,52 +0,0 @@ -{- - -passman -Copyright (C) 2018 Jonathan Lamothe - - -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 -. - --} - -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