diff options
author | Julien Tanguy <julien.tanguy@jhome.fr> | 2015-08-17 17:38:24 +0200 |
---|---|---|
committer | Julien Tanguy <julien.tanguy@jhome.fr> | 2015-08-17 17:39:31 +0200 |
commit | 86f3882318d323d1920ca1c7da6e816f0ed376da (patch) | |
tree | 0e16232125c2fb6c0413d654e6b1537c9813b301 /test | |
parent | bf31e29028a4402ea0d2deefdb3b86efd526acd0 (diff) | |
download | hmacaroons-86f3882318d323d1920ca1c7da6e816f0ed376da.tar.gz hmacaroons-86f3882318d323d1920ca1c7da6e816f0ed376da.tar.zst hmacaroons-86f3882318d323d1920ca1c7da6e816f0ed376da.zip |
Change verifier api and split Verifier module
- Added haddocks
Diffstat (limited to 'test')
-rw-r--r-- | test/Crypto/Macaroon/Instances.hs | 6 | ||||
-rw-r--r-- | test/Crypto/Macaroon/Verifier/Internal/Tests.hs | 30 | ||||
-rw-r--r-- | test/Crypto/Macaroon/Verifier/Tests.hs | 28 | ||||
-rw-r--r-- | test/main.hs | 10 |
4 files changed, 46 insertions, 28 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 | ||
35 | newtype Secret = Secret { unSecret :: BS.ByteString } deriving (Show) | 35 | newtype BSSecret = BSSecret { unSecret :: BS.ByteString } deriving (Show) |
36 | 36 | ||
37 | instance Arbitrary Secret where | 37 | instance Arbitrary BSSecret where |
38 | arbitrary = Secret . B8.pack <$> scale (*3) arbitrary | 38 | arbitrary = BSSecret . B8.pack <$> scale (*3) arbitrary |
39 | 39 | ||
40 | newtype Identifier = Identifier { unIdent :: BS.ByteString } deriving (Show) | 40 | newtype 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 | {-| | ||
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.Verifier.Internal.Tests where | ||
13 | |||
14 | import qualified Data.ByteString.Char8 as B8 | ||
15 | import Data.List | ||
16 | import Test.Tasty | ||
17 | -- import Test.Tasty.HUnit | ||
18 | import Data.Either | ||
19 | import Test.Tasty.QuickCheck hiding (Failure, Success) | ||
20 | |||
21 | import Crypto.Macaroon | ||
22 | import Crypto.Macaroon.Verifier.Internal | ||
23 | |||
24 | import Crypto.Macaroon.Instances | ||
25 | |||
26 | tests :: TestTree | ||
27 | tests = testGroup "Crypto.Macaroon.Verifier.Internal" [ sigs | ||
28 | ] | ||
29 | |||
30 | sigs = 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: | |||
12 | module Crypto.Macaroon.Verifier.Tests where | 12 | module Crypto.Macaroon.Verifier.Tests where |
13 | 13 | ||
14 | 14 | ||
15 | import Data.List | 15 | import qualified Data.ByteString.Char8 as B8 |
16 | import qualified Data.ByteString.Char8 as B8 | 16 | import Data.List |
17 | import Test.Tasty | 17 | import Test.Tasty |
18 | -- import Test.Tasty.HUnit | 18 | -- import Test.Tasty.HUnit |
19 | import Test.Tasty.QuickCheck hiding (Success, Failure) | 19 | import Data.Either |
20 | import Data.Either | 20 | import Test.Tasty.QuickCheck hiding (Failure, Success) |
21 | 21 | ||
22 | import Crypto.Macaroon | 22 | import Crypto.Macaroon |
23 | import Crypto.Macaroon.Verifier | 23 | import Crypto.Macaroon.Verifier |
24 | 24 | ||
25 | import Crypto.Macaroon.Instances | 25 | import Crypto.Macaroon.Instances |
26 | 26 | ||
27 | tests :: TestTree | 27 | tests :: TestTree |
28 | tests = testGroup "Crypto.Macaroon.Verifier" [ sigs | 28 | tests = testGroup "Crypto.Macaroon.Verifier" [ ] |
29 | ] | ||
30 | 29 | ||
31 | {- | 30 | {- |
32 | - Test fixtures | 31 | - Test fixtures |
@@ -45,22 +44,9 @@ m2 = addFirstPartyCaveat "test = caveat" m | |||
45 | m3 :: Macaroon | 44 | m3 :: Macaroon |
46 | m3 = addFirstPartyCaveat "value = 42" m2 | 45 | m3 = 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 | -} |
63 | sigs = 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 | {- |
diff --git a/test/main.hs b/test/main.hs index 3edbe54..67ebcd5 100644 --- a/test/main.hs +++ b/test/main.hs | |||
@@ -1,12 +1,13 @@ | |||
1 | module Main where | 1 | module Main where |
2 | 2 | ||
3 | import Test.Tasty | 3 | import Test.Tasty |
4 | import Test.Tasty.HUnit | 4 | import Test.Tasty.HUnit |
5 | 5 | ||
6 | import qualified Sanity | ||
7 | import qualified Crypto.Macaroon.Tests | ||
8 | import qualified Crypto.Macaroon.Serializer.Base64.Tests | 6 | import qualified Crypto.Macaroon.Serializer.Base64.Tests |
7 | import qualified Crypto.Macaroon.Tests | ||
8 | import qualified Crypto.Macaroon.Verifier.Internal.Tests | ||
9 | import qualified Crypto.Macaroon.Verifier.Tests | 9 | import qualified Crypto.Macaroon.Verifier.Tests |
10 | import qualified Sanity | ||
10 | 11 | ||
11 | main = defaultMain tests | 12 | main = defaultMain tests |
12 | 13 | ||
@@ -15,5 +16,6 @@ tests = testGroup "Tests" [ Sanity.tests | |||
15 | , Crypto.Macaroon.Tests.tests | 16 | , Crypto.Macaroon.Tests.tests |
16 | , Crypto.Macaroon.Serializer.Base64.Tests.tests | 17 | , Crypto.Macaroon.Serializer.Base64.Tests.tests |
17 | , Crypto.Macaroon.Verifier.Tests.tests | 18 | , Crypto.Macaroon.Verifier.Tests.tests |
19 | , Crypto.Macaroon.Verifier.Internal.Tests.tests | ||
18 | ] | 20 | ] |
19 | 21 | ||