aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/Crypto/Macaroon
diff options
context:
space:
mode:
authorJulien Tanguy <julien.tanguy@jhome.fr>2015-08-17 17:38:24 +0200
committerJulien Tanguy <julien.tanguy@jhome.fr>2015-08-17 17:39:31 +0200
commit86f3882318d323d1920ca1c7da6e816f0ed376da (patch)
tree0e16232125c2fb6c0413d654e6b1537c9813b301 /test/Crypto/Macaroon
parentbf31e29028a4402ea0d2deefdb3b86efd526acd0 (diff)
downloadhmacaroons-86f3882318d323d1920ca1c7da6e816f0ed376da.tar.gz
hmacaroons-86f3882318d323d1920ca1c7da6e816f0ed376da.tar.zst
hmacaroons-86f3882318d323d1920ca1c7da6e816f0ed376da.zip
Change verifier api and split Verifier module
- Added haddocks
Diffstat (limited to 'test/Crypto/Macaroon')
-rw-r--r--test/Crypto/Macaroon/Instances.hs6
-rw-r--r--test/Crypto/Macaroon/Verifier/Internal/Tests.hs30
-rw-r--r--test/Crypto/Macaroon/Verifier/Tests.hs28
3 files changed, 40 insertions, 24 deletions
diff --git a/test/Crypto/Macaroon/Instances.hs b/test/Crypto/Macaroon/Instances.hs
index 9c89857..6348c56 100644
--- a/test/Crypto/Macaroon/Instances.hs
+++ b/test/Crypto/Macaroon/Instances.hs
@@ -32,10 +32,10 @@ instance Arbitrary Url where
32 domain <- elements [".com",".net"] 32 domain <- elements [".com",".net"]
33 return . Url . B8.pack $ (protocol ++ name ++ domain) 33 return . Url . B8.pack $ (protocol ++ name ++ domain)
34 34
35newtype Secret = Secret { unSecret :: BS.ByteString } deriving (Show) 35newtype BSSecret = BSSecret { unSecret :: BS.ByteString } deriving (Show)
36 36
37instance Arbitrary Secret where 37instance Arbitrary BSSecret where
38 arbitrary = Secret . B8.pack <$> scale (*3) arbitrary 38 arbitrary = BSSecret . B8.pack <$> scale (*3) arbitrary
39 39
40newtype Identifier = Identifier { unIdent :: BS.ByteString } deriving (Show) 40newtype Identifier = Identifier { unIdent :: BS.ByteString } deriving (Show)
41 41
diff --git a/test/Crypto/Macaroon/Verifier/Internal/Tests.hs b/test/Crypto/Macaroon/Verifier/Internal/Tests.hs
new file mode 100644
index 0000000..cd75118
--- /dev/null
+++ b/test/Crypto/Macaroon/Verifier/Internal/Tests.hs
@@ -0,0 +1,30 @@
1{-# LANGUAGE OverloadedStrings #-}
2{-|
3Copyright : (c) 2015 Julien Tanguy
4License : BSD3
5
6Maintainer : julien.tanguy@jhome.fr
7
8
9This test suite is based on the pymacaroons test suite:
10<https://github.com/ecordell/pymacaroons>
11-}
12module Crypto.Macaroon.Verifier.Internal.Tests where
13
14import qualified Data.ByteString.Char8 as B8
15import Data.List
16import Test.Tasty
17-- import Test.Tasty.HUnit
18import Data.Either
19import Test.Tasty.QuickCheck hiding (Failure, Success)
20
21import Crypto.Macaroon
22import Crypto.Macaroon.Verifier.Internal
23
24import Crypto.Macaroon.Instances
25
26tests :: TestTree
27tests = testGroup "Crypto.Macaroon.Verifier.Internal" [ sigs
28 ]
29
30sigs = testProperty "Signatures" $ \sm -> verifySig (secret sm) (macaroon sm) == Right (macaroon sm)
diff --git a/test/Crypto/Macaroon/Verifier/Tests.hs b/test/Crypto/Macaroon/Verifier/Tests.hs
index 670c991..b6220eb 100644
--- a/test/Crypto/Macaroon/Verifier/Tests.hs
+++ b/test/Crypto/Macaroon/Verifier/Tests.hs
@@ -12,21 +12,20 @@ This test suite is based on the pymacaroons test suite:
12module Crypto.Macaroon.Verifier.Tests where 12module Crypto.Macaroon.Verifier.Tests where
13 13
14 14
15import Data.List 15import qualified Data.ByteString.Char8 as B8
16import qualified Data.ByteString.Char8 as B8 16import Data.List
17import Test.Tasty 17import Test.Tasty
18-- import Test.Tasty.HUnit 18-- import Test.Tasty.HUnit
19import Test.Tasty.QuickCheck hiding (Success, Failure) 19import Data.Either
20import Data.Either 20import Test.Tasty.QuickCheck hiding (Failure, Success)
21 21
22import Crypto.Macaroon 22import Crypto.Macaroon
23import Crypto.Macaroon.Verifier 23import Crypto.Macaroon.Verifier
24 24
25import Crypto.Macaroon.Instances 25import Crypto.Macaroon.Instances
26 26
27tests :: TestTree 27tests :: TestTree
28tests = testGroup "Crypto.Macaroon.Verifier" [ sigs 28tests = testGroup "Crypto.Macaroon.Verifier" [ ]
29 ]
30 29
31{- 30{-
32 - Test fixtures 31 - Test fixtures
@@ -45,22 +44,9 @@ m2 = addFirstPartyCaveat "test = caveat" m
45m3 :: Macaroon 44m3 :: Macaroon
46m3 = addFirstPartyCaveat "value = 42" m2 45m3 = addFirstPartyCaveat "value = 42" m2
47 46
48-- exTC = verifyExact "test" "caveat" (many' letter_ascii)
49-- exTZ = verifyExact "test" "bleh" (many' letter_ascii)
50-- exV42 = verifyExact "value" 42 decimal
51-- exV43 = verifyExact "value" 43 decimal
52
53-- funTCPre = verifyFun "test" (string "test = " *> many' letter_ascii)
54-- (\e -> if "cav" `isPrefixOf` e then Right e else Left "Does not start with cav" )
55-- funTV43lte = verifyFun "value" (string "value = " *> decimal)
56-- (\v -> if v <= 43 then Right v else Left "Greater than 43")
57
58-- allvs = [exTC, exTZ, exV42, exV43, funTCPre, funTV43lte]
59
60{- 47{-
61 - Tests 48 - Tests
62 -} 49 -}
63sigs = testProperty "Signatures" $ \sm -> verifySig (secret sm) (macaroon sm) == Right (macaroon sm)
64 50
65-- TODO: Re-do tests 51-- TODO: Re-do tests
66{- 52{-