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
27 -- | Adjust the size parameter, by transforming it with the given
29 scale :: (Int -> Int) -> Gen a -> Gen a
30 scale f g = sized (\n -> resize (f n) g)
32 newtype Url = Url { unUrl :: BS.ByteString } deriving (Show)
34 instance Arbitrary Url where
36 protocol <- elements ["http://"]
37 name <- fmap (intercalate ".") <$> listOf1 . listOf1 $ elements ['a'..'z']
38 domain <- elements [".com",".net"]
39 return . Url . B8.pack $ (protocol ++ name ++ domain)
41 newtype Secret = Secret { unSecret :: BS.ByteString } deriving (Show)
43 instance Arbitrary Secret where
44 arbitrary = Secret . B8.pack <$> scale (*3) arbitrary
46 newtype Identifier = Identifier { unIdent :: BS.ByteString } deriving (Show)
48 instance Arbitrary Identifier where
49 arbitrary = Identifier . B8.pack <$>(scale (*3) . listOf1 . elements $ ['a'..'z'])
51 data SimpleMac = SimpleMac { secret :: BS.ByteString, macaroon :: Macaroon } deriving Show
53 instance Arbitrary SimpleMac where
55 secret <- unSecret <$> arbitrary
56 location <- unUrl <$> arbitrary
57 ident <- unIdent <$> arbitrary
58 return $ SimpleMac secret (create secret ident location)