Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
|
||
module Test.Cli.FilePermissions | ||
( tests | ||
) where | ||
|
||
import Cardano.Prelude | ||
|
||
import Control.Exception (bracket_) | ||
import System.Directory (removeFile) | ||
import System.Posix.Files | ||
import System.Posix.IO (createFile) | ||
import System.Posix.Types (FileMode) | ||
|
||
import Cardano.Node.Run (checkVRFFilePermissions) | ||
import Cardano.Node.Types (VRFPrivateKeyFilePermissionError (..)) | ||
import Hedgehog (Gen, Property, classify, discover, forAll, property, success) | ||
import qualified Hedgehog | ||
import qualified Hedgehog.Gen as Gen | ||
import Hedgehog.Internal.Property (failWith) | ||
|
||
|
||
-- | This property ensures that the VRF signing key file is created only with owner permissions | ||
prop_createVRFSigningKeyFilePermissions :: Property | ||
prop_createVRFSigningKeyFilePermissions = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do | ||
-- Key filepaths | ||
vrfVerKey <- noteTempFile tempDir "VRF-verification-key-file" | ||
|
||
vrfSignKey <- noteTempFile tempDir "VRF-signing-key-file" | ||
|
||
-- Create VRF key pair | ||
void $ execCardanoCLI | ||
[ "shelley","node","key-gen-VRF" | ||
, "--verification-key-file", vrfVerKey | ||
, "--signing-key-file", vrfSignKey | ||
] | ||
|
||
result <- liftIO . runExceptT $ checkVRFFilePermissions vrfSignKey | ||
case result of | ||
Left err -> | ||
failWith Nothing | ||
$ "key-gen-VRF cli command created a VRF signing key file with the wrong permissions: " <> show err | ||
Right () -> success | ||
|
||
-- ----------------------------------------------------------------------------- | ||
|
||
tests :: IO Bool | ||
tests = | ||
Hedgehog.checkParallel $$discover |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters