module Tests.Hash (tests) where import Tests.Test import Passman.Core.Hash import Test.QuickCheck.Monadic import Test.QuickCheck.Property import Distribution.TestSuite.QuickCheck tests :: IO [Test] tests = return [ testProperty "prop_hashMasterPassword" prop_hashMasterPassword ] preMaybe :: Monad m => Maybe a -> (a -> PropertyM m ()) -> PropertyM m () preMaybe Nothing _ = pre False preMaybe (Just x) f = f x prop_hashMasterPassword :: String -> String -> Property prop_hashMasterPassword x y = monadicIO $ preMaybe (masterPassword x) $ \x' -> preMaybe (masterPassword y) $ \y' -> do pre (x /= y) hashX <- run $ hashMasterPassword x' hashY <- run $ hashMasterPassword y' let info = "x = " ++ show x ++ ",y = " ++ show y ++ "hashX = " ++ show hashX ++ ", hashY = " ++ show hashY ++ "." assertM ("(checkMasterPassword hashX x) failed, where: " ++ info) $ checkMasterPassword hashX x' assertM ("(checkMasterPassword hashY y) failed, where: " ++ info) $ checkMasterPassword hashY y' assertM ("(not $ checkMasterPassword hashX y) failed, where: " ++ info) $ not $ checkMasterPassword hashX y' assertM ("(not $ checkMasterPassword hashY x) failed, where: " ++ info) $ not $ checkMasterPassword hashY x'