implemented pwSetService

This commit is contained in:
Jonathan Lamothe 2018-12-24 11:55:49 -05:00
parent 824f52b108
commit 7b13aad709
3 changed files with 76 additions and 1 deletions

View File

@ -225,7 +225,7 @@ pwSetService
-- ^ the database to add to
-> PWDatabase
-- ^ the resulting database
pwSetService = undefined
pwSetService = M.insert
-- | attempts to get a service from the database
pwGetService

View File

@ -32,6 +32,7 @@ import qualified Spec.NewPWPolicy as NewPWPolicy
import qualified Spec.NewPWSalt as NewPWSalt
import qualified Spec.PWGenerate as PWGenerate
import qualified Spec.PWHasService as PWHasService
import qualified Spec.PWSetService as PWSetService
import qualified Spec.ValidatePWData as ValidatePWData
import qualified Spec.ValidatePWDatabase as ValidatePWDatabase
import qualified Spec.ValidatePWPolicy as ValidatePWPolicy
@ -51,6 +52,7 @@ tests = TestList
, ValidatePWPolicy.tests
, PWGenerate.tests
, PWHasService.tests
, PWSetService.tests
]
--jl

73
test/Spec/PWSetService.hs Normal file
View File

@ -0,0 +1,73 @@
{-
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.PWSetService (tests) where
import qualified Data.Map as M
import System.Random (mkStdGen)
import Test.HUnit (Test (..), (~?=))
import Password
tests = TestLabel "pwSetService" $ TestList
[ addToEmpty, addToNonEmpty, addToExisting ]
addToEmpty = tests' "empty database" newPWDatabase 1
addToNonEmpty = tests' "non-empty database" nonEmpty 3
addToExisting = tests' "exiating database" existing 3
tests' label db size = TestLabel label $ TestList
[ dbSize result size
, find result
] where
result = pwSetService "foo" foo db
dbSize db expect = TestLabel "database size" $
length db ~?= expect
find db = TestLabel "record" $
M.lookup "foo" db ~?= Just foo
nonEmpty = M.fromList
[ ( "bar", bar )
, ( "baz", baz )
]
existing = M.fromList
[ ( "foo", foo' )
, ( "bar", bar )
, ( "baz", baz )
]
(foo, g1) = newPWData g
(foo', g2) = newPWData g1
(bar, g3) = newPWData g2
(baz, _) = newPWData g3
g = mkStdGen 1
--jl