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
16 import qualified Data.ByteString.Char8 as B8
18 -- import Test.Tasty.HUnit
19 import Test.Tasty.QuickCheck
21 import Crypto.Macaroon
22 import Crypto.Macaroon.Verifier
24 import Crypto.Macaroon.Instances
27 tests = testGroup "Crypto.Macaroon.Verifier" [ sigs
34 sec = B8.pack "this is our super secret key; only we should know it"
37 m = create sec key loc
39 key = B8.pack "we used our sec key"
40 loc = B8.pack "http://mybank/"
43 m2 = addFirstPartyCaveat "test = caveat" m
46 m3 = addFirstPartyCaveat "value = 42" m2
48 exTC = verifyExact "test" "caveat" (many' letter_ascii) <???> "test = caveat"
49 exTZ = verifyExact "test" "bleh" (many' letter_ascii) <???> "test = bleh"
50 exV42 = verifyExact "value" 42 decimal <???> "value = 42"
51 exV43 = verifyExact "value" 43 decimal <???> "value = 43"
53 funTCPre = verifyFun "test" ("cav" `isPrefixOf`) (many' letter_ascii) <???> "test startsWith cav"
54 funTV43lte = verifyFun "value" (<= 43) decimal <???> "value <= 43"
56 allvs = [exTC, exTZ, exV42, exV43, funTCPre, funTV43lte]
61 sigs = testProperty "Signatures" $ \sm -> verifySig (secret sm) (macaroon sm) == Ok
63 firstParty = testGroup "First party caveats" [
64 testGroup "Pure verifiers" [
65 testProperty "Zero caveat" $
66 forAll (sublistOf allvs) (\vs -> Ok == verifyCavs vs m)
67 , testProperty "One caveat" $
68 forAll (sublistOf allvs) (\vs -> disjoin [
69 Ok == verifyCavs vs m2 .&&. any (`elem` vs) [exTC,funTCPre] .&&. (exTZ `notElem` vs)
70 , Failed === verifyCavs vs m2
72 , testProperty "Two Exact" $
73 forAll (sublistOf allvs) (\vs -> disjoin [
74 Ok == verifyCavs vs m3 .&&.
75 any (`elem` vs) [exTC,funTCPre] .&&. (exTZ `notElem` vs) .&&.
76 any (`elem` vs) [exV42,funTV43lte] .&&. (exV43 `notElem` vs)
77 , Failed === verifyCavs vs m3