~ubuntu-branches/ubuntu/raring/haskell-clientsession/raring-proposed

« back to all changes in this revision

Viewing changes to tests/runtests.hs

  • Committer: Package Import Robot
  • Author(s): Clint Adams
  • Date: 2012-02-29 16:49:43 UTC
  • mfrom: (2.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20120229164943-k5kavo9w79l2fokn
* New upstream version.
* Bump to Standards-Verison 3.9.3.
* Enable test suite.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
import Web.ClientSession
15
15
import System.IO.Unsafe
16
16
 
 
17
import qualified Data.Set as Set
 
18
import Control.Monad.Trans.State.Strict (evalStateT, get, put)
 
19
import Control.Monad.Trans.Class (lift)
 
20
import Control.Monad (replicateM_)
 
21
 
17
22
main :: IO ()
18
23
main = hspecX $ describe "client session" $ do
19
24
    it "encrypt/decrypt success" $ property propEncDec
21
26
    it "AES encrypt/decrypt success" $ property propAES
22
27
    it "AES encryption changes bs" $ property propAESChanges
23
28
    it "specific values" caseSpecific
 
29
    it "randomIV is really random" caseRandomIV
24
30
 
25
31
propEncDec :: S.ByteString -> Bool
26
32
propEncDec bs = unsafePerformIO $ do
51
57
    let s' = S.concat $ replicate 500 s
52
58
    Just s' @=? decrypt key (encrypt key iv s')
53
59
 
 
60
caseRandomIV :: Assertion
 
61
caseRandomIV = do
 
62
    evalStateT (replicateM_ 10000 go) Set.empty
 
63
  where
 
64
    go = do
 
65
        val <- lift randomIV
 
66
        set <- get
 
67
        lift $ assertBool "No duplicated keys" (not $ val `Set.member` set)
 
68
        put $ Set.insert val set
 
69
 
54
70
instance Arbitrary S.ByteString where
55
71
    arbitrary = S.pack `fmap` arbitrary
56
72