From d2e7446c0adc2394891c91660c6cff6063a76975 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 --- cardano-cli/cardano-cli.cabal | 1 + .../Test/Golden/Governance/DRep.hs | 28 ++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/cardano-cli/cardano-cli.cabal b/cardano-cli/cardano-cli.cabal index 615542140d..ddfd9a10ec 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..66eb17e9f3 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,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) @@ -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