aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/Crypto
diff options
context:
space:
mode:
Diffstat (limited to 'test/Crypto')
-rw-r--r--test/Crypto/Macaroon/Tests.hs74
1 files changed, 74 insertions, 0 deletions
diff --git a/test/Crypto/Macaroon/Tests.hs b/test/Crypto/Macaroon/Tests.hs
new file mode 100644
index 0000000..cdfb620
--- /dev/null
+++ b/test/Crypto/Macaroon/Tests.hs
@@ -0,0 +1,74 @@
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
26 , basicMintTrimmed
27 ]
28
29
30m :: Macaroon
31m = create secret key loc
32 where
33 secret = B8.pack "this is our super secret key; only we should know it"
34 key = B8.pack "we used our secret key"
35 loc = B8.pack "http://mybank/"
36
37m2 :: Macaroon
38m2 = addFirstPartyCaveat "test = caveat" m
39
40m3 :: Macaroon
41m3 = addFirstPartyCaveat "test = acaveat" m
42
43m4 :: Macaroon
44m4 = addThirdPartyCaveat caveat_key caveat_id caveat_loc n
45 where
46 n = addFirstPartyCaveat "account = 3735928559" $ create sec key loc
47 key = B8.pack "we used our other secret key"
48 loc = B8.pack "http://mybank/"
49 sec = B8.pack "this is a different super-secret key; never use the same secret twice"
50 caveat_key = B8.pack "4; guaranteed random by a fair toss of the dice"
51 caveat_id = B8.pack "this was how we remind auth of key/pred"
52 caveat_loc = B8.pack "http://auth.mybank/"
53
54
55basicSignature = testCase "Basic signature" $
56 "E3D9E02908526C4C0039AE15114115D97FDD68BF2BA379B342AAF0F617D0552F" @=? (hex . signature) m
57
58basicSerialize = testCase "Serialization" $
59 "MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudG\
60 \lmaWVyIHdlIHVzZWQgb3VyIHNlY3JldCBrZXkKMDAyZnNpZ25h\
61 \dHVyZSDj2eApCFJsTAA5rhURQRXZf91ovyujebNCqvD2F9BVLwo" @=? serialize m
62
63basicMint = testCase "First Party Caveat" $
64 "MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudGlmaWVyIHdlIHVzZ\
65 \WQgb3VyIHNlY3JldCBrZXkKMDAxNmNpZCB0ZXN0ID0gY2F2ZWF0CjAwMmZzaWduYXR1cmUgGXusegR\
66 \K8zMyhluSZuJtSTvdZopmDkTYjOGpmMI9vWcK" @=? serialize m2
67
68basicMintTrimmed = testCase "Trimmed base64" $
69 "MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudGlmaWVyIHdlIHVz\
70 \ZWQgb3VyIHNlY3JldCBrZXkKMDAxN2NpZCB0ZXN0ID0gYWNhdmVhdAowMDJmc2ln\
71 \bmF0dXJlIJRJ_V3WNJQnqlVq5eez7spnltwU_AXs8NIRY739sHooCg" @=? serialize m3
72
73basicThirdParty = testCase "Third Party Caveat" $
74 "6B99EDB2EC6D7A4382071D7D41A0BF7DFA27D87D2F9FEA86E330D7850FFDA2B2" @=? (hex . signature) m4