diff options
author | Julien Tanguy <julien.tanguy@jhome.fr> | 2015-04-09 01:12:36 +0200 |
---|---|---|
committer | Julien Tanguy <julien.tanguy@jhome.fr> | 2015-04-09 01:12:36 +0200 |
commit | f678145637ba6f42c36d07c19f8c764e5d537f72 (patch) | |
tree | 3e8578900501968de7404131a89e8e063dd0f12e /test/Crypto | |
download | hmacaroons-f678145637ba6f42c36d07c19f8c764e5d537f72.tar.gz hmacaroons-f678145637ba6f42c36d07c19f8c764e5d537f72.tar.zst hmacaroons-f678145637ba6f42c36d07c19f8c764e5d537f72.zip |
Initial commit
Diffstat (limited to 'test/Crypto')
-rw-r--r-- | test/Crypto/Macaroon/Tests.hs | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/test/Crypto/Macaroon/Tests.hs b/test/Crypto/Macaroon/Tests.hs new file mode 100644 index 0000000..cdfb620 --- /dev/null +++ b/test/Crypto/Macaroon/Tests.hs | |||
@@ -0,0 +1,74 @@ | |||
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 | |||
22 | tests :: TestTree | ||
23 | tests = testGroup "Crypto.Macaroon" [ basicSignature | ||
24 | , basicSerialize | ||
25 | , basicMint | ||
26 | , basicMintTrimmed | ||
27 | ] | ||
28 | |||
29 | |||
30 | m :: Macaroon | ||
31 | m = create secret key loc | ||
32 | where | ||
33 | secret = B8.pack "this is our super secret key; only we should know it" | ||
34 | key = B8.pack "we used our secret key" | ||
35 | loc = B8.pack "http://mybank/" | ||
36 | |||
37 | m2 :: Macaroon | ||
38 | m2 = addFirstPartyCaveat "test = caveat" m | ||
39 | |||
40 | m3 :: Macaroon | ||
41 | m3 = addFirstPartyCaveat "test = acaveat" m | ||
42 | |||
43 | m4 :: Macaroon | ||
44 | m4 = addThirdPartyCaveat caveat_key caveat_id caveat_loc n | ||
45 | where | ||
46 | n = addFirstPartyCaveat "account = 3735928559" $ create sec key loc | ||
47 | key = B8.pack "we used our other secret key" | ||
48 | loc = B8.pack "http://mybank/" | ||
49 | sec = B8.pack "this is a different super-secret key; never use the same secret twice" | ||
50 | caveat_key = B8.pack "4; guaranteed random by a fair toss of the dice" | ||
51 | caveat_id = B8.pack "this was how we remind auth of key/pred" | ||
52 | caveat_loc = B8.pack "http://auth.mybank/" | ||
53 | |||
54 | |||
55 | basicSignature = testCase "Basic signature" $ | ||
56 | "E3D9E02908526C4C0039AE15114115D97FDD68BF2BA379B342AAF0F617D0552F" @=? (hex . signature) m | ||
57 | |||
58 | basicSerialize = testCase "Serialization" $ | ||
59 | "MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudG\ | ||
60 | \lmaWVyIHdlIHVzZWQgb3VyIHNlY3JldCBrZXkKMDAyZnNpZ25h\ | ||
61 | \dHVyZSDj2eApCFJsTAA5rhURQRXZf91ovyujebNCqvD2F9BVLwo" @=? serialize m | ||
62 | |||
63 | basicMint = testCase "First Party Caveat" $ | ||
64 | "MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudGlmaWVyIHdlIHVzZ\ | ||
65 | \WQgb3VyIHNlY3JldCBrZXkKMDAxNmNpZCB0ZXN0ID0gY2F2ZWF0CjAwMmZzaWduYXR1cmUgGXusegR\ | ||
66 | \K8zMyhluSZuJtSTvdZopmDkTYjOGpmMI9vWcK" @=? serialize m2 | ||
67 | |||
68 | basicMintTrimmed = testCase "Trimmed base64" $ | ||
69 | "MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudGlmaWVyIHdlIHVz\ | ||
70 | \ZWQgb3VyIHNlY3JldCBrZXkKMDAxN2NpZCB0ZXN0ID0gYWNhdmVhdAowMDJmc2ln\ | ||
71 | \bmF0dXJlIJRJ_V3WNJQnqlVq5eez7spnltwU_AXs8NIRY739sHooCg" @=? serialize m3 | ||
72 | |||
73 | basicThirdParty = testCase "Third Party Caveat" $ | ||
74 | "6B99EDB2EC6D7A4382071D7D41A0BF7DFA27D87D2F9FEA86E330D7850FFDA2B2" @=? (hex . signature) m4 | ||