aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/Crypto
diff options
context:
space:
mode:
authorJulien Tanguy <julien.tanguy@jhome.fr>2015-05-15 16:03:30 +0200
committerJulien Tanguy <julien.tanguy@jhome.fr>2015-05-15 23:10:16 +0200
commit5d1b7d51854d355bf5b6438c1a96ce9e743fd810 (patch)
tree9790591988ee639d50bc873e5f757a4c0e6b7ffb /test/Crypto
parent8fad4fa9d1b592ece4806dcd9abb6c011d3948bf (diff)
downloadhmacaroons-5d1b7d51854d355bf5b6438c1a96ce9e743fd810.tar.gz
hmacaroons-5d1b7d51854d355bf5b6438c1a96ce9e743fd810.tar.zst
hmacaroons-5d1b7d51854d355bf5b6438c1a96ce9e743fd810.zip
Add quickcheck properties
Diffstat (limited to 'test/Crypto')
-rw-r--r--test/Crypto/Macaroon/Serializer/Base64/Tests.hs2
-rw-r--r--test/Crypto/Macaroon/Verifier/Tests.hs30
2 files changed, 20 insertions, 12 deletions
diff --git a/test/Crypto/Macaroon/Serializer/Base64/Tests.hs b/test/Crypto/Macaroon/Serializer/Base64/Tests.hs
index 19084af..ea3bed9 100644
--- a/test/Crypto/Macaroon/Serializer/Base64/Tests.hs
+++ b/test/Crypto/Macaroon/Serializer/Base64/Tests.hs
@@ -30,7 +30,7 @@ tests = testGroup "Crypto.Macaroon.Serializer.Base64" [ basic
30 ] 30 ]
31 31
32basicQC = testProperty "Reversibility" $ 32basicQC = testProperty "Reversibility" $
33 forAll (macaroon <$> arbitrary) (\m -> deserialize (serialize m) == Right m) 33 \sm -> deserialize (serialize (macaroon sm)) == Right (macaroon sm)
34 34
35m :: Macaroon 35m :: Macaroon
36m = create secret key loc 36m = create secret key loc
diff --git a/test/Crypto/Macaroon/Verifier/Tests.hs b/test/Crypto/Macaroon/Verifier/Tests.hs
index 92a8a21..f87f192 100644
--- a/test/Crypto/Macaroon/Verifier/Tests.hs
+++ b/test/Crypto/Macaroon/Verifier/Tests.hs
@@ -15,6 +15,7 @@ module Crypto.Macaroon.Verifier.Tests where
15import qualified Data.ByteString.Char8 as B8 15import qualified Data.ByteString.Char8 as B8
16import Test.Tasty 16import Test.Tasty
17import Test.Tasty.HUnit 17import Test.Tasty.HUnit
18import Test.Tasty.QuickCheck
18 19
19import Crypto.Macaroon 20import Crypto.Macaroon
20import Crypto.Macaroon.Verifier 21import Crypto.Macaroon.Verifier
@@ -25,6 +26,9 @@ tests :: TestTree
25tests = testGroup "Crypto.Macaroon.Verifier" [ sigs 26tests = testGroup "Crypto.Macaroon.Verifier" [ sigs
26 ] 27 ]
27 28
29{-
30 - Test fixtures
31 -}
28sec = B8.pack "this is our super secret key; only we should know it" 32sec = B8.pack "this is our super secret key; only we should know it"
29 33
30m :: Macaroon 34m :: Macaroon
@@ -39,21 +43,25 @@ m2 = addFirstPartyCaveat "test = caveat" m
39m3 :: Macaroon 43m3 :: Macaroon
40m3 = addFirstPartyCaveat "test = acaveat" m 44m3 = addFirstPartyCaveat "test = acaveat" m
41 45
46{-
47 - Tests
48 -}
42sigs = testGroup "Signatures" [ basic 49sigs = testGroup "Signatures" [ basic
43 , minted 50 , one
51 , two
44 ] 52 ]
45 53
46basic = testCase "Basic Macaroon Signature" $ 54basic = testGroup "Basic Macaroon" [ none , sigQC ]
47 Success @=? verifySig sec m
48 55
56none = testCase "No caveat" $
57 VSuccess @=? verifySig sec m
49 58
50minted :: TestTree 59sigQC = testProperty "Random" $
51minted = testGroup "Macaroon with first party caveats" [ one 60 \sm -> verifySig (secret sm) (macaroon sm) == VSuccess
52 , two
53 ]
54one = testCase "One caveat" $
55 Success @=? verifySig sec m2
56 61
57two = testCase "Two caveats" $ 62one = testCase "Macaroon with one caveat" $
58 Success @=? verifySig sec m3 63 VSuccess @=? verifySig sec m2
64
65two = testCase "Macaroon with two caveats" $
66 VSuccess @=? verifySig sec m3
59 67