]> git.immae.eu Git - github/fretlink/hmacaroons.git/blame - test/Crypto/Macaroon/Tests.hs
Rewording and lint
[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
21
22tests :: TestTree
23tests = testGroup "Crypto.Macaroon" [ basicSignature
24 , basicSerialize
25 , basicMint
2aede11a 26 , basicInspect
f6781456
JT
27 , basicMintTrimmed
28 ]
29
30
31m :: Macaroon
32m = create secret key loc
33 where
34 secret = B8.pack "this is our super secret key; only we should know it"
35 key = B8.pack "we used our secret key"
36 loc = B8.pack "http://mybank/"
37
2aede11a
JT
38basicSignature = testCase "Basic signature" $
39 "E3D9E02908526C4C0039AE15114115D97FDD68BF2BA379B342AAF0F617D0552F" @=? (hex . signature) m
40
41basicSerialize = testCase "Serialization" $
42 "MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudG\
43 \lmaWVyIHdlIHVzZWQgb3VyIHNlY3JldCBrZXkKMDAyZnNpZ25h\
44 \dHVyZSDj2eApCFJsTAA5rhURQRXZf91ovyujebNCqvD2F9BVLwo" @=? serialize m
45
f6781456
JT
46m2 :: Macaroon
47m2 = addFirstPartyCaveat "test = caveat" m
48
2aede11a
JT
49basicInspect = testCase "Inspect" $
50 "location http://mybank/\nidentifier we used\
51 \ our secret key\ncid test = caveat\nsignature\
52 \ 197BAC7A044AF33332865B9266E26D49\
53 \3BDD668A660E44D88CE1A998C23DBD67" @=? inspect m2
54
55
56basicMint = testCase "First Party Caveat" $
57 "MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudGlmaWVyIHdlIHVzZ\
58 \WQgb3VyIHNlY3JldCBrZXkKMDAxNmNpZCB0ZXN0ID0gY2F2ZWF0CjAwMmZzaWduYXR1cmUgGXusegR\
59 \K8zMyhluSZuJtSTvdZopmDkTYjOGpmMI9vWcK" @=? serialize m2
60
61
f6781456
JT
62m3 :: Macaroon
63m3 = addFirstPartyCaveat "test = acaveat" m
64
2aede11a
JT
65basicMintTrimmed = testCase "Trimmed base64" $
66 "MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudGlmaWVyIHdlIHVz\
67 \ZWQgb3VyIHNlY3JldCBrZXkKMDAxN2NpZCB0ZXN0ID0gYWNhdmVhdAowMDJmc2ln\
68 \bmF0dXJlIJRJ_V3WNJQnqlVq5eez7spnltwU_AXs8NIRY739sHooCg" @=? serialize m3
69
70
f6781456
JT
71m4 :: Macaroon
72m4 = addThirdPartyCaveat caveat_key caveat_id caveat_loc n
73 where
74 n = addFirstPartyCaveat "account = 3735928559" $ create sec key loc
75 key = B8.pack "we used our other secret key"
76 loc = B8.pack "http://mybank/"
77 sec = B8.pack "this is a different super-secret key; never use the same secret twice"
78 caveat_key = B8.pack "4; guaranteed random by a fair toss of the dice"
79 caveat_id = B8.pack "this was how we remind auth of key/pred"
80 caveat_loc = B8.pack "http://auth.mybank/"
81
82
2aede11a 83basicThirdParty = testCase "Third Party Caveat" $
f6781456 84 "6B99EDB2EC6D7A4382071D7D41A0BF7DFA27D87D2F9FEA86E330D7850FFDA2B2" @=? (hex . signature) m4