aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorJulien Tanguy <julien.tanguy@jhome.fr>2015-04-14 17:40:08 +0200
committerJulien Tanguy <julien.tanguy@jhome.fr>2015-04-14 17:40:08 +0200
commita20c77f85bcbc74b70c108f440435c70b29ab822 (patch)
tree34f0ca81908496939b3010d376be589c09ddfb5d /test
parentb44d2aa13fc1172e4bda303e7d177389e22d3f95 (diff)
downloadhmacaroons-a20c77f85bcbc74b70c108f440435c70b29ab822.tar.gz
hmacaroons-a20c77f85bcbc74b70c108f440435c70b29ab822.tar.zst
hmacaroons-a20c77f85bcbc74b70c108f440435c70b29ab822.zip
Deserialize Macaroons
- Refactor serialization/deserialization into its own module - Refactor tests
Diffstat (limited to 'test')
-rw-r--r--test/Crypto/Macaroon/Tests.hs48
1 files changed, 38 insertions, 10 deletions
diff --git a/test/Crypto/Macaroon/Tests.hs b/test/Crypto/Macaroon/Tests.hs
index f57bec3..6fa6504 100644
--- a/test/Crypto/Macaroon/Tests.hs
+++ b/test/Crypto/Macaroon/Tests.hs
@@ -18,13 +18,13 @@ import Test.Tasty
18import Test.Tasty.HUnit 18import Test.Tasty.HUnit
19 19
20import Crypto.Macaroon 20import Crypto.Macaroon
21import Crypto.Macaroon.Serializer.Base64
21 22
22tests :: TestTree 23tests :: TestTree
23tests = testGroup "Crypto.Macaroon" [ basicSignature 24tests = testGroup "Crypto.Macaroon" [ basic
24 , basicSerialize 25 , minted
25 , basicMint 26 , minted2
26 , basicInspect 27 , minted3
27 , basicMintTrimmed
28 ] 28 ]
29 29
30 30
@@ -35,7 +35,13 @@ m = create secret key loc
35 key = B8.pack "we used our secret key" 35 key = B8.pack "we used our secret key"
36 loc = B8.pack "http://mybank/" 36 loc = B8.pack "http://mybank/"
37 37
38basicSignature = testCase "Basic signature" $ 38basic :: TestTree
39basic = testGroup "Basic macaroon" [ basicSignature
40 , basicSerialize
41 , basicDeserialize
42 ]
43
44basicSignature = testCase "Signature" $
39 "E3D9E02908526C4C0039AE15114115D97FDD68BF2BA379B342AAF0F617D0552F" @=? (hex . signature) m 45 "E3D9E02908526C4C0039AE15114115D97FDD68BF2BA379B342AAF0F617D0552F" @=? (hex . signature) m
40 46
41basicSerialize = testCase "Serialization" $ 47basicSerialize = testCase "Serialization" $
@@ -43,30 +49,49 @@ basicSerialize = testCase "Serialization" $
43 \lmaWVyIHdlIHVzZWQgb3VyIHNlY3JldCBrZXkKMDAyZnNpZ25h\ 49 \lmaWVyIHdlIHVzZWQgb3VyIHNlY3JldCBrZXkKMDAyZnNpZ25h\
44 \dHVyZSDj2eApCFJsTAA5rhURQRXZf91ovyujebNCqvD2F9BVLwo" @=? serialize m 50 \dHVyZSDj2eApCFJsTAA5rhURQRXZf91ovyujebNCqvD2F9BVLwo" @=? serialize m
45 51
52basicDeserialize = testCase "Deserialization" $
53 Right m @=? (deserialize . serialize) m
54
46m2 :: Macaroon 55m2 :: Macaroon
47m2 = addFirstPartyCaveat "test = caveat" m 56m2 = addFirstPartyCaveat "test = caveat" m
48 57
49basicInspect = testCase "Inspect" $ 58minted :: TestTree
59minted = testGroup "Macaroon with first party caveat" [ mintInspect
60 , mintSerialize
61 , mintDeserialize
62 ]
63
64mintInspect = testCase "Inspect" $
50 "location http://mybank/\nidentifier we used\ 65 "location http://mybank/\nidentifier we used\
51 \ our secret key\ncid test = caveat\nsignature\ 66 \ our secret key\ncid test = caveat\nsignature\
52 \ 197BAC7A044AF33332865B9266E26D49\ 67 \ 197BAC7A044AF33332865B9266E26D49\
53 \3BDD668A660E44D88CE1A998C23DBD67" @=? inspect m2 68 \3BDD668A660E44D88CE1A998C23DBD67" @=? inspect m2
54 69
55 70
56basicMint = testCase "First Party Caveat" $ 71mintSerialize = testCase "Serialization" $
57 "MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudGlmaWVyIHdlIHVzZ\ 72 "MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudGlmaWVyIHdlIHVzZ\
58 \WQgb3VyIHNlY3JldCBrZXkKMDAxNmNpZCB0ZXN0ID0gY2F2ZWF0CjAwMmZzaWduYXR1cmUgGXusegR\ 73 \WQgb3VyIHNlY3JldCBrZXkKMDAxNmNpZCB0ZXN0ID0gY2F2ZWF0CjAwMmZzaWduYXR1cmUgGXusegR\
59 \K8zMyhluSZuJtSTvdZopmDkTYjOGpmMI9vWcK" @=? serialize m2 74 \K8zMyhluSZuJtSTvdZopmDkTYjOGpmMI9vWcK" @=? serialize m2
60 75
76mintDeserialize = testCase "Deserialization" $
77 Right m2 @=? (deserialize . serialize) m2
78
61 79
62m3 :: Macaroon 80m3 :: Macaroon
63m3 = addFirstPartyCaveat "test = acaveat" m 81m3 = addFirstPartyCaveat "test = acaveat" m
64 82
65basicMintTrimmed = testCase "Trimmed base64" $ 83minted2 :: TestTree
84minted2 = testGroup "Macaroon with first party caveats" [ mint2Trimmed
85 , mint2Des
86 ]
87
88mint2Trimmed = testCase "Serialization" $
66 "MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudGlmaWVyIHdlIHVz\ 89 "MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudGlmaWVyIHdlIHVz\
67 \ZWQgb3VyIHNlY3JldCBrZXkKMDAxN2NpZCB0ZXN0ID0gYWNhdmVhdAowMDJmc2ln\ 90 \ZWQgb3VyIHNlY3JldCBrZXkKMDAxN2NpZCB0ZXN0ID0gYWNhdmVhdAowMDJmc2ln\
68 \bmF0dXJlIJRJ_V3WNJQnqlVq5eez7spnltwU_AXs8NIRY739sHooCg" @=? serialize m3 91 \bmF0dXJlIJRJ_V3WNJQnqlVq5eez7spnltwU_AXs8NIRY739sHooCg" @=? serialize m3
69 92
93mint2Des = testCase "Deserialization" $
94 Right m3 @=? (deserialize . serialize) m3
70 95
71m4 :: Macaroon 96m4 :: Macaroon
72m4 = addThirdPartyCaveat caveat_key caveat_id caveat_loc n 97m4 = addThirdPartyCaveat caveat_key caveat_id caveat_loc n
@@ -79,6 +104,9 @@ m4 = addThirdPartyCaveat caveat_key caveat_id caveat_loc n
79 caveat_id = B8.pack "this was how we remind auth of key/pred" 104 caveat_id = B8.pack "this was how we remind auth of key/pred"
80 caveat_loc = B8.pack "http://auth.mybank/" 105 caveat_loc = B8.pack "http://auth.mybank/"
81 106
107minted3 :: TestTree
108minted3 = testGroup "Macaroon with first and third party caveats" [ mint3sig ]
109
82 110
83basicThirdParty = testCase "Third Party Caveat" $ 111mint3sig = testCase "Signature" $
84 "6B99EDB2EC6D7A4382071D7D41A0BF7DFA27D87D2F9FEA86E330D7850FFDA2B2" @=? (hex . signature) m4 112 "6B99EDB2EC6D7A4382071D7D41A0BF7DFA27D87D2F9FEA86E330D7850FFDA2B2" @=? (hex . signature) m4