aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/Crypto
diff options
context:
space:
mode:
Diffstat (limited to 'test/Crypto')
-rw-r--r--test/Crypto/Macaroon/Serializer/Base64/Tests.hs83
-rw-r--r--test/Crypto/Macaroon/Tests.hs49
2 files changed, 93 insertions, 39 deletions
diff --git a/test/Crypto/Macaroon/Serializer/Base64/Tests.hs b/test/Crypto/Macaroon/Serializer/Base64/Tests.hs
new file mode 100644
index 0000000..9c49e96
--- /dev/null
+++ b/test/Crypto/Macaroon/Serializer/Base64/Tests.hs
@@ -0,0 +1,83 @@
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.Serializer.Base64.Tests where
13
14
15import qualified Data.ByteString.Char8 as B8
16import Test.Tasty
17import Test.Tasty.HUnit
18
19import Crypto.Macaroon
20import Crypto.Macaroon.Serializer.Base64
21
22tests :: TestTree
23tests = testGroup "Crypto.Macaroon.Serializer.Base64" [ basic
24 , minted
25 , minted2
26 -- , minted3
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
37basic :: TestTree
38basic = testGroup "Basic macaroon" [ basicSerialize
39 , basicDeserialize
40 ]
41
42basicSerialize = testCase "Serialization" $
43 "MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudG\
44 \lmaWVyIHdlIHVzZWQgb3VyIHNlY3JldCBrZXkKMDAyZnNpZ25h\
45 \dHVyZSDj2eApCFJsTAA5rhURQRXZf91ovyujebNCqvD2F9BVLwo" @=? serialize m
46
47basicDeserialize = testCase "Deserialization" $
48 Right m @=? (deserialize . serialize) m
49
50m2 :: Macaroon
51m2 = addFirstPartyCaveat "test = caveat" m
52
53minted :: TestTree
54minted = testGroup "Macaroon with first party caveat" [ mintSerialize
55 , mintDeserialize
56 ]
57
58
59mintSerialize = testCase "Serialization" $
60 "MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudGlmaWVyIHdlIHVzZ\
61 \WQgb3VyIHNlY3JldCBrZXkKMDAxNmNpZCB0ZXN0ID0gY2F2ZWF0CjAwMmZzaWduYXR1cmUgGXusegR\
62 \K8zMyhluSZuJtSTvdZopmDkTYjOGpmMI9vWcK" @=? serialize m2
63
64mintDeserialize = testCase "Deserialization" $
65 Right m2 @=? (deserialize . serialize) m2
66
67
68m3 :: Macaroon
69m3 = addFirstPartyCaveat "test = acaveat" m
70
71minted2 :: TestTree
72minted2 = testGroup "Macaroon with first party caveats" [ mint2Trimmed
73 , mint2Des
74 ]
75
76mint2Trimmed = testCase "Serialization" $
77 "MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudGlmaWVyIHdlIHVz\
78 \ZWQgb3VyIHNlY3JldCBrZXkKMDAxN2NpZCB0ZXN0ID0gYWNhdmVhdAowMDJmc2ln\
79 \bmF0dXJlIJRJ_V3WNJQnqlVq5eez7spnltwU_AXs8NIRY739sHooCg" @=? serialize m3
80
81mint2Des = testCase "Deserialization" $
82 Right m3 @=? (deserialize . serialize) m3
83
diff --git a/test/Crypto/Macaroon/Tests.hs b/test/Crypto/Macaroon/Tests.hs
index 244ec50..25d77c8 100644
--- a/test/Crypto/Macaroon/Tests.hs
+++ b/test/Crypto/Macaroon/Tests.hs
@@ -23,8 +23,6 @@ import Crypto.Macaroon.Serializer.Base64
23tests :: TestTree 23tests :: TestTree
24tests = testGroup "Crypto.Macaroon" [ basic 24tests = testGroup "Crypto.Macaroon" [ basic
25 , minted 25 , minted
26 , minted2
27 -- , minted3
28 ] 26 ]
29 27
30 28
@@ -36,29 +34,24 @@ m = create secret key loc
36 loc = B8.pack "http://mybank/" 34 loc = B8.pack "http://mybank/"
37 35
38basic :: TestTree 36basic :: TestTree
39basic = testGroup "Basic macaroon" [ basicSignature 37basic = testGroup "Basic macaroon" [ basicInspect
40 , basicSerialize 38 , basicSignature
41 , basicDeserialize
42 ] 39 ]
43 40
41basicInspect = testCase "Inspect" $
42 "location http://mybank/\nidentifier we used\
43 \ our secret key\n\nsignature E3D9E02908526C4C\
44 \0039AE15114115D97FDD68BF2BA379B342AAF0F617D0552F" @=? inspect m
45
44basicSignature = testCase "Signature" $ 46basicSignature = testCase "Signature" $
45 "E3D9E02908526C4C0039AE15114115D97FDD68BF2BA379B342AAF0F617D0552F" @=? (hex . signature) m 47 "E3D9E02908526C4C0039AE15114115D97FDD68BF2BA379B342AAF0F617D0552F" @=? (hex . signature) m
46 48
47basicSerialize = testCase "Serialization" $
48 "MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudG\
49 \lmaWVyIHdlIHVzZWQgb3VyIHNlY3JldCBrZXkKMDAyZnNpZ25h\
50 \dHVyZSDj2eApCFJsTAA5rhURQRXZf91ovyujebNCqvD2F9BVLwo" @=? serialize m
51
52basicDeserialize = testCase "Deserialization" $
53 Right m @=? (deserialize . serialize) m
54
55m2 :: Macaroon 49m2 :: Macaroon
56m2 = addFirstPartyCaveat "test = caveat" m 50m2 = addFirstPartyCaveat "test = caveat" m
57 51
58minted :: TestTree 52minted :: TestTree
59minted = testGroup "Macaroon with first party caveat" [ mintInspect 53minted = testGroup "Macaroon with first party caveat" [ mintInspect
60 , mintSerialize 54 , mintSignature
61 , mintDeserialize
62 ] 55 ]
63 56
64mintInspect = testCase "Inspect" $ 57mintInspect = testCase "Inspect" $
@@ -68,30 +61,8 @@ mintInspect = testCase "Inspect" $
68 \3BDD668A660E44D88CE1A998C23DBD67" @=? inspect m2 61 \3BDD668A660E44D88CE1A998C23DBD67" @=? inspect m2
69 62
70 63
71mintSerialize = testCase "Serialization" $ 64mintSignature = testCase "Signature" $
72 "MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudGlmaWVyIHdlIHVzZ\ 65 "197BAC7A044AF33332865B9266E26D493BDD668A660E44D88CE1A998C23DBD67" @=? (hex . signature) m2
73 \WQgb3VyIHNlY3JldCBrZXkKMDAxNmNpZCB0ZXN0ID0gY2F2ZWF0CjAwMmZzaWduYXR1cmUgGXusegR\
74 \K8zMyhluSZuJtSTvdZopmDkTYjOGpmMI9vWcK" @=? serialize m2
75
76mintDeserialize = testCase "Deserialization" $
77 Right m2 @=? (deserialize . serialize) m2
78
79
80m3 :: Macaroon
81m3 = addFirstPartyCaveat "test = acaveat" m
82
83minted2 :: TestTree
84minted2 = testGroup "Macaroon with first party caveats" [ mint2Trimmed
85 , mint2Des
86 ]
87
88mint2Trimmed = testCase "Serialization" $
89 "MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudGlmaWVyIHdlIHVz\
90 \ZWQgb3VyIHNlY3JldCBrZXkKMDAxN2NpZCB0ZXN0ID0gYWNhdmVhdAowMDJmc2ln\
91 \bmF0dXJlIJRJ_V3WNJQnqlVq5eez7spnltwU_AXs8NIRY739sHooCg" @=? serialize m3
92
93mint2Des = testCase "Deserialization" $
94 Right m3 @=? (deserialize . serialize) m3
95 66
96-- m4 :: Macaroon 67-- m4 :: Macaroon
97-- m4 = addThirdPartyCaveat caveat_key caveat_id caveat_loc n 68-- m4 = addThirdPartyCaveat caveat_key caveat_id caveat_loc n