diff options
author | Julien Tanguy <julien.tanguy@jhome.fr> | 2015-05-15 22:31:05 +0200 |
---|---|---|
committer | Julien Tanguy <julien.tanguy@jhome.fr> | 2015-05-15 23:10:16 +0200 |
commit | 6f3c0dca02c1069115bc2592c439970d2af07cc5 (patch) | |
tree | 90ebecf85eec1b041de347c16b931f3cba7ccc2b /test/Crypto/Macaroon/Verifier | |
parent | 2ba8d1c3034fb99723ba42c066b56ed6b0691a2f (diff) | |
download | hmacaroons-6f3c0dca02c1069115bc2592c439970d2af07cc5.tar.gz hmacaroons-6f3c0dca02c1069115bc2592c439970d2af07cc5.tar.zst hmacaroons-6f3c0dca02c1069115bc2592c439970d2af07cc5.zip |
Add basic exact caveat verifiers
Need more tests
Touching #2 Verify first party caveats
Diffstat (limited to 'test/Crypto/Macaroon/Verifier')
-rw-r--r-- | test/Crypto/Macaroon/Verifier/Tests.hs | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/test/Crypto/Macaroon/Verifier/Tests.hs b/test/Crypto/Macaroon/Verifier/Tests.hs index f87f192..37d0230 100644 --- a/test/Crypto/Macaroon/Verifier/Tests.hs +++ b/test/Crypto/Macaroon/Verifier/Tests.hs | |||
@@ -24,6 +24,7 @@ import Crypto.Macaroon.Instances | |||
24 | 24 | ||
25 | tests :: TestTree | 25 | tests :: TestTree |
26 | tests = testGroup "Crypto.Macaroon.Verifier" [ sigs | 26 | tests = testGroup "Crypto.Macaroon.Verifier" [ sigs |
27 | , exactCavs | ||
27 | ] | 28 | ] |
28 | 29 | ||
29 | {- | 30 | {- |
@@ -41,7 +42,14 @@ m2 :: Macaroon | |||
41 | m2 = addFirstPartyCaveat "test = caveat" m | 42 | m2 = addFirstPartyCaveat "test = caveat" m |
42 | 43 | ||
43 | m3 :: Macaroon | 44 | m3 :: Macaroon |
44 | m3 = addFirstPartyCaveat "test = acaveat" m | 45 | m3 = addFirstPartyCaveat "value = 42" m2 |
46 | |||
47 | exVerifiers = [ verifyExact "test" "caveat" (many' letter_ascii) | ||
48 | , verifyExact "value" 42 decimal | ||
49 | ] | ||
50 | exVerifiers' = [ verifyExact "test" "caveat" (many' letter_ascii) | ||
51 | , verifyExact "value" 43 decimal | ||
52 | ] | ||
45 | 53 | ||
46 | {- | 54 | {- |
47 | - Tests | 55 | - Tests |
@@ -54,14 +62,26 @@ sigs = testGroup "Signatures" [ basic | |||
54 | basic = testGroup "Basic Macaroon" [ none , sigQC ] | 62 | basic = testGroup "Basic Macaroon" [ none , sigQC ] |
55 | 63 | ||
56 | none = testCase "No caveat" $ | 64 | none = testCase "No caveat" $ |
57 | VSuccess @=? verifySig sec m | 65 | Ok @=? verifySig sec m |
58 | 66 | ||
59 | sigQC = testProperty "Random" $ | 67 | sigQC = testProperty "Random" $ |
60 | \sm -> verifySig (secret sm) (macaroon sm) == VSuccess | 68 | \sm -> verifySig (secret sm) (macaroon sm) == Ok |
61 | 69 | ||
62 | one = testCase "Macaroon with one caveat" $ | 70 | one = testCase "Macaroon with one caveat" $ |
63 | VSuccess @=? verifySig sec m2 | 71 | Ok @=? verifySig sec m2 |
64 | 72 | ||
65 | two = testCase "Macaroon with two caveats" $ | 73 | two = testCase "Macaroon with two caveats" $ |
66 | VSuccess @=? verifySig sec m3 | 74 | Ok @=? verifySig sec m3 |
67 | 75 | ||
76 | exactCavs = testGroup "Exact Caveats" [ zero', one', two' , one'', two''] | ||
77 | |||
78 | zero' = testCase "Zero caveat win" $ | ||
79 | Ok @=? verifyCavs exVerifiers m | ||
80 | one' = testCase "One caveat win" $ | ||
81 | Ok @=? verifyCavs exVerifiers m2 | ||
82 | one'' = testCase "Ignoring non-relevant" $ | ||
83 | Ok @=? verifyCavs exVerifiers' m2 | ||
84 | two' = testCase "Two caveat win" $ | ||
85 | Ok @=? verifyCavs exVerifiers m3 | ||
86 | two'' = testCase "Two caveat fail" $ | ||
87 | Failed @=? verifyCavs exVerifiers' m3 | ||