diff options
-rw-r--r-- | kiki.cabal | 1 | ||||
-rw-r--r-- | testkiki/testkiki.hs | 76 |
2 files changed, 72 insertions, 5 deletions
@@ -134,5 +134,6 @@ Test-suite testkiki | |||
134 | , directory | 134 | , directory |
135 | , unix | 135 | , unix |
136 | , filepath | 136 | , filepath |
137 | , bytestring | ||
137 | , kiki | 138 | , kiki |
138 | 139 | ||
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 |
14 | import Control.Applicative | 14 | import Control.Applicative |
15 | import Control.Monad | 15 | import Control.Monad |
16 | import qualified Data.ByteString.Char8 as B | ||
16 | 17 | ||
17 | 18 | ||
18 | data TestKikiSettings = TKS | 19 | data TestKikiSettings = TKS |
19 | { chroot :: FilePath | 20 | { gnupghome :: FilePath |
21 | , chroot :: FilePath | ||
20 | } | 22 | } |
21 | deriving (Show,Eq) | 23 | deriving (Show,Eq) |
22 | 24 | ||
23 | kiki = "./dist/build/kiki/kiki" | ||
24 | 25 | ||
25 | main = do | 26 | main = 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 | ||
54 | doTests :: TestKikiSettings -> IO () | 57 | doTests :: TestKikiSettings -> IO () |
55 | doTests tkConfig = hspec $ do | 58 | doTests 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 | |||