mirror of
https://github.com/NixOS/nix.git
synced 2025-11-09 03:56:01 +01:00
shellcheck fix: tests/functional/restricted.sh
This commit is contained in:
parent
d35d86da89
commit
b42ed6a74d
2 changed files with 12 additions and 11 deletions
|
|
@ -106,7 +106,6 @@
|
||||||
enable = true;
|
enable = true;
|
||||||
excludes = [
|
excludes = [
|
||||||
# We haven't linted these files yet
|
# We haven't linted these files yet
|
||||||
''^tests/functional/restricted\.sh$''
|
|
||||||
''^tests/functional/search\.sh$''
|
''^tests/functional/search\.sh$''
|
||||||
''^tests/functional/secure-drv-outputs\.sh$''
|
''^tests/functional/secure-drv-outputs\.sh$''
|
||||||
''^tests/functional/selfref-gc\.sh$''
|
''^tests/functional/selfref-gc\.sh$''
|
||||||
|
|
|
||||||
|
|
@ -40,30 +40,32 @@ nix eval --raw --expr "builtins.fetchurl file://${_NIX_TEST_SOURCE_DIR}/restrict
|
||||||
(! nix eval --raw --expr "fetchGit git://github.com/NixOS/patchelf.git" --impure --restrict-eval)
|
(! nix eval --raw --expr "fetchGit git://github.com/NixOS/patchelf.git" --impure --restrict-eval)
|
||||||
|
|
||||||
ln -sfn "${_NIX_TEST_SOURCE_DIR}/restricted.nix" "$TEST_ROOT/restricted.nix"
|
ln -sfn "${_NIX_TEST_SOURCE_DIR}/restricted.nix" "$TEST_ROOT/restricted.nix"
|
||||||
[[ $(nix-instantiate --eval $TEST_ROOT/restricted.nix) == 3 ]]
|
[[ $(nix-instantiate --eval "$TEST_ROOT"/restricted.nix) == 3 ]]
|
||||||
(! nix-instantiate --eval --restrict-eval $TEST_ROOT/restricted.nix)
|
(! nix-instantiate --eval --restrict-eval "$TEST_ROOT"/restricted.nix)
|
||||||
(! nix-instantiate --eval --restrict-eval $TEST_ROOT/restricted.nix -I $TEST_ROOT)
|
(! nix-instantiate --eval --restrict-eval "$TEST_ROOT"/restricted.nix -I "$TEST_ROOT")
|
||||||
(! nix-instantiate --eval --restrict-eval $TEST_ROOT/restricted.nix -I .)
|
(! nix-instantiate --eval --restrict-eval "$TEST_ROOT"/restricted.nix -I .)
|
||||||
nix-instantiate --eval --restrict-eval "$TEST_ROOT/restricted.nix" -I "$TEST_ROOT" -I "${_NIX_TEST_SOURCE_DIR}"
|
nix-instantiate --eval --restrict-eval "$TEST_ROOT/restricted.nix" -I "$TEST_ROOT" -I "${_NIX_TEST_SOURCE_DIR}"
|
||||||
|
|
||||||
|
# shellcheck disable=SC2016
|
||||||
[[ $(nix eval --raw --impure --restrict-eval -I . --expr 'builtins.readFile "${import ./simple.nix}/hello"') == 'Hello World!' ]]
|
[[ $(nix eval --raw --impure --restrict-eval -I . --expr 'builtins.readFile "${import ./simple.nix}/hello"') == 'Hello World!' ]]
|
||||||
|
|
||||||
# Check that we can't follow a symlink outside of the allowed paths.
|
# Check that we can't follow a symlink outside of the allowed paths.
|
||||||
mkdir -p $TEST_ROOT/tunnel.d $TEST_ROOT/foo2
|
mkdir -p "$TEST_ROOT"/tunnel.d "$TEST_ROOT"/foo2
|
||||||
ln -sfn .. $TEST_ROOT/tunnel.d/tunnel
|
ln -sfn .. "$TEST_ROOT"/tunnel.d/tunnel
|
||||||
echo foo > $TEST_ROOT/bar
|
echo foo > "$TEST_ROOT"/bar
|
||||||
|
|
||||||
expectStderr 1 nix-instantiate --restrict-eval --eval -E "let __nixPath = [ { prefix = \"foo\"; path = $TEST_ROOT/tunnel.d; } ]; in builtins.readFile <foo/tunnel/bar>" -I $TEST_ROOT/tunnel.d | grepQuiet "forbidden in restricted mode"
|
expectStderr 1 nix-instantiate --restrict-eval --eval -E "let __nixPath = [ { prefix = \"foo\"; path = $TEST_ROOT/tunnel.d; } ]; in builtins.readFile <foo/tunnel/bar>" -I "$TEST_ROOT"/tunnel.d | grepQuiet "forbidden in restricted mode"
|
||||||
|
|
||||||
expectStderr 1 nix-instantiate --restrict-eval --eval -E "let __nixPath = [ { prefix = \"foo\"; path = $TEST_ROOT/tunnel.d; } ]; in builtins.readDir <foo/tunnel/foo2>" -I $TEST_ROOT/tunnel.d | grepQuiet "forbidden in restricted mode"
|
expectStderr 1 nix-instantiate --restrict-eval --eval -E "let __nixPath = [ { prefix = \"foo\"; path = $TEST_ROOT/tunnel.d; } ]; in builtins.readDir <foo/tunnel/foo2>" -I "$TEST_ROOT"/tunnel.d | grepQuiet "forbidden in restricted mode"
|
||||||
|
|
||||||
# Reading the parents of allowed paths should show only the ancestors of the allowed paths.
|
# Reading the parents of allowed paths should show only the ancestors of the allowed paths.
|
||||||
[[ $(nix-instantiate --restrict-eval --eval -E "let __nixPath = [ { prefix = \"foo\"; path = $TEST_ROOT/tunnel.d; } ]; in builtins.readDir <foo/tunnel>" -I $TEST_ROOT/tunnel.d) == '{ "tunnel.d" = "directory"; }' ]]
|
[[ $(nix-instantiate --restrict-eval --eval -E "let __nixPath = [ { prefix = \"foo\"; path = $TEST_ROOT/tunnel.d; } ]; in builtins.readDir <foo/tunnel>" -I "$TEST_ROOT"/tunnel.d) == '{ "tunnel.d" = "directory"; }' ]]
|
||||||
|
|
||||||
# Check whether we can leak symlink information through directory traversal.
|
# Check whether we can leak symlink information through directory traversal.
|
||||||
traverseDir="${_NIX_TEST_SOURCE_DIR}/restricted-traverse-me"
|
traverseDir="${_NIX_TEST_SOURCE_DIR}/restricted-traverse-me"
|
||||||
ln -sfn "${_NIX_TEST_SOURCE_DIR}/restricted-secret" "${_NIX_TEST_SOURCE_DIR}/restricted-innocent"
|
ln -sfn "${_NIX_TEST_SOURCE_DIR}/restricted-secret" "${_NIX_TEST_SOURCE_DIR}/restricted-innocent"
|
||||||
mkdir -p "$traverseDir"
|
mkdir -p "$traverseDir"
|
||||||
|
# shellcheck disable=SC2001
|
||||||
goUp="..$(echo "$traverseDir" | sed -e 's,[^/]\+,..,g')"
|
goUp="..$(echo "$traverseDir" | sed -e 's,[^/]\+,..,g')"
|
||||||
output="$(nix eval --raw --restrict-eval -I "$traverseDir" \
|
output="$(nix eval --raw --restrict-eval -I "$traverseDir" \
|
||||||
--expr "builtins.readFile \"$traverseDir/$goUp${_NIX_TEST_SOURCE_DIR}/restricted-innocent\"" \
|
--expr "builtins.readFile \"$traverseDir/$goUp${_NIX_TEST_SOURCE_DIR}/restricted-innocent\"" \
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue