diff options
Diffstat (limited to 'test/Crypto/Macaroon')
-rw-r--r-- | test/Crypto/Macaroon/Verifier/Tests.hs | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/test/Crypto/Macaroon/Verifier/Tests.hs b/test/Crypto/Macaroon/Verifier/Tests.hs index 37d0230..54c8db1 100644 --- a/test/Crypto/Macaroon/Verifier/Tests.hs +++ b/test/Crypto/Macaroon/Verifier/Tests.hs | |||
@@ -12,6 +12,7 @@ This test suite is based on the pymacaroons test suite: | |||
12 | module Crypto.Macaroon.Verifier.Tests where | 12 | module Crypto.Macaroon.Verifier.Tests where |
13 | 13 | ||
14 | 14 | ||
15 | import Data.List | ||
15 | import qualified Data.ByteString.Char8 as B8 | 16 | import qualified Data.ByteString.Char8 as B8 |
16 | import Test.Tasty | 17 | import Test.Tasty |
17 | import Test.Tasty.HUnit | 18 | import Test.Tasty.HUnit |
@@ -50,6 +51,9 @@ exVerifiers = [ verifyExact "test" "caveat" (many' letter_ascii) | |||
50 | exVerifiers' = [ verifyExact "test" "caveat" (many' letter_ascii) | 51 | exVerifiers' = [ verifyExact "test" "caveat" (many' letter_ascii) |
51 | , verifyExact "value" 43 decimal | 52 | , verifyExact "value" 43 decimal |
52 | ] | 53 | ] |
54 | funVerifiers = [ verifyFun "test" ("cav" `isPrefixOf`) (many' letter_ascii) | ||
55 | , verifyFun "value" (<= 43) decimal | ||
56 | ] | ||
53 | 57 | ||
54 | {- | 58 | {- |
55 | - Tests | 59 | - Tests |
@@ -73,15 +77,17 @@ one = testCase "Macaroon with one caveat" $ | |||
73 | two = testCase "Macaroon with two caveats" $ | 77 | two = testCase "Macaroon with two caveats" $ |
74 | Ok @=? verifySig sec m3 | 78 | Ok @=? verifySig sec m3 |
75 | 79 | ||
76 | exactCavs = testGroup "Exact Caveats" [ zero', one', two' , one'', two''] | 80 | exactCavs = testGroup "Exact Caveats" [ |
77 | 81 | testGroup "Ignoring non-relevant" [ | |
78 | zero' = testCase "Zero caveat win" $ | 82 | testCase "Zero caveat" $ Ok @=? verifyCavs exVerifiers m |
79 | Ok @=? verifyCavs exVerifiers m | 83 | , testCase "One caveat" $ Ok @=? verifyCavs exVerifiers' m2 |
80 | one' = testCase "One caveat win" $ | 84 | ] |
81 | Ok @=? verifyCavs exVerifiers m2 | 85 | , testCase "One caveat win" $ Ok @=? verifyCavs exVerifiers m2 |
82 | one'' = testCase "Ignoring non-relevant" $ | 86 | , testCase "Two caveat win" $ Ok @=? verifyCavs exVerifiers m3 |
83 | Ok @=? verifyCavs exVerifiers' m2 | 87 | , testCase "Two caveat fail" $ Failed @=? verifyCavs exVerifiers' m3 |
84 | two' = testCase "Two caveat win" $ | 88 | ] |
85 | Ok @=? verifyCavs exVerifiers m3 | 89 | |
86 | two'' = testCase "Two caveat fail" $ | 90 | funCavs = testGroup "Function Caveats" [ |
87 | Failed @=? verifyCavs exVerifiers' m3 | 91 | testCase "One caveat win" $ Ok @=? verifyCavs funVerifiers m2 |
92 | , testCase "Two caveat win" $ Ok @=? verifyCavs funVerifiers m3 | ||
93 | ] | ||