]>
Commit | Line | Data |
---|---|---|
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 | |
18 | import Test.Tasty.QuickCheck | |
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 | ||
29 | {- | |
30 | - Test fixtures | |
31 | -} | |
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 | ||
46 | {- | |
47 | - Tests | |
48 | -} | |
49 | sigs = testGroup "Signatures" [ basic | |
50 | , one | |
51 | , two | |
52 | ] | |
53 | ||
54 | basic = testGroup "Basic Macaroon" [ none , sigQC ] | |
55 | ||
56 | none = testCase "No caveat" $ | |
57 | VSuccess @=? verifySig sec m | |
58 | ||
59 | sigQC = testProperty "Random" $ | |
60 | \sm -> verifySig (secret sm) (macaroon sm) == VSuccess | |
61 | ||
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 | |
67 |