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