Skip to content

Commit

Permalink
#213 Add check for keys permissions in the test in governance drep ke…
Browse files Browse the repository at this point in the history
…y-gen
  • Loading branch information
carbolymer committed Oct 24, 2023
1 parent 9293cdb commit d2e7446
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ test-suite cardano-cli-test

test-suite cardano-cli-golden
import: project-config
, maybe-unix

hs-source-dirs: test/cardano-cli-golden
main-is: cardano-cli-golden.hs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
{-# LANGUAGE CPP #-}
{- HLINT ignore "Use camelCase" -}

module Test.Golden.Governance.DRep where

import Control.Monad (void)
#if !defined(mingw32_HOST_OS)
#define UNIX
#endif

import Control.Monad

#ifdef UNIX
import Data.Bits ((.&.))
import GHC.Stack (withFrozenCallStack)
import Hedgehog.Extras.Stock (isWin32)
import Numeric (showOct)
import System.Posix.Files (fileMode, getFileStatus)
#endif

import Test.Cardano.CLI.Util (execCardanoCLI, noteInputFile, noteTempFile, propertyOnce)

Expand Down Expand Up @@ -30,6 +43,19 @@ hprop_golden_governanceDRepKeyGen =
H.assertFileOccurences 1 "Delegate Representative Verification Key" verificationKeyFile
H.assertFileOccurences 1 "Delegate Representative Signing Key" signingKeyFile

#ifdef UNIX
unless isWin32 $ do
vrfMode <- retrievePermissions verificationKeyFile
sgnMode <- retrievePermissions verificationKeyFile

vrfMode === "600"
sgnMode === "600"
where
retrievePermissions path = withFrozenCallStack $ do
mode <- H.evalIO $ fileMode <$> getFileStatus path
pure $ showOct (mode .&. 0o777) "" -- we only need the 3 lowest octets here
#endif

hprop_golden_governance_drep_id_bech32 :: Property
hprop_golden_governance_drep_id_bech32 =
propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do
Expand Down

0 comments on commit d2e7446

Please sign in to comment.