From c830f7c2cf925ce340f4097d76ea2a3bc94cb4a6 Mon Sep 17 00:00:00 2001 From: Julien Tanguy Date: Wed, 8 Jul 2015 18:13:14 +0200 Subject: Rewrite Verifier with Validation --- test/Crypto/Macaroon/Verifier/Tests.hs | 59 ++++++++-------------------------- 1 file changed, 14 insertions(+), 45 deletions(-) (limited to 'test/Crypto/Macaroon') diff --git a/test/Crypto/Macaroon/Verifier/Tests.hs b/test/Crypto/Macaroon/Verifier/Tests.hs index 101fa26..4a9295f 100644 --- a/test/Crypto/Macaroon/Verifier/Tests.hs +++ b/test/Crypto/Macaroon/Verifier/Tests.hs @@ -16,7 +16,8 @@ import Data.List import qualified Data.ByteString.Char8 as B8 import Test.Tasty -- import Test.Tasty.HUnit -import Test.Tasty.QuickCheck +import Test.Tasty.QuickCheck hiding (Success, Failure) +import Data.Either import Crypto.Macaroon import Crypto.Macaroon.Verifier @@ -25,7 +26,6 @@ import Crypto.Macaroon.Instances tests :: TestTree tests = testGroup "Crypto.Macaroon.Verifier" [ sigs - , firstParty ] {- @@ -45,52 +45,21 @@ m2 = addFirstPartyCaveat "test = caveat" m m3 :: Macaroon m3 = addFirstPartyCaveat "value = 42" m2 -exTC = verifyExact "test" "caveat" (many' letter_ascii) "test = caveat" -exTZ = verifyExact "test" "bleh" (many' letter_ascii) "test = bleh" -exV42 = verifyExact "value" 42 decimal "value = 42" -exV43 = verifyExact "value" 43 decimal "value = 43" +-- exTC = verifyExact "test" "caveat" (many' letter_ascii) +-- exTZ = verifyExact "test" "bleh" (many' letter_ascii) +-- exV42 = verifyExact "value" 42 decimal +-- exV43 = verifyExact "value" 43 decimal -funTCPre = verifyFun "test" ("cav" `isPrefixOf`) (many' letter_ascii) "test startsWith cav" -funTV43lte = verifyFun "value" (<= 43) decimal "value <= 43" +-- funTCPre = verifyFun "test" (string "test = " *> many' letter_ascii) +-- (\e -> if "cav" `isPrefixOf` e then Right e else Left "Does not start with cav" ) +-- funTV43lte = verifyFun "value" (string "value = " *> decimal) +-- (\v -> if v <= 43 then Right v else Left "Greater than 43") -allvs = [exTC, exTZ, exV42, exV43, funTCPre, funTV43lte] +-- allvs = [exTC, exTZ, exV42, exV43, funTCPre, funTV43lte] {- - Tests -} -sigs = testProperty "Signatures" $ \sm -> verifySig (secret sm) (macaroon sm) == Ok - -firstParty = testGroup "First party caveats" [ - testGroup "Pure verifiers" [ - testProperty "Zero caveat" $ - forAll (sublistOf allvs) (\vs -> Ok == verifyCavs vs m) - , testProperty "One caveat" $ - forAll (sublistOf allvs) (\vs -> disjoin [ - Ok == verifyCavs vs m2 .&&. any (`elem` vs) [exTC,funTCPre] .&&. (exTZ `notElem` vs) - , Failed === verifyCavs vs m2 - ]) - , testProperty "Two Exact" $ - forAll (sublistOf allvs) (\vs -> disjoin [ - Ok == verifyCavs vs m3 .&&. - any (`elem` vs) [exTC,funTCPre] .&&. (exTZ `notElem` vs) .&&. - any (`elem` vs) [exV42,funTV43lte] .&&. (exV43 `notElem` vs) - , Failed === verifyCavs vs m3 - ]) - ] - , testGroup "Pure verifiers with sig" [ - testProperty "Zero caveat" $ - forAll (sublistOf allvs) (\vs -> Ok == verifyMacaroon sec vs m) - , testProperty "One caveat" $ - forAll (sublistOf allvs) (\vs -> disjoin [ - Ok == verifyMacaroon sec vs m2 .&&. any (`elem` vs) [exTC,funTCPre] .&&. (exTZ `notElem` vs) - , Failed === verifyMacaroon sec vs m2 - ]) - , testProperty "Two Exact" $ - forAll (sublistOf allvs) (\vs -> disjoin [ - Ok == verifyMacaroon sec vs m3 .&&. - any (`elem` vs) [exTC,funTCPre] .&&. (exTZ `notElem` vs) .&&. - any (`elem` vs) [exV42,funTV43lte] .&&. (exV43 `notElem` vs) - , Failed === verifyMacaroon sec vs m3 - ]) - ] - ] +sigs = testProperty "Signatures" $ \sm -> verifySig (secret sm) (macaroon sm) == Right (macaroon sm) + +-- TODO: Re-do tests -- cgit v1.2.3