]> git.immae.eu Git - github/fretlink/hmacaroons.git/blame - test/Sanity.hs
Extract sanity check
[github/fretlink/hmacaroons.git] / test / Sanity.hs
CommitLineData
f6781456 1{-#LANGUAGE OverloadedStrings#-}
46af385c 2module Sanity where
f6781456
JT
3
4import Crypto.Hash
5import Data.ByteString (ByteString)
6import qualified Data.ByteString as B
7import Data.Hex
8import Data.Byteable
9
10import Test.Tasty
11import Test.Tasty.HUnit
12
13import qualified Crypto.Macaroon.Tests
b1f77d7e 14import qualified Crypto.Macaroon.Serializer.Base64.Tests
f6781456 15
f6781456 16tests :: TestTree
46af385c 17tests = testGroup "Python HMAC Sanity check" [ checkKey
f6781456
JT
18 , checkMac1
19 , checkMac2
20 , checkMac3
21 , checkMac4
22 ]
23
24
25secret :: ByteString
26secret = "this is our super secret key; only we should know it"
27
28public :: ByteString
29public = "we used our secret key"
30
31key :: ByteString
32key = B.take 32 secret
33
34mac1 :: ByteString
46af385c 35mac1 = toBytes (hmac key public :: HMAC SHA256)
f6781456
JT
36
37mac2 :: ByteString
46af385c 38mac2 = toBytes (hmac mac1 "account = 3735928559" :: HMAC SHA256)
f6781456
JT
39
40mac3 :: ByteString
46af385c 41mac3 = toBytes (hmac mac2 "time < 2015-01-01T00:00" :: HMAC SHA256)
f6781456
JT
42
43mac4 :: ByteString
46af385c 44mac4 = toBytes (hmac mac3 "email = alice@example.org" :: HMAC SHA256)
f6781456
JT
45
46
47checkKey = testCase "Truncated key" $
48 key @?= "this is our super secret key; on"
49
50checkMac1 = testCase "HMAC key" $
51 "C60B4B3540BB1B2F2EF28D1C895691CC4A5E07A38A9D3B1C3379FB485293372F" @=? hex mac1
52
53checkMac2 = testCase "HMAC key account" $
54 "5C933DC9A7D036DFCD1740B4F26D737397A1FF635EAC900F3226973503CAAAA5" @=? hex mac2
55
56checkMac3 = testCase "HMAC key account time" $
57 "7A559B20C8B607009EBCE138C200585E9D0DECA6D23B3EAD6C5E0BA6861D3858" @=? hex mac3
58
59checkMac4 = testCase "HMAC key account time email" $
60 "E42BBB02A9A5A303483CB6295C497AE51AD1D5CB10003CBE548D907E7E62F5E4" @=? hex mac4
61