]>
Commit | Line | Data |
---|---|---|
b92e3c15 JT |
1 | {-# LANGUAGE OverloadedStrings #-} |
2 | {-| | |
3 | Copyright : (c) 2015 Julien Tanguy | |
4 | License : BSD3 | |
5 | ||
6 | Maintainer : julien.tanguy@jhome.fr | |
7 | ||
8 | ||
9 | This test suite is based on the pymacaroons test suite: | |
10 | <https://github.com/ecordell/pymacaroons> | |
11 | -} | |
12 | module Crypto.Macaroon.Verifier.Tests where | |
13 | ||
14 | ||
15 | import qualified Data.ByteString.Char8 as B8 | |
16 | import Test.Tasty | |
17 | import Test.Tasty.HUnit | |
5d1b7d51 | 18 | import Test.Tasty.QuickCheck |
b92e3c15 JT |
19 | |
20 | import Crypto.Macaroon | |
21 | import Crypto.Macaroon.Verifier | |
22 | ||
23 | import Crypto.Macaroon.Instances | |
24 | ||
25 | tests :: TestTree | |
26 | tests = testGroup "Crypto.Macaroon.Verifier" [ sigs | |
27 | ] | |
28 | ||
5d1b7d51 JT |
29 | {- |
30 | - Test fixtures | |
31 | -} | |
b92e3c15 JT |
32 | sec = B8.pack "this is our super secret key; only we should know it" |
33 | ||
34 | m :: Macaroon | |
35 | m = create sec key loc | |
36 | where | |
37 | key = B8.pack "we used our sec key" | |
38 | loc = B8.pack "http://mybank/" | |
39 | ||
40 | m2 :: Macaroon | |
41 | m2 = addFirstPartyCaveat "test = caveat" m | |
42 | ||
43 | m3 :: Macaroon | |
44 | m3 = addFirstPartyCaveat "test = acaveat" m | |
45 | ||
5d1b7d51 JT |
46 | {- |
47 | - Tests | |
48 | -} | |
b92e3c15 | 49 | sigs = testGroup "Signatures" [ basic |
5d1b7d51 JT |
50 | , one |
51 | , two | |
b92e3c15 JT |
52 | ] |
53 | ||
5d1b7d51 | 54 | basic = testGroup "Basic Macaroon" [ none , sigQC ] |
b92e3c15 | 55 | |
5d1b7d51 JT |
56 | none = testCase "No caveat" $ |
57 | VSuccess @=? verifySig sec m | |
b92e3c15 | 58 | |
5d1b7d51 JT |
59 | sigQC = testProperty "Random" $ |
60 | \sm -> verifySig (secret sm) (macaroon sm) == VSuccess | |
b92e3c15 | 61 | |
5d1b7d51 JT |
62 | one = testCase "Macaroon with one caveat" $ |
63 | VSuccess @=? verifySig sec m2 | |
64 | ||
65 | two = testCase "Macaroon with two caveats" $ | |
66 | VSuccess @=? verifySig sec m3 | |
b92e3c15 | 67 |