Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: update samples #90

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 49 additions & 23 deletions biscuit/test/Spec/SampleReader.hs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeApplications #-}
module Spec.SampleReader where

import Control.Arrow ((&&&))
Expand All @@ -31,6 +34,7 @@ import Data.Text (Text, pack, unpack)
import Data.Text.Encoding (decodeUtf8, encodeUtf8)
import Data.Traversable (for)
import GHC.Generics (Generic)
import GHC.Records (HasField(getField))

import Test.Tasty hiding (Timeout)
import Test.Tasty.HUnit
Expand Down Expand Up @@ -151,21 +155,45 @@ data BlockDesc
deriving stock (Eq, Show, Generic)
deriving anyclass (FromJSON, ToJSON)

data FactSet
= FactSet
{ origin :: [Maybe Integer]
, facts :: [Text]
}
deriving stock (Eq, Show, Generic)
deriving anyclass (FromJSON, ToJSON)

data RuleSet
= RuleSet
{ origin :: Maybe Integer
, rules :: [Text]
}
deriving stock (Eq, Show, Generic)
deriving anyclass (FromJSON, ToJSON)

data CheckSet
= CheckSet
{ origin :: Maybe Integer
, checks :: [Text]
}
deriving stock (Eq, Show, Generic)
deriving anyclass (FromJSON, ToJSON)

data WorldDesc
= WorldDesc
{ facts :: [Text]
, rules :: [Text]
, checks :: [Text]
{ facts :: [FactSet]
, rules :: [RuleSet]
, checks :: [CheckSet]
, policies :: [Text]
}
deriving stock (Eq, Show, Generic)
deriving anyclass (FromJSON, ToJSON)

instance Semigroup WorldDesc where
a <> b = WorldDesc
{ facts = facts a <> facts b
, rules = rules a <> rules b
, checks = checks a <> checks b
{ facts = getField @"facts" a <> getField @"facts" b
, rules = getField @"rules" a <> getField @"rules" b
, checks = getField @"checks" a <> getField @"checks" b
, policies = policies a <> policies b
}

Expand Down Expand Up @@ -198,6 +226,9 @@ processTestCase step rootPk TestCase{..} =
if fst filename == "test018_unbound_variables_in_rule.bc"
then
step "Skipping for now (unbound variables are now caught before evaluation)"
else if fst filename == "test027_integer_wraparound.bc"
then
step "Skipping for now (evaluation fails silently)"
else do
step "Parsing "
let vList = Map.toList validations
Expand Down Expand Up @@ -307,12 +338,7 @@ mkTestCaseFromBiscuit title filename biscuit authorizers = do
mkValidation authorizer = do
Right success <- authorizeBiscuit biscuit authorizer
pure ValidationR
{ world = Just $ WorldDesc
{ facts = []
, rules = []
, checks = []
, policies = []
}
{ world = Just mempty
, result = Ok 0
, authorizer_code = authorizer
, revocation_ids = encodeHex <$> toList (getRevocationIds biscuit)
Expand Down
Loading
Loading