]> git.immae.eu Git - github/fretlink/hmacaroons.git/blame - test/Crypto/Macaroon/Verifier/Tests.hs
Add quickcheck properties
[github/fretlink/hmacaroons.git] / test / Crypto / Macaroon / Verifier / Tests.hs
CommitLineData
b92e3c15
JT
1{-# LANGUAGE OverloadedStrings #-}
2{-|
3Copyright : (c) 2015 Julien Tanguy
4License : BSD3
5
6Maintainer : julien.tanguy@jhome.fr
7
8
9This test suite is based on the pymacaroons test suite:
10<https://github.com/ecordell/pymacaroons>
11-}
12module Crypto.Macaroon.Verifier.Tests where
13
14
15import qualified Data.ByteString.Char8 as B8
16import Test.Tasty
17import Test.Tasty.HUnit
5d1b7d51 18import Test.Tasty.QuickCheck
b92e3c15
JT
19
20import Crypto.Macaroon
21import Crypto.Macaroon.Verifier
22
23import Crypto.Macaroon.Instances
24
25tests :: TestTree
26tests = testGroup "Crypto.Macaroon.Verifier" [ sigs
27 ]
28
5d1b7d51
JT
29{-
30 - Test fixtures
31 -}
b92e3c15
JT
32sec = B8.pack "this is our super secret key; only we should know it"
33
34m :: Macaroon
35m = create sec key loc
36 where
37 key = B8.pack "we used our sec key"
38 loc = B8.pack "http://mybank/"
39
40m2 :: Macaroon
41m2 = addFirstPartyCaveat "test = caveat" m
42
43m3 :: Macaroon
44m3 = addFirstPartyCaveat "test = acaveat" m
45
5d1b7d51
JT
46{-
47 - Tests
48 -}
b92e3c15 49sigs = testGroup "Signatures" [ basic
5d1b7d51
JT
50 , one
51 , two
b92e3c15
JT
52 ]
53
5d1b7d51 54basic = testGroup "Basic Macaroon" [ none , sigQC ]
b92e3c15 55
5d1b7d51
JT
56none = testCase "No caveat" $
57 VSuccess @=? verifySig sec m
b92e3c15 58
5d1b7d51
JT
59sigQC = testProperty "Random" $
60 \sm -> verifySig (secret sm) (macaroon sm) == VSuccess
b92e3c15 61
5d1b7d51
JT
62one = testCase "Macaroon with one caveat" $
63 VSuccess @=? verifySig sec m2
64
65two = testCase "Macaroon with two caveats" $
66 VSuccess @=? verifySig sec m3
b92e3c15 67