Skip to content

Commit

Permalink
tests: Exercise --env-fd
Browse files Browse the repository at this point in the history
Signed-off-by: Simon McVittie <smcv@collabora.com>
Part-of: GHSA-4ppf-fxf6-vxg2
  • Loading branch information
smcv authored and alexlarsson committed Jan 14, 2021
1 parent aeb6a7a commit 39a5621
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions tests/test-override.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,16 @@ reset_overrides

${FLATPAK} override --user --env=FOO=BAR org.test.Hello
${FLATPAK} override --user --env=BAR= org.test.Hello
# TODO: A future commit will add a way to avoid this ever being present in argv
${FLATPAK} override --user --env=SECRET_TOKEN=3047225e-5e38-4357-b21c-eac83b7e8ea6 org.test.Hello
# --env-fd with terminating \0 (strictly as documented).
printf '%s\0' "SECRET_TOKEN=3047225e-5e38-4357-b21c-eac83b7e8ea6" > env.3
# --env-fd without terminating \0 (which we also accept).
# TMPDIR and TZDIR are filtered out by ld.so for setuid processes,
# so setting these gives us a way to verify that we can pass them through
# a setuid bwrap (without special-casing them, as we previously did for
# TMPDIR).
${FLATPAK} override --user --env=TMPDIR=/nonexistent/tmp org.test.Hello
${FLATPAK} override --user --env=TZDIR=/nonexistent/tz org.test.Hello
printf '%s\0%s' "TMPDIR=/nonexistent/tmp" "TZDIR=/nonexistent/tz" > env.4
${FLATPAK} override --user --env-fd=3 --env-fd=4 org.test.Hello \
3<env.3 4<env.4
${FLATPAK} override --user --show org.test.Hello > override

assert_file_has_content override "^\[Environment\]$"
Expand Down Expand Up @@ -118,11 +120,11 @@ else
${FLATPAK} run --command=bash \
--env=FOO=BAR \
--env=BAR= \
--env=SECRET_TOKEN=3047225e-5e38-4357-b21c-eac83b7e8ea6 \
--env=TMPDIR=/nonexistent/tmp \
--env=TZDIR=/nonexistent/tz \
--env-fd=3 \
--env-fd=4 \
org.test.Hello \
-c 'echo "FOO=$FOO"; echo "BAR=$BAR"; echo "SECRET_TOKEN=$SECRET_TOKEN"; echo "TMPDIR=$TMPDIR"; echo "TZDIR=$TZDIR"' > out
-c 'echo "FOO=$FOO"; echo "BAR=$BAR"; echo "SECRET_TOKEN=$SECRET_TOKEN"; echo "TMPDIR=$TMPDIR"; echo "TZDIR=$TZDIR"' \
3<env.3 4<env.4 > out
# The versions from `flatpak run` overrule `flatpak override`
assert_file_has_content out '^FOO=BAR$'
assert_file_has_content out '^BAR=$'
Expand Down

0 comments on commit 39a5621

Please sign in to comment.