aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorJulien Tanguy <julien.tanguy@jhome.fr>2015-05-15 18:29:11 +0200
committerJulien Tanguy <julien.tanguy@jhome.fr>2015-05-15 23:10:16 +0200
commit2ba8d1c3034fb99723ba42c066b56ed6b0691a2f (patch)
tree16f904849a68847822b3ba73a65a54ad47f2bc49 /test
parentb7889567b811ac347acff9983d15ab0e91c76876 (diff)
downloadhmacaroons-2ba8d1c3034fb99723ba42c066b56ed6b0691a2f.tar.gz
hmacaroons-2ba8d1c3034fb99723ba42c066b56ed6b0691a2f.tar.zst
hmacaroons-2ba8d1c3034fb99723ba42c066b56ed6b0691a2f.zip
1st party caveats to Macaroon Arbitrary instance
Diffstat (limited to 'test')
-rw-r--r--test/Crypto/Macaroon/Instances.hs14
1 files changed, 13 insertions, 1 deletions
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)
48instance Arbitrary Identifier where 48instance Arbitrary Identifier where
49 arbitrary = Identifier . B8.pack <$>(scale (*3) . listOf1 . elements $ ['a'..'z']) 49 arbitrary = Identifier . B8.pack <$>(scale (*3) . listOf1 . elements $ ['a'..'z'])
50 50
51newtype EquationLike = EquationLike { unEqlike :: BS.ByteString } deriving (Show)
52
53instance Arbitrary EquationLike where
54 arbitrary = do
55 keylen <- choose (3,8)
56 key <- B8.pack <$> vectorOf keylen (elements ['a'..'z'])
57 val <- B8.pack <$> (scale (*3) . listOf1 . elements $ ['a'..'z'])
58 return $ EquationLike (BS.concat [ key, " = ", val])
59
60
51data SimpleMac = SimpleMac { secret :: BS.ByteString, macaroon :: Macaroon } deriving Show 61data SimpleMac = SimpleMac { secret :: BS.ByteString, macaroon :: Macaroon } deriving Show
52 62
53instance Arbitrary SimpleMac where 63instance Arbitrary SimpleMac where
@@ -55,6 +65,8 @@ instance Arbitrary SimpleMac where
55 secret <- unSecret <$> arbitrary 65 secret <- unSecret <$> arbitrary
56 location <- unUrl <$> arbitrary 66 location <- unUrl <$> arbitrary
57 ident <- unIdent <$> arbitrary 67 ident <- unIdent <$> arbitrary
58 return $ SimpleMac secret (create secret ident location) 68 fpcavs <- listOf arbitrary
69 let mac = foldl (flip addFirstPartyCaveat) (create secret ident location) (map unEqlike fpcavs)
70 return $ SimpleMac secret mac
59 71
60 72