diff options
author | Julien Tanguy <julien.tanguy@jhome.fr> | 2015-05-15 18:29:11 +0200 |
---|---|---|
committer | Julien Tanguy <julien.tanguy@jhome.fr> | 2015-05-15 23:10:16 +0200 |
commit | 2ba8d1c3034fb99723ba42c066b56ed6b0691a2f (patch) | |
tree | 16f904849a68847822b3ba73a65a54ad47f2bc49 /test | |
parent | b7889567b811ac347acff9983d15ab0e91c76876 (diff) | |
download | hmacaroons-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.hs | 14 |
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) | |||
48 | instance Arbitrary Identifier where | 48 | instance 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 | ||
51 | newtype EquationLike = EquationLike { unEqlike :: BS.ByteString } deriving (Show) | ||
52 | |||
53 | instance 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 | |||
51 | data SimpleMac = SimpleMac { secret :: BS.ByteString, macaroon :: Macaroon } deriving Show | 61 | data SimpleMac = SimpleMac { secret :: BS.ByteString, macaroon :: Macaroon } deriving Show |
52 | 62 | ||
53 | instance Arbitrary SimpleMac where | 63 | instance 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 | ||