From 9232d98ec23ad7d79bfdd12505d62a1ff7f25cd4 Mon Sep 17 00:00:00 2001 From: James Crayne Date: Mon, 25 Apr 2016 21:03:14 -0400 Subject: test cases --- testkiki/testkiki.hs | 76 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 5 deletions(-) (limited to 'testkiki') diff --git a/testkiki/testkiki.hs b/testkiki/testkiki.hs index d84f92d..0eb49f0 100644 --- a/testkiki/testkiki.hs +++ b/testkiki/testkiki.hs @@ -13,14 +13,15 @@ import System.IO --import System.Posix.ByteString.FilePath import Control.Applicative import Control.Monad +import qualified Data.ByteString.Char8 as B data TestKikiSettings = TKS - { chroot :: FilePath + { gnupghome :: FilePath + , chroot :: FilePath } deriving (Show,Eq) -kiki = "./dist/build/kiki/kiki" main = do args <- getArgs @@ -44,15 +45,80 @@ main = do hPutStrLn stderr ("Path " ++ show tdir ++ " already exists, remove or change working folder to run clean tests.") exitFailure else do - let chrootdir = cwd tdir "chroot" + let chrootdir = cwd tdir "chroot" + gnupghomedir = cwd tdir "gnupghome" createDirectoryIfMissing True chrootdir - let config = TKS { chroot = chrootdir } + createDirectoryIfMissing True gnupghomedir + let config = TKS { chroot = chrootdir , gnupghome = gnupghomedir } print config putStrLn "===" - doTests config + doTests config doTests :: TestKikiSettings -> IO () doTests tkConfig = hspec $ do describe "TODO: error" $ it "throws an exception" $ evaluate (error "TODO:testsuite") `shouldThrow` anyException + + describe "export-public" $ do + it "does not modify mtime of GNUPGHOME keyrings" $ do + pending + it "creates external pem files which do not exist" $ do + pending + it "does not leak secret data from GNUPGHOME keyrings" $ do + pending + + describe "export-secret" $ do + it "fails when public keys in existing PEM files do not match" $ do + pending + it "updates public pem files to private ones when told to" $ do + pending + it "creates external pem files which do not exist" $ do + pending + + describe "init" $ do + it "honors GNUPGHOME environment variable" $ do + let kiki = kiki'Env tkConfig + (isInfixOf "New packet" <$> kiki ["init"]) `shouldReturn` True + + it "creates parent directories with --gnupghome" $ do + let kiki = kiki'Env'And'HomeArg tkConfig + { gnupghome = chroot tkConfig "home" "tester" } + output <- kiki ["init"] + b <- doesDirectoryExist (gnupghome tkConfig) + (isInfixOf "New packet" output && b ) `shouldBe` True + + it "creates new secring honoring GNUPGHOME" $ do + let kiki = kiki'Env'And'HomeArg tkConfig + output <- kiki ["init"] + b <- doesFileExist (gnupghome tkConfig "secring.gpg") + (isInfixOf "New packet" output && b ) `shouldBe` True + + it "creates new secring in /root/.gnupg" $ do + let kiki = kiki'No'Env'No'Home tkConfig + output <- kiki ["init"] + b <- doesFileExist (chroot tkConfig "root" "secring.gpg") + (isInfixOf "New packet" output && b ) `shouldBe` True + where + kiki'Env config args = do + setEnv "GNUPGHOME" (gnupghome config) + let args' = args ++ ["--chroot=" ++ chroot config] + readProcess "./dist/build/kiki/kiki" args' "" + + kiki'No'Env'No'Home config args = do + let args' = args ++ ["--chroot=" ++ chroot config] + readProcess "./dist/build/kiki/kiki" args' "" + + kiki'No'Env config args = do + let args' = args ++ ["--chroot=" ++ chroot config,"--home=" ++ gnupghome config] + readProcess "./dist/build/kiki/kiki" args' "" + + kiki'Env'And'HomeArg config args = do + setEnv "GNUPGHOME" (gnupghome config) + let args' = args ++ ["--chroot=" ++ chroot config,"--home=" ++ gnupghome config] + readProcess "./dist/build/kiki/kiki" args' "" + + -- UTILS + isInfixOf sub str = let (_,match) = B.breakSubstring (B.pack sub) (B.pack str) + in not (B.null match) + -- cgit v1.2.3