Check exact error codes in linux-sandbox.sh
This commit is contained in:
parent
494a09c6df
commit
b9c2f834ee
|
@ -1,29 +1,30 @@
|
||||||
{ fixed-output }:
|
{ mode }:
|
||||||
|
|
||||||
with import ./config.nix;
|
with import ./config.nix;
|
||||||
|
|
||||||
mkDerivation ({
|
mkDerivation (
|
||||||
name = "ssl-export";
|
{
|
||||||
buildCommand = ''
|
name = "ssl-export";
|
||||||
# Add some indirection, otherwise grepping into the debug output finds the string.
|
buildCommand = ''
|
||||||
report () { echo CERT_$1_IN_SANDBOX; }
|
# Add some indirection, otherwise grepping into the debug output finds the string.
|
||||||
|
report () { echo CERT_$1_IN_SANDBOX; }
|
||||||
|
|
||||||
if [ -f /etc/ssl/certs/ca-certificates.crt ]; then
|
if [ -f /etc/ssl/certs/ca-certificates.crt ]; then
|
||||||
content=$(</etc/ssl/certs/ca-certificates.crt)
|
content=$(</etc/ssl/certs/ca-certificates.crt)
|
||||||
if [ "$content" == CERT_CONTENT ]; then
|
if [ "$content" == CERT_CONTENT ]; then
|
||||||
report present
|
report present
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
report missing
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
report missing
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Always fail, because we do not want to bother with fixed-output
|
# Always fail, because we do not want to bother with fixed-output
|
||||||
# derivations being cached, and do not want to compute the right hash.
|
# derivations being cached, and do not want to compute the right hash.
|
||||||
false;
|
false;
|
||||||
'';
|
'';
|
||||||
} // (
|
} // {
|
||||||
if fixed-output == "fixed-output"
|
fixed-output = { outputHash = "sha256:0000000000000000000000000000000000000000000000000000000000000000"; };
|
||||||
then { outputHash = "sha256:0000000000000000000000000000000000000000000000000000000000000000"; }
|
normal = { };
|
||||||
else { }
|
}.${mode}
|
||||||
))
|
)
|
||||||
|
|
||||||
|
|
|
@ -34,19 +34,23 @@ nix-build dependencies.nix --no-out-link --check --sandbox-paths /nix/store
|
||||||
# Test that sandboxed builds with --check and -K can move .check directory to store
|
# Test that sandboxed builds with --check and -K can move .check directory to store
|
||||||
nix-build check.nix -A nondeterministic --sandbox-paths /nix/store --no-out-link
|
nix-build check.nix -A nondeterministic --sandbox-paths /nix/store --no-out-link
|
||||||
|
|
||||||
(! nix-build check.nix -A nondeterministic --sandbox-paths /nix/store --no-out-link --check -K 2> $TEST_ROOT/log)
|
expectStderr 104 nix-build check.nix -A nondeterministic --sandbox-paths /nix/store --no-out-link --check -K \
|
||||||
if grepQuiet 'error: renaming' $TEST_ROOT/log; then false; fi
|
| tee >( grepQuietInverse 'error: renaming' ) \
|
||||||
grepQuiet 'may not be deterministic' $TEST_ROOT/log
|
| grepQuiet 'may not be deterministic'
|
||||||
|
|
||||||
# Test that sandboxed builds cannot write to /etc easily
|
# Test that sandboxed builds cannot write to /etc easily
|
||||||
(! nix-build -E 'with import ./config.nix; mkDerivation { name = "etc-write"; buildCommand = "echo > /etc/test"; }' --no-out-link --sandbox-paths /nix/store)
|
expect 100 nix-build -E 'with import ./config.nix; mkDerivation { name = "etc-write"; buildCommand = "echo > /etc/test"; }' --no-out-link --sandbox-paths /nix/store
|
||||||
|
|
||||||
|
|
||||||
## Test mounting of SSL certificates into the sandbox
|
## Test mounting of SSL certificates into the sandbox
|
||||||
testCert () {
|
testCert () {
|
||||||
(! nix-build linux-sandbox-cert-test.nix --argstr fixed-output "$2" --no-out-link --sandbox-paths /nix/store --option ssl-cert-file "$3" 2> $TEST_ROOT/log)
|
expectation=$1 # "missing" | "present"
|
||||||
cat $TEST_ROOT/log
|
mode=$2 # "normal" | "fixed-output"
|
||||||
grepQuiet "CERT_${1}_IN_SANDBOX" $TEST_ROOT/log
|
certFile=$3 # a string that can be the path to a cert file
|
||||||
|
[ "$mode" == fixed-output ] && ret=1 || ret=100
|
||||||
|
expectStderr $ret nix-build linux-sandbox-cert-test.nix --argstr mode "$mode" --no-out-link --sandbox-paths /nix/store --option ssl-cert-file "$certFile" | \
|
||||||
|
# tee /dev/stderr | \
|
||||||
|
grepQuiet "CERT_${expectation}_IN_SANDBOX"
|
||||||
}
|
}
|
||||||
|
|
||||||
nocert=$TEST_ROOT/no-cert-file.pem
|
nocert=$TEST_ROOT/no-cert-file.pem
|
||||||
|
|
Loading…
Reference in a new issue