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
|