From b92e3c159fad49b86fe4bd115f487057c04e3c18 Mon Sep 17 00:00:00 2001 From: Julien Tanguy Date: Thu, 14 May 2015 19:00:50 +0200 Subject: Basic verification of macaroons - Only signatures are checked --- test/Crypto/Macaroon/Verifier/Tests.hs | 59 ++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 test/Crypto/Macaroon/Verifier/Tests.hs (limited to 'test/Crypto/Macaroon/Verifier') diff --git a/test/Crypto/Macaroon/Verifier/Tests.hs b/test/Crypto/Macaroon/Verifier/Tests.hs new file mode 100644 index 0000000..92a8a21 --- /dev/null +++ b/test/Crypto/Macaroon/Verifier/Tests.hs @@ -0,0 +1,59 @@ +{-# LANGUAGE OverloadedStrings #-} +{-| +Copyright : (c) 2015 Julien Tanguy +License : BSD3 + +Maintainer : julien.tanguy@jhome.fr + + +This test suite is based on the pymacaroons test suite: + +-} +module Crypto.Macaroon.Verifier.Tests where + + +import qualified Data.ByteString.Char8 as B8 +import Test.Tasty +import Test.Tasty.HUnit + +import Crypto.Macaroon +import Crypto.Macaroon.Verifier + +import Crypto.Macaroon.Instances + +tests :: TestTree +tests = testGroup "Crypto.Macaroon.Verifier" [ sigs + ] + +sec = B8.pack "this is our super secret key; only we should know it" + +m :: Macaroon +m = create sec key loc + where + key = B8.pack "we used our sec key" + loc = B8.pack "http://mybank/" + +m2 :: Macaroon +m2 = addFirstPartyCaveat "test = caveat" m + +m3 :: Macaroon +m3 = addFirstPartyCaveat "test = acaveat" m + +sigs = testGroup "Signatures" [ basic + , minted + ] + +basic = testCase "Basic Macaroon Signature" $ + Success @=? verifySig sec m + + +minted :: TestTree +minted = testGroup "Macaroon with first party caveats" [ one + , two + ] +one = testCase "One caveat" $ + Success @=? verifySig sec m2 + +two = testCase "Two caveats" $ + Success @=? verifySig sec m3 + -- cgit v1.2.3