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.Instances where
16 import qualified Data.ByteString as BS
17 import qualified Data.ByteString.Char8 as B8
21 import Test.Tasty.HUnit
22 import Test.Tasty.QuickCheck
24 import Crypto.Macaroon
26 newtype Url = Url { unUrl :: BS.ByteString } deriving (Show)
28 instance Arbitrary Url where
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)
35 newtype Secret = Secret { unSecret :: BS.ByteString } deriving (Show)
37 instance Arbitrary Secret where
38 arbitrary = Secret . B8.pack <$> scale (*3) arbitrary
40 newtype Identifier = Identifier { unIdent :: BS.ByteString } deriving (Show)
42 instance Arbitrary Identifier where
43 arbitrary = Identifier . B8.pack <$>(scale (*3) . listOf1 . elements $ ['a'..'z'])
45 data SimpleMac = SimpleMac { secret :: BS.ByteString, macaroon :: Macaroon } deriving Show
47 instance Arbitrary SimpleMac where
49 secret <- unSecret <$> arbitrary
50 location <- unUrl <$> arbitrary
51 ident <- unIdent <$> arbitrary
52 return $ SimpleMac secret (create secret ident location)