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.Tests where
15 import qualified Data.ByteString.Char8 as B8
18 import Test.Tasty.HUnit
20 import Crypto.Macaroon
21 import Crypto.Macaroon.Serializer.Base64
24 tests = testGroup "Crypto.Macaroon" [ basic
30 m = create secret key loc
32 secret = B8.pack "this is our super secret key; only we should know it"
33 key = B8.pack "we used our secret key"
34 loc = B8.pack "http://mybank/"
37 basic = testGroup "Basic macaroon" [ basicInspect
41 basicInspect = testCase "Inspect" $
42 "location http://mybank/\nidentifier we used\
43 \ our secret key\n\nsignature E3D9E02908526C4C\
44 \0039AE15114115D97FDD68BF2BA379B342AAF0F617D0552F" @=? inspect m
46 basicSignature = testCase "Signature" $
47 "E3D9E02908526C4C0039AE15114115D97FDD68BF2BA379B342AAF0F617D0552F" @=? (hex . signature) m
50 m2 = addFirstPartyCaveat "test = caveat" m
53 minted = testGroup "Macaroon with first party caveat" [ mintInspect
57 mintInspect = testCase "Inspect" $
58 "location http://mybank/\nidentifier we used\
59 \ our secret key\ncid test = caveat\nsignature\
60 \ 197BAC7A044AF33332865B9266E26D49\
61 \3BDD668A660E44D88CE1A998C23DBD67" @=? inspect m2
64 mintSignature = testCase "Signature" $
65 "197BAC7A044AF33332865B9266E26D493BDD668A660E44D88CE1A998C23DBD67" @=? (hex . signature) m2
68 -- m4 = addThirdPartyCaveat caveat_key caveat_id caveat_loc n
70 -- n = addFirstPartyCaveat "account = 3735928559" $ create sec key loc
71 -- key = B8.pack "we used our other secret key"
72 -- loc = B8.pack "http://mybank/"
73 -- sec = B8.pack "this is a different super-secret key; never use the same secret twice"
74 -- caveat_key = B8.pack "4; guaranteed random by a fair toss of the dice"
75 -- caveat_id = B8.pack "this was how we remind auth of key/pred"
76 -- caveat_loc = B8.pack "http://auth.mybank/"
78 -- minted3 :: TestTree
79 -- minted3 = testGroup "Macaroon with first and third party caveats" [ mint3sig ]
82 -- mint3sig = testCase "Signature" $
83 -- "6B99EDB2EC6D7A4382071D7D41A0BF7DFA27D87D2F9FEA86E330D7850FFDA2B2" @=? (hex . signature) m4