summaryrefslogtreecommitdiff
path: root/testkiki
diff options
context:
space:
mode:
authorJames Crayne <jim.crayne@gmail.com>2016-04-25 21:03:14 -0400
committerJames Crayne <jim.crayne@gmail.com>2016-04-26 06:04:05 -0400
commit9232d98ec23ad7d79bfdd12505d62a1ff7f25cd4 (patch)
treed4fb7c3ef5515a84d630d4eea9ab86508430c822 /testkiki
parente40babf7ef744375eae355742acf47d4e6323f2e (diff)
test cases
Diffstat (limited to 'testkiki')
-rw-r--r--testkiki/testkiki.hs76
1 files changed, 71 insertions, 5 deletions
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
13--import System.Posix.ByteString.FilePath 13--import System.Posix.ByteString.FilePath
14import Control.Applicative 14import Control.Applicative
15import Control.Monad 15import Control.Monad
16import qualified Data.ByteString.Char8 as B
16 17
17 18
18data TestKikiSettings = TKS 19data TestKikiSettings = TKS
19 { chroot :: FilePath 20 { gnupghome :: FilePath
21 , chroot :: FilePath
20 } 22 }
21 deriving (Show,Eq) 23 deriving (Show,Eq)
22 24
23kiki = "./dist/build/kiki/kiki"
24 25
25main = do 26main = do
26 args <- getArgs 27 args <- getArgs
@@ -44,15 +45,80 @@ main = do
44 hPutStrLn stderr ("Path " ++ show tdir ++ " already exists, remove or change working folder to run clean tests.") 45 hPutStrLn stderr ("Path " ++ show tdir ++ " already exists, remove or change working folder to run clean tests.")
45 exitFailure 46 exitFailure
46 else do 47 else do
47 let chrootdir = cwd </> tdir </> "chroot" 48 let chrootdir = cwd </> tdir </> "chroot"
49 gnupghomedir = cwd </> tdir </> "gnupghome"
48 createDirectoryIfMissing True chrootdir 50 createDirectoryIfMissing True chrootdir
49 let config = TKS { chroot = chrootdir } 51 createDirectoryIfMissing True gnupghomedir
52 let config = TKS { chroot = chrootdir , gnupghome = gnupghomedir }
50 print config 53 print config
51 putStrLn "===" 54 putStrLn "==="
52 doTests config 55 doTests config
53 56
54doTests :: TestKikiSettings -> IO () 57doTests :: TestKikiSettings -> IO ()
55doTests tkConfig = hspec $ do 58doTests tkConfig = hspec $ do
56 describe "TODO: error" $ 59 describe "TODO: error" $
57 it "throws an exception" $ 60 it "throws an exception" $
58 evaluate (error "TODO:testsuite") `shouldThrow` anyException 61 evaluate (error "TODO:testsuite") `shouldThrow` anyException
62
63 describe "export-public" $ do
64 it "does not modify mtime of GNUPGHOME keyrings" $ do
65 pending
66 it "creates external pem files which do not exist" $ do
67 pending
68 it "does not leak secret data from GNUPGHOME keyrings" $ do
69 pending
70
71 describe "export-secret" $ do
72 it "fails when public keys in existing PEM files do not match" $ do
73 pending
74 it "updates public pem files to private ones when told to" $ do
75 pending
76 it "creates external pem files which do not exist" $ do
77 pending
78
79 describe "init" $ do
80 it "honors GNUPGHOME environment variable" $ do
81 let kiki = kiki'Env tkConfig
82 (isInfixOf "New packet" <$> kiki ["init"]) `shouldReturn` True
83
84 it "creates parent directories with --gnupghome" $ do
85 let kiki = kiki'Env'And'HomeArg tkConfig
86 { gnupghome = chroot tkConfig </> "home" </> "tester" }
87 output <- kiki ["init"]
88 b <- doesDirectoryExist (gnupghome tkConfig)
89 (isInfixOf "New packet" output && b ) `shouldBe` True
90
91 it "creates new secring honoring GNUPGHOME" $ do
92 let kiki = kiki'Env'And'HomeArg tkConfig
93 output <- kiki ["init"]
94 b <- doesFileExist (gnupghome tkConfig </> "secring.gpg")
95 (isInfixOf "New packet" output && b ) `shouldBe` True
96
97 it "creates new secring in /root/.gnupg" $ do
98 let kiki = kiki'No'Env'No'Home tkConfig
99 output <- kiki ["init"]
100 b <- doesFileExist (chroot tkConfig </> "root" </> "secring.gpg")
101 (isInfixOf "New packet" output && b ) `shouldBe` True
102 where
103 kiki'Env config args = do
104 setEnv "GNUPGHOME" (gnupghome config)
105 let args' = args ++ ["--chroot=" ++ chroot config]
106 readProcess "./dist/build/kiki/kiki" args' ""
107
108 kiki'No'Env'No'Home config args = do
109 let args' = args ++ ["--chroot=" ++ chroot config]
110 readProcess "./dist/build/kiki/kiki" args' ""
111
112 kiki'No'Env config args = do
113 let args' = args ++ ["--chroot=" ++ chroot config,"--home=" ++ gnupghome config]
114 readProcess "./dist/build/kiki/kiki" args' ""
115
116 kiki'Env'And'HomeArg config args = do
117 setEnv "GNUPGHOME" (gnupghome config)
118 let args' = args ++ ["--chroot=" ++ chroot config,"--home=" ++ gnupghome config]
119 readProcess "./dist/build/kiki/kiki" args' ""
120
121 -- UTILS
122 isInfixOf sub str = let (_,match) = B.breakSubstring (B.pack sub) (B.pack str)
123 in not (B.null match)
124