]> git.immae.eu Git - github/fretlink/hmacaroons.git/blame_incremental - test/Crypto/Macaroon/Verifier/Tests.hs
Add quickcheck properties
[github/fretlink/hmacaroons.git] / test / Crypto / Macaroon / Verifier / Tests.hs
... / ...
CommitLineData
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
18import Test.Tasty.QuickCheck
19
20import Crypto.Macaroon
21import Crypto.Macaroon.Verifier
22
23import Crypto.Macaroon.Instances
24
25tests :: TestTree
26tests = testGroup "Crypto.Macaroon.Verifier" [ sigs
27 ]
28
29{-
30 - Test fixtures
31 -}
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
46{-
47 - Tests
48 -}
49sigs = testGroup "Signatures" [ basic
50 , one
51 , two
52 ]
53
54basic = testGroup "Basic Macaroon" [ none , sigQC ]
55
56none = testCase "No caveat" $
57 VSuccess @=? verifySig sec m
58
59sigQC = testProperty "Random" $
60 \sm -> verifySig (secret sm) (macaroon sm) == VSuccess
61
62one = testCase "Macaroon with one caveat" $
63 VSuccess @=? verifySig sec m2
64
65two = testCase "Macaroon with two caveats" $
66 VSuccess @=? verifySig sec m3
67