Browse files

add tests for certificate

  • Loading branch information...
1 parent 4efb818 commit 085028acb6687b36e005b47261f058d428753b31 @vincenthz committed Dec 6, 2010
Showing with 43 additions and 0 deletions.
  1. +4 −0 Tests.hs
  2. +27 −0 Tests/Unit.hs
  3. +12 −0 certificate.cabal
View
4 Tests.hs
@@ -0,0 +1,4 @@
+import qualified Tests.Unit as Unit
+
+main = do
+ Unit.runTests
View
27 Tests/Unit.hs
@@ -0,0 +1,27 @@
+module Tests.Unit
+ ( runTests
+ ) where
+
+import System.Directory
+import Test.HUnit
+import Control.Monad
+import Control.Applicative ((<$>))
+import Control.Exception
+import qualified Data.ByteString as B
+import Data.Certificate.X509
+import Data.Certificate.PEM
+import Data.List (isPrefixOf)
+
+readAllSystemCertificates = do
+ certfiles <- filter (not . isPrefixOf ".") <$> getDirectoryContents "/etc/ssl/certs"
+ foldM getCertData [] certfiles
+ where getCertData acc certfile = do
+ certdata <- try (B.readFile ("/etc/ssl/certs/" ++ certfile)) :: IO (Either IOException B.ByteString)
+ case either (const Nothing) (parsePEMCert) $ certdata of
+ Nothing -> return acc
+ Just x -> return ((certfile, x) : acc)
+
+runTests :: IO ()
+runTests = do
+ certs <- readAllSystemCertificates
+ return ()
View
12 certificate.cabal
@@ -17,6 +17,10 @@ stability: experimental
Homepage: http://github.com/vincenthz/hs-certificate
Cabal-Version: >=1.6
+Flag test
+ Description: Build unit test
+ Default: False
+
Flag executable
Description: Build the executable
Default: False
@@ -41,6 +45,14 @@ Executable certificate
else
Buildable: False
+executable Tests
+ Main-is: Tests.hs
+ if flag(test)
+ Buildable: True
+ Build-Depends: base >= 3 && < 7, directory, HUnit, QuickCheck >= 2, bytestring
+ else
+ Buildable: False
+
source-repository head
type: git
location: git://github.com/vincenthz/hs-certificate

0 comments on commit 085028a

Please sign in to comment.