From 098aaeb49fdf76a796cd927210dede023b1642ff Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Tue, 18 Dec 2018 14:04:45 -0500 Subject: [PATCH] implemented newPWData --- src/Password.hs | 13 +++++++++++- test/Spec.hs | 2 ++ test/Spec/NewPWData.hs | 45 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 test/Spec/NewPWData.hs diff --git a/src/Password.hs b/src/Password.hs index fdc2ed6..047365e 100644 --- a/src/Password.hs +++ b/src/Password.hs @@ -34,7 +34,7 @@ module Password ( -- *** PWPolicy pwLength, pwUpper, pwLower, pwDigits, pwSpecial, -- ** Default Instances - newPWPolicy, newSalt, + newPWData, newPWPolicy, newSalt, -- * Functions validatePWPolicy ) where @@ -84,6 +84,17 @@ makeLenses ''PWData newPWPolicy :: PWPolicy newPWPolicy = PWPolicy 16 0 0 0 (Just 0) +-- | builds a new @'PWData'@ +newPWData + :: RandomGen g + => g + -- ^ the random generator to use + -> (PWData, g) + -- ^ the result and new random generator +newPWData g = (result, g') where + result = PWData newPWPolicy salt + (salt, g') = newSalt g + -- | builds a new salt newSalt :: RandomGen g diff --git a/test/Spec.hs b/test/Spec.hs index f29d496..969765b 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -26,6 +26,7 @@ import Control.Monad (when) import System.Exit (exitFailure) import Test.HUnit (errors, failures, runTestTT, Test(TestList)) +import qualified Spec.NewPWData as NewPWData import qualified Spec.NewSalt as NewSalt import qualified Spec.PWPolicy as PWPolicy import qualified Spec.ValidatePWPolicy as ValidatePWPolicy @@ -39,6 +40,7 @@ tests = TestList [ PWPolicy.tests , ValidatePWPolicy.tests , NewSalt.tests + , NewPWData.tests ] --jl diff --git a/test/Spec/NewPWData.hs b/test/Spec/NewPWData.hs new file mode 100644 index 0000000..91b9e10 --- /dev/null +++ b/test/Spec/NewPWData.hs @@ -0,0 +1,45 @@ +{- + +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.NewPWData (tests) where + +import Control.Lens ((^.)) +import System.Random (mkStdGen) +import Test.HUnit (Test (..), (~?=)) + +import Password + +tests = TestLabel "newPData" $ TestList + [ testSalt x + , testPolicy x + ] where (x, _) = newPWData g + +testSalt x = TestLabel "pwSalt" $ + x^.pwSalt ~?= salt where + (salt, _) = newSalt g + +testPolicy x = TestLabel "pwPolicy" $ + x^.pwPolicy ~?= newPWPolicy + +g = mkStdGen 1 + +--jl