File: TokenSpec.hs

package info (click to toggle)
haskell-crypto-token 0.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 68 kB
  • sloc: haskell: 246; makefile: 3
file content (28 lines) | stat: -rw-r--r-- 987 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{-# LANGUAGE OverloadedStrings #-}

module TokenSpec where

import Control.Concurrent
import Crypto.Token
import Test.Hspec

----------------------------------------------------------------

spec :: Spec
spec = do
    describe "crypto token" $ do
        it "encrypt & decrypt ByteString" $ do
            mgr <- spawnTokenManager $ defaultConfig{interval = 1, tokenLifetime = 3}
            tf <- encryptToken mgr "Foo"
            threadDelay 1100000
            decryptToken mgr tf `shouldReturn` Just "Foo"
            tb <- encryptToken mgr "Bar"
            threadDelay 1100000
            decryptToken mgr tf `shouldReturn` Just "Foo"
            decryptToken mgr tb `shouldReturn` Just "Bar"
            threadDelay 1100000
            decryptToken mgr tf `shouldReturn` Nothing
            decryptToken mgr tb `shouldReturn` Just "Bar"
            threadDelay 1100000
            decryptToken mgr tf `shouldReturn` Nothing
            decryptToken mgr tb `shouldReturn` Nothing