1 {-# LANGUAGE OverloadedStrings #-}
3 Copyright : (c) 2015 Julien Tanguy
6 Maintainer : julien.tanguy@jhome.fr
9 This test suite is based on the pymacaroons test suite:
10 <https://github.com/ecordell/pymacaroons>
12 module Crypto.Macaroon.Serializer.Base64.Tests where
15 import qualified Data.ByteString.Char8 as B8
17 import Test.Tasty.HUnit
18 import Test.Tasty.QuickCheck
20 import Crypto.Macaroon
21 import Crypto.Macaroon.Serializer.Base64
23 import Crypto.Macaroon.Instances
26 tests = testGroup "Crypto.Macaroon.Serializer.Base64" [ basic
32 basicQC = testProperty "Reversibility" $
33 \sm -> deserialize (serialize (macaroon sm)) == Right (macaroon sm)
36 m = create secret key loc
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/"
43 basic = testGroup "Basic macaroon" [ basicSerialize
48 basicSerialize = testCase "Serialization" $
49 "MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudG\
50 \lmaWVyIHdlIHVzZWQgb3VyIHNlY3JldCBrZXkKMDAyZnNpZ25h\
51 \dHVyZSDj2eApCFJsTAA5rhURQRXZf91ovyujebNCqvD2F9BVLwo" @=? serialize m
53 basicDeserialize = testCase "Deserialization" $
54 Right m @=? (deserialize . serialize) m
57 m2 = addFirstPartyCaveat "test = caveat" m
60 minted = testGroup "Macaroon with first party caveat" [ mintSerialize
65 mintSerialize = testCase "Serialization" $
66 "MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudGlmaWVyIHdlIHVzZ\
67 \WQgb3VyIHNlY3JldCBrZXkKMDAxNmNpZCB0ZXN0ID0gY2F2ZWF0CjAwMmZzaWduYXR1cmUgGXusegR\
68 \K8zMyhluSZuJtSTvdZopmDkTYjOGpmMI9vWcK" @=? serialize m2
70 mintDeserialize = testCase "Deserialization" $
71 Right m2 @=? (deserialize . serialize) m2
75 m3 = addFirstPartyCaveat "test = acaveat" m
78 minted2 = testGroup "Macaroon with first party caveats" [ mint2Trimmed
82 mint2Trimmed = testCase "Serialization" $
83 "MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudGlmaWVyIHdlIHVz\
84 \ZWQgb3VyIHNlY3JldCBrZXkKMDAxN2NpZCB0ZXN0ID0gYWNhdmVhdAowMDJmc2ln\
85 \bmF0dXJlIJRJ_V3WNJQnqlVq5eez7spnltwU_AXs8NIRY739sHooCg" @=? serialize m3
87 mint2Des = testCase "Deserialization" $
88 Right m3 @=? (deserialize . serialize) m3