aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/Crypto/Macaroon/Instances.hs
diff options
context:
space:
mode:
authorJulien Tanguy <julien.tanguy@jhome.fr>2015-04-15 15:30:28 +0200
committerJulien Tanguy <julien.tanguy@jhome.fr>2015-04-15 15:30:28 +0200
commita22bcdb648d1f540ae895cb246997dcdcce7b568 (patch)
tree9b69685f806b1419bea9f1304f73655420ed12b3 /test/Crypto/Macaroon/Instances.hs
parent46af385cc6f7c7e378ef7866a3da4ad9fb6e941c (diff)
downloadhmacaroons-a22bcdb648d1f540ae895cb246997dcdcce7b568.tar.gz
hmacaroons-a22bcdb648d1f540ae895cb246997dcdcce7b568.tar.zst
hmacaroons-a22bcdb648d1f540ae895cb246997dcdcce7b568.zip
Add quickchecked serialization properties
Diffstat (limited to 'test/Crypto/Macaroon/Instances.hs')
-rw-r--r--test/Crypto/Macaroon/Instances.hs54
1 files changed, 54 insertions, 0 deletions
diff --git a/test/Crypto/Macaroon/Instances.hs b/test/Crypto/Macaroon/Instances.hs
new file mode 100644
index 0000000..5d4b062
--- /dev/null
+++ b/test/Crypto/Macaroon/Instances.hs
@@ -0,0 +1,54 @@
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.Instances where
13
14import Control.Monad
15import Data.Byteable
16import qualified Data.ByteString as BS
17import qualified Data.ByteString.Char8 as B8
18import Data.Hex
19import Data.List
20import Test.Tasty
21import Test.Tasty.HUnit
22import Test.Tasty.QuickCheck
23
24import Crypto.Macaroon
25
26newtype Url = Url { unUrl :: BS.ByteString } deriving (Show)
27
28instance Arbitrary Url where
29 arbitrary = do
30 protocol <- elements ["http://"]
31 name <- fmap (intercalate ".") <$> listOf1 . listOf1 $ elements ['a'..'z']
32 domain <- elements [".com",".net"]
33 return . Url . B8.pack $ (protocol ++ name ++ domain)
34
35newtype Secret = Secret { unSecret :: BS.ByteString } deriving (Show)
36
37instance Arbitrary Secret where
38 arbitrary = Secret . B8.pack <$> scale (*3) arbitrary
39
40newtype Identifier = Identifier { unIdent :: BS.ByteString } deriving (Show)
41
42instance Arbitrary Identifier where
43 arbitrary = Identifier . B8.pack <$>(scale (*3) . listOf1 . elements $ ['a'..'z'])
44
45data SimpleMac = SimpleMac { secret :: BS.ByteString, macaroon :: Macaroon } deriving Show
46
47instance Arbitrary SimpleMac where
48 arbitrary = do
49 secret <- unSecret <$> arbitrary
50 location <- unUrl <$> arbitrary
51 ident <- unIdent <$> arbitrary
52 return $ SimpleMac secret (create secret ident location)
53
54