1 {-# LANGUAGE OverloadedStrings #-}
3 Copyright : (c) 2015 Julien Tanguy
6 Maintainer : julien.tanguy@jhome.fr
9 This test suite is based on the pymacaroons test suite:
10 <https://github.com/ecordell/pymacaroons>
12 module Crypto.Macaroon.Verifier.Tests where
15 import qualified Data.ByteString.Char8 as B8
17 import Test.Tasty.HUnit
18 import Test.Tasty.QuickCheck
20 import Crypto.Macaroon
21 import Crypto.Macaroon.Verifier
23 import Crypto.Macaroon.Instances
26 tests = testGroup "Crypto.Macaroon.Verifier" [ sigs
33 sec = B8.pack "this is our super secret key; only we should know it"
36 m = create sec key loc
38 key = B8.pack "we used our sec key"
39 loc = B8.pack "http://mybank/"
42 m2 = addFirstPartyCaveat "test = caveat" m
45 m3 = addFirstPartyCaveat "value = 42" m2
47 exVerifiers = [ verifyExact "test" "caveat" (many' letter_ascii)
48 , verifyExact "value" 42 decimal
50 exVerifiers' = [ verifyExact "test" "caveat" (many' letter_ascii)
51 , verifyExact "value" 43 decimal
57 sigs = testGroup "Signatures" [ basic
62 basic = testGroup "Basic Macaroon" [ none , sigQC ]
64 none = testCase "No caveat" $
65 Ok @=? verifySig sec m
67 sigQC = testProperty "Random" $
68 \sm -> verifySig (secret sm) (macaroon sm) == Ok
70 one = testCase "Macaroon with one caveat" $
71 Ok @=? verifySig sec m2
73 two = testCase "Macaroon with two caveats" $
74 Ok @=? verifySig sec m3
76 exactCavs = testGroup "Exact Caveats" [ zero', one', two' , one'', two'']
78 zero' = testCase "Zero caveat win" $
79 Ok @=? verifyCavs exVerifiers m
80 one' = testCase "One caveat win" $
81 Ok @=? verifyCavs exVerifiers m2
82 one'' = testCase "Ignoring non-relevant" $
83 Ok @=? verifyCavs exVerifiers' m2
84 two' = testCase "Two caveat win" $
85 Ok @=? verifyCavs exVerifiers m3
86 two'' = testCase "Two caveat fail" $
87 Failed @=? verifyCavs exVerifiers' m3