From fd6ebe2862ede40939619fcd76557f214e6859cd Mon Sep 17 00:00:00 2001 From: Mateusz Galazyn Date: Tue, 24 Oct 2023 19:34:26 +0200 Subject: [PATCH] #213 Add check for keys permissions in the test in governance drep key-gen Update cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/DRep.hs Co-authored-by: carlhammann <102371507+carlhammann@users.noreply.github.com> --- cardano-cli/cardano-cli.cabal | 1 + .../Test/Golden/Governance/DRep.hs | 26 ++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/cardano-cli/cardano-cli.cabal b/cardano-cli/cardano-cli.cabal index 718b466cd0..6fc157010d 100644 --- a/cardano-cli/cardano-cli.cabal +++ b/cardano-cli/cardano-cli.cabal @@ -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 diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/DRep.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/DRep.hs index 380380c44e..44db5fe6eb 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/DRep.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/DRep.hs @@ -1,8 +1,20 @@ +{-# 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 Numeric (showOct) +import System.Posix.Files (fileMode, getFileStatus) +#endif import Test.Cardano.CLI.Util (execCardanoCLI, noteInputFile, noteTempFile, propertyOnce) @@ -30,6 +42,18 @@ hprop_golden_governanceDRepKeyGen = H.assertFileOccurences 1 "Delegate Representative Verification Key" verificationKeyFile H.assertFileOccurences 1 "Delegate Representative Signing Key" signingKeyFile +#ifdef UNIX + vrfMode <- retrievePermissions verificationKeyFile + sgnMode <- retrievePermissions signingKeyFile + + 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