diff options
Diffstat (limited to 'test/Crypto/Macaroon/Serializer/Base64')
-rw-r--r-- | test/Crypto/Macaroon/Serializer/Base64/Tests.hs | 83 |
1 files changed, 83 insertions, 0 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 | {-| | ||
3 | Copyright : (c) 2015 Julien Tanguy | ||
4 | License : BSD3 | ||
5 | |||
6 | Maintainer : julien.tanguy@jhome.fr | ||
7 | |||
8 | |||
9 | This test suite is based on the pymacaroons test suite: | ||
10 | <https://github.com/ecordell/pymacaroons> | ||
11 | -} | ||
12 | module Crypto.Macaroon.Serializer.Base64.Tests where | ||
13 | |||
14 | |||
15 | import qualified Data.ByteString.Char8 as B8 | ||
16 | import Test.Tasty | ||
17 | import Test.Tasty.HUnit | ||
18 | |||
19 | import Crypto.Macaroon | ||
20 | import Crypto.Macaroon.Serializer.Base64 | ||
21 | |||
22 | tests :: TestTree | ||
23 | tests = testGroup "Crypto.Macaroon.Serializer.Base64" [ basic | ||
24 | , minted | ||
25 | , minted2 | ||
26 | -- , minted3 | ||
27 | ] | ||
28 | |||
29 | |||
30 | m :: Macaroon | ||
31 | m = 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 | |||
37 | basic :: TestTree | ||
38 | basic = testGroup "Basic macaroon" [ basicSerialize | ||
39 | , basicDeserialize | ||
40 | ] | ||
41 | |||
42 | basicSerialize = testCase "Serialization" $ | ||
43 | "MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudG\ | ||
44 | \lmaWVyIHdlIHVzZWQgb3VyIHNlY3JldCBrZXkKMDAyZnNpZ25h\ | ||
45 | \dHVyZSDj2eApCFJsTAA5rhURQRXZf91ovyujebNCqvD2F9BVLwo" @=? serialize m | ||
46 | |||
47 | basicDeserialize = testCase "Deserialization" $ | ||
48 | Right m @=? (deserialize . serialize) m | ||
49 | |||
50 | m2 :: Macaroon | ||
51 | m2 = addFirstPartyCaveat "test = caveat" m | ||
52 | |||
53 | minted :: TestTree | ||
54 | minted = testGroup "Macaroon with first party caveat" [ mintSerialize | ||
55 | , mintDeserialize | ||
56 | ] | ||
57 | |||
58 | |||
59 | mintSerialize = testCase "Serialization" $ | ||
60 | "MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudGlmaWVyIHdlIHVzZ\ | ||
61 | \WQgb3VyIHNlY3JldCBrZXkKMDAxNmNpZCB0ZXN0ID0gY2F2ZWF0CjAwMmZzaWduYXR1cmUgGXusegR\ | ||
62 | \K8zMyhluSZuJtSTvdZopmDkTYjOGpmMI9vWcK" @=? serialize m2 | ||
63 | |||
64 | mintDeserialize = testCase "Deserialization" $ | ||
65 | Right m2 @=? (deserialize . serialize) m2 | ||
66 | |||
67 | |||
68 | m3 :: Macaroon | ||
69 | m3 = addFirstPartyCaveat "test = acaveat" m | ||
70 | |||
71 | minted2 :: TestTree | ||
72 | minted2 = testGroup "Macaroon with first party caveats" [ mint2Trimmed | ||
73 | , mint2Des | ||
74 | ] | ||
75 | |||
76 | mint2Trimmed = testCase "Serialization" $ | ||
77 | "MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudGlmaWVyIHdlIHVz\ | ||
78 | \ZWQgb3VyIHNlY3JldCBrZXkKMDAxN2NpZCB0ZXN0ID0gYWNhdmVhdAowMDJmc2ln\ | ||
79 | \bmF0dXJlIJRJ_V3WNJQnqlVq5eez7spnltwU_AXs8NIRY739sHooCg" @=? serialize m3 | ||
80 | |||
81 | mint2Des = testCase "Deserialization" $ | ||
82 | Right m3 @=? (deserialize . serialize) m3 | ||
83 | |||