]> git.immae.eu Git - github/fretlink/hmacaroons.git/blobdiff - test/Crypto/Macaroon/Instances.hs
Typos and stylish-haskell
[github/fretlink/hmacaroons.git] / test / Crypto / Macaroon / Instances.hs
index 4e2f39f4d3bad32c05cedc043694a59483fd1066..9c898578af1c4b4749b9f83335d9d6d961ec5c22 100644 (file)
@@ -11,9 +11,9 @@ This test suite is based on the pymacaroons test suite:
 -}
 module Crypto.Macaroon.Instances where
 
-import Control.Monad
+import           Control.Monad
 import           Data.Byteable
-import qualified Data.ByteString as BS
+import qualified Data.ByteString       as BS
 import qualified Data.ByteString.Char8 as B8
 import           Data.Hex
 import           Data.List
@@ -23,12 +23,6 @@ import           Test.Tasty.QuickCheck
 
 import           Crypto.Macaroon
 
-
--- | Adjust the size parameter, by transforming it with the given
--- function.
-scale :: (Int -> Int) -> Gen a -> Gen a
-scale f g = sized (\n -> resize (f n) g)
-
 newtype Url = Url { unUrl :: BS.ByteString } deriving (Show)
 
 instance Arbitrary Url where
@@ -48,6 +42,16 @@ newtype Identifier = Identifier { unIdent :: BS.ByteString } deriving (Show)
 instance Arbitrary Identifier where
     arbitrary = Identifier . B8.pack <$>(scale (*3) . listOf1 . elements $ ['a'..'z'])
 
+newtype EquationLike = EquationLike { unEqlike :: BS.ByteString } deriving (Show)
+
+instance Arbitrary EquationLike where
+    arbitrary = do
+        keylen <- choose (3,8)
+        key <- B8.pack <$> vectorOf keylen (elements ['a'..'z'])
+        val <- B8.pack <$> (scale (*3) . listOf1 . elements $ ['a'..'z'])
+        return $ EquationLike (BS.concat [ key, " = ", val])
+
+
 data SimpleMac = SimpleMac { secret :: BS.ByteString, macaroon :: Macaroon } deriving Show
 
 instance Arbitrary SimpleMac where
@@ -55,6 +59,8 @@ instance Arbitrary SimpleMac where
         secret <- unSecret <$> arbitrary
         location <- unUrl <$> arbitrary
         ident <- unIdent <$> arbitrary
-        return $ SimpleMac secret (create secret ident location)
+        fpcavs <- listOf arbitrary
+        let mac = foldl (flip addFirstPartyCaveat) (create secret ident location) (map unEqlike fpcavs)
+        return $ SimpleMac secret mac