From 582ad0423e28e950619f5c61e04fcf4da49b0cd1 Mon Sep 17 00:00:00 2001 From: James Crayne Date: Wed, 27 Apr 2016 00:52:40 -0400 Subject: testsuite, conditional skipping, update stubs --- testkiki/testkiki.hs | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'testkiki/testkiki.hs') diff --git a/testkiki/testkiki.hs b/testkiki/testkiki.hs index db984f5..c45764f 100644 --- a/testkiki/testkiki.hs +++ b/testkiki/testkiki.hs @@ -22,6 +22,7 @@ import Data.Time.Clock import Data.Time.Clock.POSIX import Data.IORef import Crypto.Hash.SHA1 (hash) +import System.IO.Unsafe (unsafePerformIO) #if !MIN_VERSION_base(4,7,0) setEnv k v = System.Posix.Env.setEnv k v True @@ -65,6 +66,9 @@ main = do putStrLn "===" doTests config +{-# NOINLINE didFirstEportSecret #-} +didFirstEportSecret = unsafePerformIO $ newIORef False + doTests :: TestKikiSettings -> IO () doTests tkConfig = hspec $ do {- @@ -73,6 +77,7 @@ doTests tkConfig = hspec $ do it "throws an exception" $ evaluate (error "TODO:testsuite") `shouldThrow` anyException -} + didInit3 <- runIO $! newIORef False -- **** kiki tests ***** describe "kiki init" $ do @@ -107,10 +112,10 @@ doTests tkConfig = hspec $ do let p = (chroot cfg "root" ".gnupg" "secring.gpg") b <- doesFileExist p let c = isInfixOf "New packet" output + when (b && c) $ writeIORef didInit3 True (b,c) `shouldBe` (True,True) describe "kiki export-secret --pems" $ do - t <- runIO $ getPOSIXTime mtime1 <- runIO $ newIORef (posixSecondsToUTCTime t) mtime2 <- runIO $ newIORef (posixSecondsToUTCTime t) @@ -118,6 +123,8 @@ doTests tkConfig = hspec $ do hash2 <- runIO $ newIORef "" it "creates external pem files which do not exist" $ do + bDidInit3 <-readIORef didInit3 + if not bDidInit3 then skipThisTest else do let cfg' = appendpaths tkConfig "3" home = chroot cfg' "root" gnuhome = home ".gnupg" @@ -143,9 +150,12 @@ doTests tkConfig = hspec $ do createDirectoryIfMissing True secs kiki ("export-secret":extraArgs) exists <- mapM doesFileExist files + when (and exists) $ writeIORef didFirstEportSecret True exists `shouldBe` replicate (length files) True it "does not modify mtime nor SHA1 of GNUPGHOME keyrings" $ do + bDidFirstExportSecret <- readIORef didFirstEportSecret + if not bDidFirstExportSecret then skipThisTest else do let cfg' = appendpaths tkConfig "3" home = chroot cfg' "root" gnuhome = home ".gnupg" @@ -170,7 +180,7 @@ doTests tkConfig = hspec $ do describe "kiki export-public --pems" $ do - + didExportPublic <- runIO $ newIORef False t <- runIO $ getPOSIXTime mtime1 <- runIO $ newIORef (posixSecondsToUTCTime t) mtime2 <- runIO $ newIORef (posixSecondsToUTCTime t) @@ -178,6 +188,8 @@ doTests tkConfig = hspec $ do hash2 <- runIO $ newIORef "" it "creates external pem files which do not exist" $ do + bDidInit3 <-readIORef didInit3 + if not bDidInit3 then skipThisTest else do let cfg' = appendpaths tkConfig "3" home = chroot cfg' "root" gnuhome = home ".gnupg" @@ -202,9 +214,12 @@ doTests tkConfig = hspec $ do createDirectoryIfMissing True pubs kiki ("export-public":extraArgs) exists <- mapM doesFileExist files + when (and exists) $ writeIORef didExportPublic True exists `shouldBe` replicate (length files) True it "does not modify mtime nor SHA1 of GNUPGHOME keyrings" $ do + bDidInit3 <-readIORef didInit3 + if not bDidInit3 then skipThisTest else do let cfg' = appendpaths tkConfig "3" home = chroot cfg' "root" gnuhome = home ".gnupg" @@ -221,6 +236,8 @@ doTests tkConfig = hspec $ do ([ tsec , tpub], hsec == hsec0, hpub == hpub0 ) `shouldBe` ([ tsec0,tpub0],True,True) it "always makes strictly smaller files than export-secret" $ do + bDidFirstExportSecret <-readIORef didFirstEportSecret + if not bDidFirstExportSecret then skipThisTest else do let cfg' = appendpaths tkConfig "3" home = chroot cfg' "root" gnuhome = home ".gnupg" @@ -236,23 +253,19 @@ doTests tkConfig = hspec $ do -- **** cokiki tests ***** describe "cokiki ssh-client" $ do - it "modifies system ssh configuration to respect /var/cache/kiki/ssh_known_hosts" $ do - pending - it "sets kiki ssh-server key to /etc/ssh/ssh_host_rsa_key" $ do - pending - it "replaces existing ssh-server key with /etc/ssh/ssh_hosts_rsa_key" $ do - pending - it "refreshes /var/cache/kiki/*" $ do + it "modifies system ssh configuration to respect /var/cache/kiki/ssh_known_hosts." $ do pending describe "cokiki ssh-server" $ do - it "does something" $ + it "modifies system ssh config to use /var/cache/kiki/ssh_host_rsa_key." $ do pending describe "cokiki strongswan" $ do - it "does something" $ + it "modifies /etc/ipsec.conf to include settings from /var/cache/kiki/ipsec.conf." $ do pending + where + skipThisTest = pendingWith "SKIPPING due to prior failure." kiki'Env config args = do setEnv "GNUPGHOME" (chroot config gnupghome config) let args' = args ++ ["--chroot=" ++ chroot config] -- cgit v1.2.3