]> git.immae.eu Git - github/fretlink/hmacaroons.git/blame_incremental - test/Crypto/Macaroon/Tests.hs
Change verifier api and split Verifier module
[github/fretlink/hmacaroons.git] / test / Crypto / Macaroon / Tests.hs
... / ...
CommitLineData
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
21import Crypto.Macaroon.Serializer.Base64
22
23tests :: TestTree
24tests = testGroup "Crypto.Macaroon" [ basic
25 , minted
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
36basic :: TestTree
37basic = testGroup "Basic macaroon" [ basicInspect
38 , basicSignature
39 ]
40
41basicInspect = testCase "Inspect" $
42 "location http://mybank/\nidentifier we used\
43 \ our secret key\n\nsignature E3D9E02908526C4C\
44 \0039AE15114115D97FDD68BF2BA379B342AAF0F617D0552F" @=? inspect m
45
46basicSignature = testCase "Signature" $
47 "E3D9E02908526C4C0039AE15114115D97FDD68BF2BA379B342AAF0F617D0552F" @=? (hex . signature) m
48
49m2 :: Macaroon
50m2 = addFirstPartyCaveat "test = caveat" m
51
52minted :: TestTree
53minted = testGroup "Macaroon with first party caveat" [ mintInspect
54 , mintSignature
55 ]
56
57mintInspect = testCase "Inspect" $
58 "location http://mybank/\nidentifier we used\
59 \ our secret key\ncid test = caveat\nsignature\
60 \ 197BAC7A044AF33332865B9266E26D49\
61 \3BDD668A660E44D88CE1A998C23DBD67" @=? inspect m2
62
63
64mintSignature = testCase "Signature" $
65 "197BAC7A044AF33332865B9266E26D493BDD668A660E44D88CE1A998C23DBD67" @=? (hex . signature) m2
66
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/"
77
78-- minted3 :: TestTree
79-- minted3 = testGroup "Macaroon with first and third party caveats" [ mint3sig ]
80
81
82-- mint3sig = testCase "Signature" $
83-- "6B99EDB2EC6D7A4382071D7D41A0BF7DFA27D87D2F9FEA86E330D7850FFDA2B2" @=? (hex . signature) m4