aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/tests.hs
diff options
context:
space:
mode:
authorJulien Tanguy <julien.tanguy@jhome.fr>2015-04-09 01:12:36 +0200
committerJulien Tanguy <julien.tanguy@jhome.fr>2015-04-09 01:12:36 +0200
commitf678145637ba6f42c36d07c19f8c764e5d537f72 (patch)
tree3e8578900501968de7404131a89e8e063dd0f12e /test/tests.hs
downloadhmacaroons-f678145637ba6f42c36d07c19f8c764e5d537f72.tar.gz
hmacaroons-f678145637ba6f42c36d07c19f8c764e5d537f72.tar.zst
hmacaroons-f678145637ba6f42c36d07c19f8c764e5d537f72.zip
Initial commit
Diffstat (limited to 'test/tests.hs')
-rw-r--r--test/tests.hs66
1 files changed, 66 insertions, 0 deletions
diff --git a/test/tests.hs b/test/tests.hs
new file mode 100644
index 0000000..ba5dafd
--- /dev/null
+++ b/test/tests.hs
@@ -0,0 +1,66 @@
1{-#LANGUAGE OverloadedStrings#-}
2
3import Crypto.Hash
4import Data.ByteString (ByteString)
5import qualified Data.ByteString as B
6import Data.Hex
7import Data.Byteable
8
9import Test.Tasty
10import Test.Tasty.HUnit
11
12import qualified Crypto.Macaroon.Tests
13
14main = defaultMain tests
15
16tests :: TestTree
17tests = testGroup "Tests" [ sanityCheck
18 , Crypto.Macaroon.Tests.tests
19 ]
20
21sanityCheck :: TestTree
22sanityCheck = testGroup "Python HMAC Sanity check" [ checkKey
23 , checkMac1
24 , checkMac2
25 , checkMac3
26 , checkMac4
27 ]
28
29
30secret :: ByteString
31secret = "this is our super secret key; only we should know it"
32
33public :: ByteString
34public = "we used our secret key"
35
36key :: ByteString
37key = B.take 32 secret
38
39mac1 :: ByteString
40mac1 = toBytes $ (hmac key public :: HMAC SHA256)
41
42mac2 :: ByteString
43mac2 = toBytes $ (hmac mac1 "account = 3735928559" :: HMAC SHA256)
44
45mac3 :: ByteString
46mac3 = toBytes $ (hmac mac2 "time < 2015-01-01T00:00" :: HMAC SHA256)
47
48mac4 :: ByteString
49mac4 = toBytes $ (hmac mac3 "email = alice@example.org" :: HMAC SHA256)
50
51
52checkKey = testCase "Truncated key" $
53 key @?= "this is our super secret key; on"
54
55checkMac1 = testCase "HMAC key" $
56 "C60B4B3540BB1B2F2EF28D1C895691CC4A5E07A38A9D3B1C3379FB485293372F" @=? hex mac1
57
58checkMac2 = testCase "HMAC key account" $
59 "5C933DC9A7D036DFCD1740B4F26D737397A1FF635EAC900F3226973503CAAAA5" @=? hex mac2
60
61checkMac3 = testCase "HMAC key account time" $
62 "7A559B20C8B607009EBCE138C200585E9D0DECA6D23B3EAD6C5E0BA6861D3858" @=? hex mac3
63
64checkMac4 = testCase "HMAC key account time email" $
65 "E42BBB02A9A5A303483CB6295C497AE51AD1D5CB10003CBE548D907E7E62F5E4" @=? hex mac4
66