]> git.immae.eu Git - github/fretlink/hmacaroons.git/blame - test/Crypto/Macaroon/Tests.hs
Refactor tests
[github/fretlink/hmacaroons.git] / test / Crypto / Macaroon / Tests.hs
CommitLineData
f6781456
JT
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.Tests where
13
14import Data.Byteable
15import qualified Data.ByteString.Char8 as B8
16import Data.Hex
17import Test.Tasty
18import Test.Tasty.HUnit
19
20import Crypto.Macaroon
a20c77f8 21import Crypto.Macaroon.Serializer.Base64
f6781456
JT
22
23tests :: TestTree
a20c77f8
JT
24tests = testGroup "Crypto.Macaroon" [ basic
25 , minted
f6781456
JT
26 ]
27
28
29m :: Macaroon
30m = create secret key loc
31 where
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/"
35
a20c77f8 36basic :: TestTree
b1f77d7e
JT
37basic = testGroup "Basic macaroon" [ basicInspect
38 , basicSignature
a20c77f8
JT
39 ]
40
b1f77d7e
JT
41basicInspect = testCase "Inspect" $
42 "location http://mybank/\nidentifier we used\
43 \ our secret key\n\nsignature E3D9E02908526C4C\
44 \0039AE15114115D97FDD68BF2BA379B342AAF0F617D0552F" @=? inspect m
45
a20c77f8 46basicSignature = testCase "Signature" $
2aede11a
JT
47 "E3D9E02908526C4C0039AE15114115D97FDD68BF2BA379B342AAF0F617D0552F" @=? (hex . signature) m
48
f6781456
JT
49m2 :: Macaroon
50m2 = addFirstPartyCaveat "test = caveat" m
51
a20c77f8
JT
52minted :: TestTree
53minted = testGroup "Macaroon with first party caveat" [ mintInspect
b1f77d7e 54 , mintSignature
a20c77f8
JT
55 ]
56
57mintInspect = testCase "Inspect" $
2aede11a
JT
58 "location http://mybank/\nidentifier we used\
59 \ our secret key\ncid test = caveat\nsignature\
60 \ 197BAC7A044AF33332865B9266E26D49\
61 \3BDD668A660E44D88CE1A998C23DBD67" @=? inspect m2
62
63
b1f77d7e
JT
64mintSignature = testCase "Signature" $
65 "197BAC7A044AF33332865B9266E26D493BDD668A660E44D88CE1A998C23DBD67" @=? (hex . signature) m2
2aede11a 66
26d38f73
JT
67-- m4 :: Macaroon
68-- m4 = addThirdPartyCaveat caveat_key caveat_id caveat_loc n
69-- where
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/"
f6781456 77
26d38f73
JT
78-- minted3 :: TestTree
79-- minted3 = testGroup "Macaroon with first and third party caveats" [ mint3sig ]
a20c77f8 80
f6781456 81
26d38f73
JT
82-- mint3sig = testCase "Signature" $
83-- "6B99EDB2EC6D7A4382071D7D41A0BF7DFA27D87D2F9FEA86E330D7850FFDA2B2" @=? (hex . signature) m4