]>
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.Tests where | |
13 | ||
14 | import Data.Byteable | |
15 | import qualified Data.ByteString.Char8 as B8 | |
16 | import Data.Hex | |
17 | import Test.Tasty | |
18 | import Test.Tasty.HUnit | |
19 | ||
20 | import Crypto.Macaroon | |
21 | import Crypto.Macaroon.Serializer.Base64 | |
22 | ||
23 | tests :: TestTree | |
24 | tests = testGroup "Crypto.Macaroon" [ basic | |
25 | , minted | |
26 | ] | |
27 | ||
28 | ||
29 | m :: Macaroon | |
30 | m = create secret key loc | |
31 | where | |
32 | secret = B8.pack "this is our super secret key; only we should know it" | |
33 | key = B8.pack "we used our secret key" | |
34 | loc = B8.pack "http://mybank/" | |
35 | ||
36 | basic :: TestTree | |
37 | basic = testGroup "Basic macaroon" [ basicInspect | |
38 | , basicSignature | |
39 | ] | |
40 | ||
41 | basicInspect = testCase "Inspect" $ | |
42 | "location http://mybank/\nidentifier we used\ | |
43 | \ our secret key\n\nsignature E3D9E02908526C4C\ | |
44 | \0039AE15114115D97FDD68BF2BA379B342AAF0F617D0552F" @=? inspect m | |
45 | ||
46 | basicSignature = testCase "Signature" $ | |
47 | "E3D9E02908526C4C0039AE15114115D97FDD68BF2BA379B342AAF0F617D0552F" @=? (hex . signature) m | |
48 | ||
49 | m2 :: Macaroon | |
50 | m2 = addFirstPartyCaveat "test = caveat" m | |
51 | ||
52 | minted :: TestTree | |
53 | minted = testGroup "Macaroon with first party caveat" [ mintInspect | |
54 | , mintSignature | |
55 | ] | |
56 | ||
57 | mintInspect = testCase "Inspect" $ | |
58 | "location http://mybank/\nidentifier we used\ | |
59 | \ our secret key\ncid test = caveat\nsignature\ | |
60 | \ 197BAC7A044AF33332865B9266E26D49\ | |
61 | \3BDD668A660E44D88CE1A998C23DBD67" @=? inspect m2 | |
62 | ||
63 | ||
64 | mintSignature = testCase "Signature" $ | |
65 | "197BAC7A044AF33332865B9266E26D493BDD668A660E44D88CE1A998C23DBD67" @=? (hex . signature) m2 | |
66 | ||
67 | -- m4 :: Macaroon | |
68 | -- m4 = addThirdPartyCaveat caveat_key caveat_id caveat_loc n | |
69 | -- where | |
70 | -- n = addFirstPartyCaveat "account = 3735928559" $ create sec key loc | |
71 | -- key = B8.pack "we used our other secret key" | |
72 | -- loc = B8.pack "http://mybank/" | |
73 | -- sec = B8.pack "this is a different super-secret key; never use the same secret twice" | |
74 | -- caveat_key = B8.pack "4; guaranteed random by a fair toss of the dice" | |
75 | -- caveat_id = B8.pack "this was how we remind auth of key/pred" | |
76 | -- caveat_loc = B8.pack "http://auth.mybank/" | |
77 | ||
78 | -- minted3 :: TestTree | |
79 | -- minted3 = testGroup "Macaroon with first and third party caveats" [ mint3sig ] | |
80 | ||
81 | ||
82 | -- mint3sig = testCase "Signature" $ | |
83 | -- "6B99EDB2EC6D7A4382071D7D41A0BF7DFA27D87D2F9FEA86E330D7850FFDA2B2" @=? (hex . signature) m4 |