From 2ba8d1c3034fb99723ba42c066b56ed6b0691a2f Mon Sep 17 00:00:00 2001 From: Julien Tanguy Date: Fri, 15 May 2015 18:29:11 +0200 Subject: 1st party caveats to Macaroon Arbitrary instance --- test/Crypto/Macaroon/Instances.hs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'test/Crypto/Macaroon/Instances.hs') diff --git a/test/Crypto/Macaroon/Instances.hs b/test/Crypto/Macaroon/Instances.hs index 4e2f39f..17044a0 100644 --- a/test/Crypto/Macaroon/Instances.hs +++ b/test/Crypto/Macaroon/Instances.hs @@ -48,6 +48,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 +65,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 -- cgit v1.2.3 From 90695615c54b5939d7286e777cb1b19a221616b9 Mon Sep 17 00:00:00 2001 From: Julien Tanguy Date: Sat, 16 May 2015 02:12:14 +0200 Subject: Fix caveat verification QuickCheck properties > HUnit tests --- test/Crypto/Macaroon/Instances.hs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test/Crypto/Macaroon/Instances.hs') diff --git a/test/Crypto/Macaroon/Instances.hs b/test/Crypto/Macaroon/Instances.hs index 17044a0..c82bbd3 100644 --- a/test/Crypto/Macaroon/Instances.hs +++ b/test/Crypto/Macaroon/Instances.hs @@ -26,9 +26,16 @@ import Crypto.Macaroon -- | Adjust the size parameter, by transforming it with the given -- function. +-- Copied over from QuickCheck 2.8 scale :: (Int -> Int) -> Gen a -> Gen a scale f g = sized (\n -> resize (f n) g) + +-- | Generates a random subsequence of the given list. +-- Copied over from QuickCheck 2.8 +sublistOf :: [a] -> Gen [a] +sublistOf = filterM (\_ -> choose (False, True)) + newtype Url = Url { unUrl :: BS.ByteString } deriving (Show) instance Arbitrary Url where -- cgit v1.2.3