diff --git a/cardano-api/cardano-api.cabal b/cardano-api/cardano-api.cabal index 029bc96ffc..e1c2c95065 100644 --- a/cardano-api/cardano-api.cabal +++ b/cardano-api/cardano-api.cabal @@ -1,7 +1,7 @@ cabal-version: 3.4 name: cardano-api -version: 8.10.0.0 +version: 8.10.1.0 synopsis: The cardano api description: The cardano api. category: Cardano, @@ -196,11 +196,11 @@ library Cardano.Api.ChainSync.ClientPipelined Cardano.Api.Crypto.Ed25519Bip32 Cardano.Api.Shelley - -- TODO: Eliminate Cardano.Api.Ledger when - -- cardano-api only depends on modules - -- exposed by cardano-api-ledger - Cardano.Api.Ledger - + -- TODO: Eliminate Cardano.Api.Ledger when + -- cardano-api only depends on modules + -- exposed by cardano-api-ledger + Cardano.Api.Ledger + build-depends: bytestring , cardano-api:internal @@ -268,7 +268,9 @@ test-suite cardano-api-test , cardano-ledger-api >= 1.3 , cardano-ledger-core:{cardano-ledger-core, testlib} >= 1.4 , containers + , directory , hedgehog >= 1.1 + , hedgehog-extras , hedgehog-quickcheck , mtl , QuickCheck @@ -278,6 +280,7 @@ test-suite cardano-api-test other-modules: Test.Cardano.Api.Crypto Test.Cardano.Api.Eras + Test.Cardano.Api.IO Test.Cardano.Api.Json Test.Cardano.Api.KeysByron Test.Cardano.Api.Ledger diff --git a/cardano-api/internal/Cardano/Api/IO/Compat/Posix.hs b/cardano-api/internal/Cardano/Api/IO/Compat/Posix.hs index 2df1a73917..a95f4a897b 100644 --- a/cardano-api/internal/Cardano/Api/IO/Compat/Posix.hs +++ b/cardano-api/internal/Cardano/Api/IO/Compat/Posix.hs @@ -17,22 +17,22 @@ module Cardano.Api.IO.Compat.Posix #ifdef UNIX -import Cardano.Api.Error (FileError (..), fileIOExceptT) +import Cardano.Api.Error (FileError (..)) import Cardano.Api.IO.Base import Control.Exception (IOException, bracket, bracketOnError, try) import Control.Monad (forM_, when) import Control.Monad.Except (ExceptT, runExceptT) import Control.Monad.IO.Class -import Control.Monad.Trans.Except.Extra (left) +import Control.Monad.Trans.Except.Extra (handleIOExceptT, left) import qualified Data.ByteString as BS import System.Directory () import System.FilePath ((</>)) import qualified System.IO as IO import System.IO (Handle) import System.Posix.Files (fileMode, getFileStatus, groupModes, intersectFileModes, - nullFileMode, otherModes, ownerReadMode, setFdOwnerAndGroup, setFileMode, - stdFileMode) + nullFileMode, otherModes, ownerModes, ownerReadMode, setFdOwnerAndGroup, + setFileMode, stdFileMode) # if MIN_VERSION_unix(2,8,0) import System.Posix.IO (OpenFileFlags (..), OpenMode (..), closeFd, defaultFileFlags, fdToHandle, openFd) @@ -67,7 +67,7 @@ handleFileForWritingWithOwnerPermissionImpl path f = do bracket (fdToHandle fd) IO.hClose - (runExceptT . fileIOExceptT path . const . f) + (runExceptT . handleIOExceptT (FileIOError path) . f) writeSecretsImpl :: FilePath -> [Char] -> [Char] -> (a -> BS.ByteString) -> [a] -> IO () writeSecretsImpl outDir prefix suffix secretOp xs = @@ -112,7 +112,7 @@ openFileDescriptor fp openMode = ReadWrite -> defaultFileFlags { creat = Just stdFileMode } WriteOnly -> - defaultFileFlags { creat = Just stdFileMode } + defaultFileFlags { creat = Just ownerModes } # else openFileDescriptor fp openMode = @@ -129,7 +129,7 @@ openFileDescriptor fp openMode = , defaultFileFlags ) WriteOnly -> - ( Just stdFileMode + ( Just ownerModes , defaultFileFlags ) # endif diff --git a/cardano-api/test/cardano-api-test/Test/Cardano/Api/IO.hs b/cardano-api/test/cardano-api-test/Test/Cardano/Api/IO.hs new file mode 100644 index 0000000000..9c6994c8b6 --- /dev/null +++ b/cardano-api/test/cardano-api-test/Test/Cardano/Api/IO.hs @@ -0,0 +1,40 @@ +{-# LANGUAGE TypeApplications #-} + +module Test.Cardano.Api.IO + ( tests + ) where + +import Cardano.Api +import Cardano.Api.IO + +import Control.Monad.Except (runExceptT) +import Control.Monad.IO.Class (liftIO) +import System.Directory (removeFile) + +import Hedgehog +import qualified Hedgehog.Extras as H +import Hedgehog.Internal.Property +import Test.Tasty (TestTree, testGroup) +import Test.Tasty.Hedgehog + +prop_createVrfFileWithOwnerPermissions :: Property +prop_createVrfFileWithOwnerPermissions = + H.propertyOnce . H.moduleWorkspace "help" $ \ws -> do + file <- H.noteTempFile ws "file" + + result <- liftIO $ writeLazyByteStringFileWithOwnerPermissions (File file) "" + + case result of + Left err -> failWith Nothing $ displayError @(FileError ()) err + Right () -> return () + + fResult <- liftIO . runExceptT $ checkVrfFilePermissions (File file) + + case fResult of + Left err -> failWith Nothing $ show err + Right () -> liftIO (removeFile file) >> success + +tests :: TestTree +tests = testGroup "Test.Cardano.Api.IO" + [ testProperty "Create VRF File with Owner Permissions" prop_createVrfFileWithOwnerPermissions + ] diff --git a/cardano-api/test/cardano-api-test/cardano-api-test.hs b/cardano-api/test/cardano-api-test/cardano-api-test.hs index 8e9db7ade1..0946866b1c 100644 --- a/cardano-api/test/cardano-api-test/cardano-api-test.hs +++ b/cardano-api/test/cardano-api-test/cardano-api-test.hs @@ -6,6 +6,7 @@ import System.IO (BufferMode (LineBuffering), hSetBuffering, hSetEncod import qualified Test.Cardano.Api.Crypto import qualified Test.Cardano.Api.Eras +import qualified Test.Cardano.Api.IO import qualified Test.Cardano.Api.Json import qualified Test.Cardano.Api.KeysByron import qualified Test.Cardano.Api.Ledger @@ -35,6 +36,7 @@ tests = testGroup "Cardano.Api" [ Test.Cardano.Api.Crypto.tests , Test.Cardano.Api.Eras.tests + , Test.Cardano.Api.IO.tests , Test.Cardano.Api.Json.tests , Test.Cardano.Api.KeysByron.tests , Test.Cardano.Api.Ledger.tests