]> git.immae.eu Git - github/fretlink/hmacaroons.git/blob - test/Crypto/Macaroon/Serializer/Base64/Tests.hs
Rearrange tests
[github/fretlink/hmacaroons.git] / test / Crypto / Macaroon / Serializer / Base64 / Tests.hs
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 import Test.Tasty.QuickCheck
19
20 import Crypto.Macaroon
21 import Crypto.Macaroon.Serializer.Base64
22
23 import Crypto.Macaroon.Instances
24
25 tests :: TestTree
26 tests = testGroup "Crypto.Macaroon.Serializer.Base64" [ basic
27 , minted
28 , minted2
29 -- , minted3
30 ]
31
32 basicQC = testProperty "Reversibility" $
33 forAll (macaroon <$> arbitrary) (\m -> deserialize (serialize m) == Right m)
34
35 m :: Macaroon
36 m = create secret key loc
37 where
38 secret = B8.pack "this is our super secret key; only we should know it"
39 key = B8.pack "we used our secret key"
40 loc = B8.pack "http://mybank/"
41
42 basic :: TestTree
43 basic = testGroup "Basic macaroon" [ basicSerialize
44 , basicDeserialize
45 , basicQC
46 ]
47
48 basicSerialize = testCase "Serialization" $
49 "MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudG\
50 \lmaWVyIHdlIHVzZWQgb3VyIHNlY3JldCBrZXkKMDAyZnNpZ25h\
51 \dHVyZSDj2eApCFJsTAA5rhURQRXZf91ovyujebNCqvD2F9BVLwo" @=? serialize m
52
53 basicDeserialize = testCase "Deserialization" $
54 Right m @=? (deserialize . serialize) m
55
56 m2 :: Macaroon
57 m2 = addFirstPartyCaveat "test = caveat" m
58
59 minted :: TestTree
60 minted = testGroup "Macaroon with first party caveat" [ mintSerialize
61 , mintDeserialize
62 ]
63
64
65 mintSerialize = testCase "Serialization" $
66 "MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudGlmaWVyIHdlIHVzZ\
67 \WQgb3VyIHNlY3JldCBrZXkKMDAxNmNpZCB0ZXN0ID0gY2F2ZWF0CjAwMmZzaWduYXR1cmUgGXusegR\
68 \K8zMyhluSZuJtSTvdZopmDkTYjOGpmMI9vWcK" @=? serialize m2
69
70 mintDeserialize = testCase "Deserialization" $
71 Right m2 @=? (deserialize . serialize) m2
72
73
74 m3 :: Macaroon
75 m3 = addFirstPartyCaveat "test = acaveat" m
76
77 minted2 :: TestTree
78 minted2 = testGroup "Macaroon with first party caveats" [ mint2Trimmed
79 , mint2Des
80 ]
81
82 mint2Trimmed = testCase "Serialization" $
83 "MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudGlmaWVyIHdlIHVz\
84 \ZWQgb3VyIHNlY3JldCBrZXkKMDAxN2NpZCB0ZXN0ID0gYWNhdmVhdAowMDJmc2ln\
85 \bmF0dXJlIJRJ_V3WNJQnqlVq5eez7spnltwU_AXs8NIRY739sHooCg" @=? serialize m3
86
87 mint2Des = testCase "Deserialization" $
88 Right m3 @=? (deserialize . serialize) m3
89