Backfill tests for fwd-env and try-fwd-env
This commit is contained in:
parent
ff5dd74cbf
commit
2f8e84bf0a
2 changed files with 53 additions and 0 deletions
|
|
@ -10,6 +10,7 @@ import System.Posix (getProcessStatus, sigKILL, signalProcess)
|
|||
import System.Process qualified as Process
|
||||
import Test.Hspec
|
||||
import TestPrelude
|
||||
import GHC.IO.Exception (ExitCode(..))
|
||||
|
||||
spec :: Spec
|
||||
spec = parallel $ inTestM $ do
|
||||
|
|
@ -68,6 +69,26 @@ spec = parallel $ inTestM $ do
|
|||
|]
|
||||
`shouldOutput` "secret\n"
|
||||
|
||||
it "correctly escapes variables" $ do
|
||||
withEnv "MY_ENV_VAR" "$(echo foo)" $ do
|
||||
[i|
|
||||
jail "test" (sh ''echo "''${MY_ENV_VAR-unset}"'') (c: [
|
||||
(c.fwd-env "MY_ENV_VAR")
|
||||
])
|
||||
|]
|
||||
`shouldOutput` "$(echo foo)\n"
|
||||
|
||||
it "exits non-zero if the variable isn't set at runtime" $ do
|
||||
(exitCode, _stdout, stderr) <-
|
||||
runNixDrvWithExitCode
|
||||
[i|
|
||||
jail "test" (sh ''echo ok'') (c: [
|
||||
(c.fwd-env "MY_ENV_VAR")
|
||||
])
|
||||
|]
|
||||
liftIO $ exitCode `shouldBe` ExitFailure 1
|
||||
liftIO $ stderr `shouldContain` "MY_ENV_VAR: unbound variable"
|
||||
|
||||
describe "jail-to-host-channel" $ do
|
||||
it "calls a script on the outside of the jail with an argument and returns its stdout" $ do
|
||||
tmpDir <- getTestDir
|
||||
|
|
@ -379,6 +400,33 @@ spec = parallel $ inTestM $ do
|
|||
|]
|
||||
`shouldOutput` "UTC\n"
|
||||
|
||||
describe "try-fwd-env" $ do
|
||||
it "forwards the environment variable if set" $ do
|
||||
withEnv "MY_ENV_VAR" "secret" $ do
|
||||
[i|
|
||||
jail "test" (sh ''echo "''${MY_ENV_VAR-unset}"'') (c: [
|
||||
(c.try-fwd-env "MY_ENV_VAR")
|
||||
])
|
||||
|]
|
||||
`shouldOutput` "secret\n"
|
||||
|
||||
it "correctly escapes variables" $ do
|
||||
withEnv "MY_ENV_VAR" "$(echo foo)" $ do
|
||||
[i|
|
||||
jail "test" (sh ''echo "''${MY_ENV_VAR-unset}"'') (c: [
|
||||
(c.try-fwd-env "MY_ENV_VAR")
|
||||
])
|
||||
|]
|
||||
`shouldOutput` "$(echo foo)\n"
|
||||
|
||||
it "does not set the environment variable if it is not set" $ do
|
||||
[i|
|
||||
jail "test" (sh ''echo "''${MY_ENV_VAR-unset}"'') (c: [
|
||||
(c.try-fwd-env "MY_ENV_VAR")
|
||||
])
|
||||
|]
|
||||
`shouldOutput` "unset\n"
|
||||
|
||||
describe "try-readonly" $ do
|
||||
it "binds paths as readonly in the jail" $ do
|
||||
tmpDir <- getTestDir
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue