1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610
|
#!/bin/bash
#
# Copyright (C) 2011 Colin Walters <walters@verbum.org>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
set -euo pipefail
. $(dirname $0)/libtest.sh
skip_without_bwrap
skip_revokefs_without_fuse
echo "1..27"
# Use stable rather than master as the branch so we can test that the run
# command automatically finds the branch correctly
setup_repo "" "" stable
install_repo "" stable
# Verify that app is correctly installed
assert_has_dir $FL_DIR/app/org.test.Hello
assert_has_symlink $FL_DIR/app/org.test.Hello/current
assert_symlink_has_content $FL_DIR/app/org.test.Hello/current ^$ARCH/stable$
assert_has_dir $FL_DIR/app/org.test.Hello/$ARCH/stable
assert_has_symlink $FL_DIR/app/org.test.Hello/$ARCH/stable/active
ID=`readlink $FL_DIR/app/org.test.Hello/$ARCH/stable/active`
assert_has_file $FL_DIR/app/org.test.Hello/$ARCH/stable/active/deploy
assert_has_file $FL_DIR/app/org.test.Hello/$ARCH/stable/active/metadata
assert_has_dir $FL_DIR/app/org.test.Hello/$ARCH/stable/active/files
assert_has_dir $FL_DIR/app/org.test.Hello/$ARCH/stable/active/export
assert_has_file $FL_DIR/exports/share/applications/org.test.Hello.desktop
assert_has_file $FL_DIR/exports/share/metainfo/org.test.Hello.metainfo.xml
assert_has_file $FL_DIR/exports/share/metainfo/org.test.Hello.cmd.appdata.xml
# Ensure Exec key is rewritten
assert_file_has_content $FL_DIR/exports/share/applications/org.test.Hello.desktop "^Exec=.*flatpak run --branch=stable --arch=$ARCH --command=hello\.sh org\.test\.Hello$"
assert_has_file $FL_DIR/exports/share/gnome-shell/search-providers/org.test.Hello.search-provider.ini
assert_file_has_content $FL_DIR/exports/share/gnome-shell/search-providers/org.test.Hello.search-provider.ini "^DefaultDisabled=true$"
assert_has_file $FL_DIR/exports/share/krunner/dbusplugins/org.test.Hello.desktop
assert_file_has_content $FL_DIR/exports/share/krunner/dbusplugins/org.test.Hello.desktop "^X-KDE-PluginInfo-EnabledByDefault=false$"
assert_has_file $FL_DIR/exports/share/icons/hicolor/64x64/apps/org.test.Hello.png
assert_not_has_file $FL_DIR/exports/share/icons/hicolor/64x64/apps/dont-export.png
assert_has_file $FL_DIR/exports/share/icons/HighContrast/64x64/apps/org.test.Hello.png
$FLATPAK list ${U} | grep org.test.Hello > /dev/null
$FLATPAK list ${U} -d | grep org.test.Hello | grep test-repo > /dev/null
$FLATPAK list ${U} -d | grep org.test.Hello | grep current > /dev/null
$FLATPAK list ${U} -d | grep org.test.Hello | grep ${ID:0:12} > /dev/null
$FLATPAK info ${U} org.test.Hello > /dev/null
$FLATPAK info ${U} org.test.Hello | grep test-repo > /dev/null
$FLATPAK info ${U} org.test.Hello | grep $ID > /dev/null
ok "install"
if command -v update-desktop-database >/dev/null &&
command -v update-mime-database >/dev/null &&
command -v gtk-update-icon-cache >/dev/null; then
# Ensure triggers ran
assert_has_file $FL_DIR/exports/share/applications/mimeinfo.cache
assert_file_has_content $FL_DIR/exports/share/applications/mimeinfo.cache x-test/Hello
assert_has_file $FL_DIR/exports/share/icons/hicolor/icon-theme.cache
assert_has_file $FL_DIR/exports/share/icons/hicolor/index.theme
ok "install triggers"
else
ok "install triggers # skip Dependencies not available"
fi
run org.test.Hello &> hello_out
assert_file_has_content hello_out '^Hello world, from a sandbox$'
ok "hello"
# This should try and fail to run e.g. /usr/bin/--tmpfs, which will
# exit with a nonzero status because there is no such executable.
# It should not pass "--tmpfs /blah hello.sh" as bwrap options.
exit_status=0
run --command=--tmpfs org.test.Hello /blah hello.sh >&2 || exit_status=$?
assert_not_streq "$exit_status" 0
ok "avoided CVE-2024-32462"
true > value-in-sandbox
head value-in-sandbox >&2
run_sh org.test.Hello 'echo fd passthrough >&5' 5>value-in-sandbox
assert_file_has_content value-in-sandbox '^fd passthrough$'
ok "redirected fds can pass through to the app"
# XDG_RUNTIME_DIR is set to <temp directory>/runtime by libtest.sh,
# so we always have the necessary setup to reproduce #4372
assert_not_streq "$XDG_RUNTIME_DIR" "/run/user/$(id -u)"
run_sh org.test.Platform 'echo $XDG_RUNTIME_DIR' > value-in-sandbox
head value-in-sandbox >&2
assert_file_has_content value-in-sandbox "^/run/user/$(id -u)\$"
ok "XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR not inherited"
assert_streq "$XDG_CACHE_HOME" "${TEST_DATA_DIR}/home/cache"
run_sh org.test.Hello 'echo "$XDG_CACHE_HOME"' > value-in-sandbox
head value-in-sandbox >&2
assert_file_has_content value-in-sandbox "^${TEST_DATA_DIR}/home/\\.var/app/org\\.test\\.Hello/cache\$"
test -d "${TEST_DATA_DIR}/home/.var/app/org.test.Hello/cache"
run_sh org.test.Hello 'echo "$HOST_XDG_CACHE_HOME"' > host-value-in-sandbox
head host-value-in-sandbox >&2
assert_file_has_content host-value-in-sandbox "^${TEST_DATA_DIR}/home/cache\$"
assert_streq "$XDG_CONFIG_HOME" "${TEST_DATA_DIR}/home/config"
run_sh org.test.Hello 'echo "$XDG_CONFIG_HOME"' > value-in-sandbox
head value-in-sandbox >&2
assert_file_has_content value-in-sandbox "^${TEST_DATA_DIR}/home/\\.var/app/org\\.test\\.Hello/config\$"
test -d "${TEST_DATA_DIR}/home/.var/app/org.test.Hello/config"
run_sh org.test.Hello 'echo "$HOST_XDG_CONFIG_HOME"' > host-value-in-sandbox
head host-value-in-sandbox >&2
assert_file_has_content host-value-in-sandbox "^${TEST_DATA_DIR}/home/config\$"
assert_streq "$XDG_DATA_HOME" "${TEST_DATA_DIR}/home/share"
run_sh org.test.Hello 'echo "$XDG_DATA_HOME"' > value-in-sandbox
head value-in-sandbox >&2
assert_file_has_content value-in-sandbox "^${TEST_DATA_DIR}/home/\\.var/app/org\\.test\\.Hello/data\$"
test -d "${TEST_DATA_DIR}/home/.var/app/org.test.Hello/data"
run_sh org.test.Hello 'echo "$HOST_XDG_DATA_HOME"' > host-value-in-sandbox
head host-value-in-sandbox >&2
assert_file_has_content host-value-in-sandbox "^${TEST_DATA_DIR}/home/share\$"
assert_streq "$XDG_STATE_HOME" "${TEST_DATA_DIR}/home/state"
run_sh org.test.Hello 'echo "$XDG_STATE_HOME"' > value-in-sandbox
head value-in-sandbox >&2
assert_file_has_content value-in-sandbox "^${TEST_DATA_DIR}/home/\\.var/app/org\\.test\\.Hello/\\.local/state\$"
test -d "${TEST_DATA_DIR}/home/.var/app/org.test.Hello/.local/state"
run_sh org.test.Hello 'echo "$HOST_XDG_STATE_HOME"' > host-value-in-sandbox
head host-value-in-sandbox >&2
assert_file_has_content host-value-in-sandbox "^${TEST_DATA_DIR}/home/state\$"
ok "XDG_foo_HOME work as expected"
run_sh org.test.Platform cat /.flatpak-info >runtime-fpi
assert_file_has_content runtime-fpi "[Runtime]"
assert_file_has_content runtime-fpi "^runtime=runtime/org\.test\.Platform/$ARCH/stable$"
ok "run a runtime"
if [ -f /etc/os-release ]; then
run_sh org.test.Platform cat /run/host/os-release >os-release
(cd /etc; md5sum os-release) | md5sum -c >&2
ARGS="--filesystem=host-etc" run_sh org.test.Platform cat /run/host/os-release >os-release
(cd /etc; md5sum os-release) | md5sum -c >&2
if run_sh org.test.Platform "echo test >> /run/host/os-release"; then exit 1; fi
if run_sh org.test.Platform "echo test >> /run/host/os-release"; then exit 1; fi
elif [ -f /usr/lib/os-release ]; then
run_sh org.test.Platform cat /run/host/os-release >os-release
(cd /usr/lib; md5sum os-release) | md5sum -c >&2
ARGS="--filesystem=host-os" run_sh org.test.Platform cat /run/host/os-release >os-release
(cd /usr/lib; md5sum os-release) | md5sum -c >&2
if run_sh org.test.Platform "echo test >> /run/host/os-release"; then exit 1; fi
if run_sh org.test.Platform "echo test >> /run/host/os-release"; then exit 1; fi
fi
ok "host os-release"
run_sh org.test.Platform 'cat /run/host/container-manager' > container-manager
echo flatpak > expected
diff -u expected container-manager >&2
run_sh org.test.Platform 'echo "${container}"' > container-manager
diff -u expected container-manager >&2
ok "host container-manager"
if run org.test.Nonexistent 2> run-error-log >&2; then
assert_not_reached "Unexpectedly able to run non-existent runtime"
fi
assert_file_has_content run-error-log "error: app/org\.test\.Nonexistent/$ARCH/master not installed"
if ${FLATPAK} run --commit=abc runtime/org.test.Platform 2> run-error-log >&2; then
assert_not_reached "Unexpectedly able to run non-existent commit"
fi
assert_file_has_content run-error-log "error: runtime/org\.test\.Platform/$ARCH/stable (commit abc) not installed"
if run runtime/org.test.Nonexistent 2> run-error-log >&2; then
assert_not_reached "Unexpectedly able to run non-existent runtime"
fi
assert_file_has_content run-error-log "error: runtime/org\.test\.Nonexistent/\*unspecified\*/\*unspecified\* not installed"
ok "error handling for invalid refs"
run_sh org.test.Hello cat /run/user/`id -u`/flatpak-info > fpi
assert_file_has_content fpi '^name=org\.test\.Hello$'
ok "flatpak-info"
run_sh org.test.Hello readlink /proc/self/ns/net > unshared_net_ns
ARGS="--share=network" run_sh org.test.Hello readlink /proc/self/ns/net > shared_net_ns
assert_not_streq `cat unshared_net_ns` `readlink /proc/self/ns/net`
assert_streq `cat shared_net_ns` `readlink /proc/self/ns/net`
run_sh org.test.Hello readlink /proc/self/ns/ipc > unshared_ipc_ns
ARGS="--share=ipc" run_sh org.test.Hello readlink /proc/self/ns/ipc > shared_ipc_ns
assert_not_streq `cat unshared_ipc_ns` `readlink /proc/self/ns/ipc`
assert_streq `cat shared_ipc_ns` `readlink /proc/self/ns/ipc`
# We try the filesystem namespace tests several times with different
# shared-or-not directories, because:
# - --filesystem=/foo doesn't work if /foo is read-only in the container
# (notably, --filesystem=/usr/... won't work)
# - --filesystem=host doesn't expose either /usr or /var/... or /var/tmp
# from the host because they're on the list of things we expect to be
# supplied by the container
test_filesystem_binding () {
local dir="$1"
if run_sh org.test.Hello cat "$dir/package_version.txt" &> /dev/null; then
assert_not_reached "Unexpectedly allowed to access file"
fi
case "$dir" in
(/home/*|/opt/*|/var/tmp/*)
if ! ARGS="--filesystem=$dir" run_sh org.test.Hello cat "$dir/package_version.txt" > /dev/null; then
assert_not_reached "Failed to share --filesystem=$dir"
fi
;;
(*)
echo "Not testing --filesystem=$dir, it won't necessarily work" >&2
;;
esac
case "$dir" in
(/home/*|/opt/*)
if ! ARGS="--filesystem=host" run_sh org.test.Hello cat "$dir/package_version.txt" > /dev/null; then
assert_not_reached "Failed to share $dir as part of host filesystem"
fi
;;
(*)
echo "Not testing --filesystem=host with $dir, it won't necessarily work" >&2
;;
esac
}
test_filesystem_binding "${test_builddir}"
mkdir "${TEST_DATA_DIR}/shareable"
cp "${test_builddir}/package_version.txt" "${TEST_DATA_DIR}/shareable/"
test_filesystem_binding "${TEST_DATA_DIR}/shareable"
# We don't want to pollute the home directory unprompted, but the user
# can opt-in by creating this directory.
if [ -e "${HOME}/.flatpak-tests" ]; then
cp "${test_builddir}/package_version.txt" "${HOME}/.flatpak-tests/"
test_filesystem_binding "${HOME}/.flatpak-tests"
else
echo "not testing \$HOME binding, \$HOME/.flatpak-tests/ does not exist" >&2
fi
ok "namespaces"
test_overrides () {
local dir="$1"
if run_sh org.test.Hello cat "$dir/package_version.txt" &> /dev/null; then
assert_not_reached "Unexpectedly allowed to access file"
fi
$FLATPAK override ${U} --filesystem=host org.test.Hello >&2
case "$dir" in
(/home/*|/opt/*)
if ! run_sh org.test.Hello cat "$dir/package_version.txt" > /dev/null; then
assert_not_reached "Failed to share $dir as part of host filesystem"
fi
;;
(*)
echo "Not testing --filesystem=host with $dir, it won't necessarily work" >&2
;;
esac
if ARGS="--nofilesystem=host" run_sh org.test.Hello cat "${dir}/package_version.txt" &> /dev/null; then
assert_not_reached "Unexpectedly allowed to access --nofilesystem=host file"
fi
$FLATPAK override ${U} --nofilesystem=host org.test.Hello >&2
if run_sh org.test.Hello cat "${dir}/package_version.txt" &> /dev/null; then
assert_not_reached "Unexpectedly allowed to access file"
fi
}
test_overrides "${test_builddir}"
if [ -e "${HOME}/.flatpak-tests" ]; then
cp "${test_builddir}/package_version.txt" "${HOME}/.flatpak-tests/"
test_overrides "${HOME}/.flatpak-tests"
else
echo "not testing \$HOME binding overrides, \$HOME/.flatpak-tests/ does not exist" >&2
fi
ok "overrides"
OLD_COMMIT=`${FLATPAK} ${U} info --show-commit org.test.Hello`
# TODO: For weird reasons this breaks in the system case. Needs debugging
if [ x${USE_SYSTEMDIR-} != xyes ] ; then
${FLATPAK} ${U} update -y -v org.test.Hello stable >&2
ALSO_OLD_COMMIT=`${FLATPAK} ${U} info --show-commit org.test.Hello`
assert_streq "$OLD_COMMIT" "$ALSO_OLD_COMMIT"
fi
ok "null update"
make_updated_app "" "" stable
${FLATPAK} ${U} update -y org.test.Hello >&2
NEW_COMMIT=`${FLATPAK} ${U} info --show-commit org.test.Hello`
assert_not_streq "$OLD_COMMIT" "$NEW_COMMIT"
run org.test.Hello &> hello_out
assert_file_has_content hello_out '^Hello world, from a sandboxUPDATED$'
ok "update"
ostree --repo=repos/test reset app/org.test.Hello/$ARCH/stable "$OLD_COMMIT" >&2
update_repo
if ${FLATPAK} ${U} update -y org.test.Hello >&2; then
assert_not_reached "Should not be able to update to older commit"
fi
NEW_NEW_COMMIT=`${FLATPAK} ${U} info --show-commit org.test.Hello`
assert_streq "$NEW_COMMIT" "$NEW_NEW_COMMIT"
ok "backwards update"
make_updated_app "" "" stable UPDATED2
OLD_COMMIT=`${FLATPAK} ${U} info --show-commit org.test.Hello`
# We should ignore the update (and warn) by default
${FLATPAK} ${U} install -y test-repo org.test.Hello >& install_stderr
NEW_COMMIT=`${FLATPAK} ${U} info --show-commit org.test.Hello`
assert_streq "$OLD_COMMIT" "$NEW_COMMIT"
assert_file_has_content install_stderr 'org.test.Hello/.* is already installed'
# But --or-update should do the update
${FLATPAK} ${U} install -y --or-update test-repo org.test.Hello >&2
NEW_COMMIT=`${FLATPAK} ${U} info --show-commit org.test.Hello`
assert_not_streq "$OLD_COMMIT" "$NEW_COMMIT"
ok "install --or-update"
DIR=`mktemp -d`
${FLATPAK} build-init ${DIR} org.test.Split org.test.Platform org.test.Platform stable >&2
mkdir -p ${DIR}/files/a
echo "a" > ${DIR}/files/a/data
mkdir -p ${DIR}/files/b
echo "b" > ${DIR}/files/b/data
mkdir -p ${DIR}/files/c
echo "c" > ${DIR}/files/c/data
mkdir -p ${DIR}/files/d
echo "d" > ${DIR}/files/d/data
echo "nope" > ${DIR}/files/nope
${FLATPAK} build-finish --command=hello.sh ${DIR} >&2
${FLATPAK} build-export --no-update-summary ${FL_GPGARGS} repos/test ${DIR} stable >&2
update_repo
${FLATPAK} ${U} install -y test-repo org.test.Split --subpath=/a --subpath=/b --subpath=/nosuchdir stable >&2
COMMIT=`${FLATPAK} ${U} info --show-commit org.test.Split`
if [ x${USE_SYSTEMDIR-} != xyes ] ; then
# Work around bug in ostree: local pulls don't do commitpartials
assert_has_file $FL_DIR/repo/state/${COMMIT}.commitpartial
fi
assert_has_file $FL_DIR/app/org.test.Split/$ARCH/stable/active/files/a/data
assert_has_file $FL_DIR/app/org.test.Split/$ARCH/stable/active/files/b/data
assert_not_has_file $FL_DIR/app/org.test.Split/$ARCH/stable/active/files/c
assert_not_has_file $FL_DIR/app/org.test.Split/$ARCH/stable/active/files/d
assert_not_has_file $FL_DIR/app/org.test.Split/$ARCH/stable/active/files/nope
assert_not_has_file $FL_DIR/app/org.test.Split/$ARCH/stable/active/files/nosuchdir
echo "aa" > ${DIR}/files/a/data2
rm ${DIR}/files/a/data
mkdir -p ${DIR}/files/e
echo "e" > ${DIR}/files/e/data
mkdir -p ${DIR}/files/f
echo "f" > ${DIR}/files/f/data
rm -rf ${DIR}/files/b
${FLATPAK} build-export --no-update-summary ${FL_GPGARGS} repos/test ${DIR} stable >&2
update_repo
${FLATPAK} ${U} update -y --subpath=/a --subpath=/b --subpath=/e --subpath=/nosuchdir org.test.Split >&2
COMMIT=`${FLATPAK} ${U} info --show-commit org.test.Split`
if [ x${USE_SYSTEMDIR-} != xyes ] ; then
# Work around bug in ostree: local pulls don't do commitpartials
assert_has_file $FL_DIR/repo/state/${COMMIT}.commitpartial
fi
assert_not_has_file $FL_DIR/app/org.test.Split/$ARCH/stable/active/files/a/data
assert_has_file $FL_DIR/app/org.test.Split/$ARCH/stable/active/files/a/data2
assert_not_has_file $FL_DIR/app/org.test.Split/$ARCH/stable/active/files/b
assert_not_has_file $FL_DIR/app/org.test.Split/$ARCH/stable/active/files/c
assert_not_has_file $FL_DIR/app/org.test.Split/$ARCH/stable/active/files/d
assert_has_file $FL_DIR/app/org.test.Split/$ARCH/stable/active/files/e/data
assert_not_has_file $FL_DIR/app/org.test.Split/$ARCH/stable/active/files/f
assert_not_has_file $FL_DIR/app/org.test.Split/$ARCH/stable/active/files/nope
${FLATPAK} build-export --no-update-summary ${FL_GPGARGS} repos/test ${DIR} stable >&2
update_repo
# Test reusing the old subpath list
${FLATPAK} ${U} update -y org.test.Split >&2
COMMIT=`${FLATPAK} ${U} info --show-commit org.test.Split`
if [ x${USE_SYSTEMDIR-} != xyes ] ; then
# Work around bug in ostree: local pulls don't do commitpartials
assert_has_file $FL_DIR/repo/state/${COMMIT}.commitpartial
fi
assert_not_has_file $FL_DIR/app/org.test.Split/$ARCH/stable/active/files/a/data
assert_has_file $FL_DIR/app/org.test.Split/$ARCH/stable/active/files/a/data2
assert_not_has_file $FL_DIR/app/org.test.Split/$ARCH/stable/active/files/b
assert_not_has_file $FL_DIR/app/org.test.Split/$ARCH/stable/active/files/c
assert_not_has_file $FL_DIR/app/org.test.Split/$ARCH/stable/active/files/d
assert_has_file $FL_DIR/app/org.test.Split/$ARCH/stable/active/files/e/data
assert_not_has_file $FL_DIR/app/org.test.Split/$ARCH/stable/active/files/f
assert_not_has_file $FL_DIR/app/org.test.Split/$ARCH/stable/active/files/nope
ok "subpaths"
VERSION=`cat "$test_builddir/package_version.txt"`
DIR=`mktemp -d`
${FLATPAK} build-init ${DIR} org.test.CurrentVersion org.test.Platform org.test.Platform stable >&2
${FLATPAK} build-finish --require-version=${VERSION} --command=hello.sh ${DIR} >&2
${FLATPAK} build-export --no-update-summary ${FL_GPGARGS} repos/test ${DIR} stable >&2
DIR=`mktemp -d`
${FLATPAK} build-init ${DIR} org.test.OldVersion org.test.Platform org.test.Platform stable >&2
${FLATPAK} build-finish --require-version=0.6.10 --command=hello.sh ${DIR} >&2
${FLATPAK} build-export --no-update-summary ${FL_GPGARGS} repos/test ${DIR} stable >&2
DIR=`mktemp -d`
${FLATPAK} build-init ${DIR} org.test.NewVersion org.test.Platform org.test.Platform stable >&2
${FLATPAK} build-finish --require-version=1${VERSION} --command=hello.sh ${DIR} >&2
${FLATPAK} build-export --no-update-summary ${FL_GPGARGS} repos/test ${DIR} stable >&2
update_repo
${FLATPAK} ${U} install -y test-repo org.test.OldVersion stable >&2
${FLATPAK} ${U} install -y test-repo org.test.CurrentVersion stable >&2
(! ${FLATPAK} ${U} install -y test-repo org.test.NewVersion stable) >&2
DIR=`mktemp -d`
${FLATPAK} build-init ${DIR} org.test.OldVersion org.test.Platform org.test.Platform stable >&2
${FLATPAK} build-finish --require-version=99.0.0 --command=hello.sh ${DIR} >&2
${FLATPAK} build-export --no-update-summary ${FL_GPGARGS} repos/test ${DIR} stable >&2
update_repo
(! ${FLATPAK} ${U} update -y org.test.OldVersion) >&2
DIR=`mktemp -d`
${FLATPAK} build-init ${DIR} org.test.OldVersion org.test.Platform org.test.Platform stable >&2
${FLATPAK} build-finish --require-version=0.1.1 --command=hello.sh ${DIR} >&2
${FLATPAK} build-export --no-update-summary ${FL_GPGARGS} repos/test ${DIR} stable >&2
update_repo
${FLATPAK} ${U} update -y org.test.OldVersion >&2
# Make sure a multi-ref update succeeds even if some update requires a newer version
# Note that updates are in alphabetical order, so CurrentVersion will be pulled first
# and should not block a successful install of OldVersion later
DIR=`mktemp -d`
${FLATPAK} build-init ${DIR} org.test.CurrentVersion org.test.Platform org.test.Platform stable >&2
touch ${DIR}/files/updated
${FLATPAK} build-finish --require-version=99.0.0 --command=hello.sh ${DIR} >&2
${FLATPAK} build-export --no-update-summary ${FL_GPGARGS} repos/test ${DIR} stable >&2
DIR=`mktemp -d`
${FLATPAK} build-init ${DIR} org.test.OldVersion org.test.Platform org.test.Platform stable >&2
touch ${DIR}/files/updated
${FLATPAK} build-finish --require-version=${VERSION} --command=hello.sh ${DIR} >&2
${FLATPAK} build-export --no-update-summary ${FL_GPGARGS} repos/test ${DIR} stable >&2
update_repo
if ${FLATPAK} ${U} update -y &> err_version.txt; then
assert_not_reached "Should not have been able to update due to version"
fi
assert_file_has_content err_version.txt "needs a later flatpak version"
assert_not_has_file $FL_DIR/app/org.test.CurrentVersion/$ARCH/stable/active/files/updated
assert_has_file $FL_DIR/app/org.test.OldVersion/$ARCH/stable/active/files/updated
ok "version checks"
rm -rf app
${FLATPAK} build-init app org.test.Writable org.test.Platform org.test.Platform stable >&2
mkdir -p app/files/a-dir
chmod a+rwx app/files/a-dir
${FLATPAK} build-finish --command=hello.sh app >&2
# Note: not --canonical-permissions
${FLATPAK} build-export -vv --no-update-summary --disable-sandbox --files=files repos/test app stable >&2
ostree --repo=repos/test commit --keep-metadata=xa.metadata --owner-uid=0 --owner-gid=0 --no-xattrs ${FL_GPGARGS} --branch=app/org.test.Writable/$ARCH/stable app >&2
update_repo
# In the system-helper case this fails to install due to the permission canonicalization happening in the
# child-repo making objects get the wrong checksum, whereas in the user case we successfully import it, but
# it will have canonicalized permissions.
if ${FLATPAK} ${U} install -y test-repo org.test.Writable >&2; then
assert_file_has_mode $FL_DIR/app/org.test.Writable/$ARCH/stable/active/files/a-dir 775
fi
ok "no world writable dir"
rm -rf app
${FLATPAK} build-init app org.test.Setuid org.test.Platform org.test.Platform stable >&2
mkdir -p app/files/
touch app/files/exe
chmod u+s app/files/exe
${FLATPAK} build-finish --command=hello.sh app >&2
# Note: not --canonical-permissions
${FLATPAK} build-export -vv --no-update-summary --disable-sandbox --files=files repos/test app stable >&2
ostree -v --repo=repos/test commit --keep-metadata=xa.metadata --owner-uid=0 --owner-gid=0 --no-xattrs ${FL_GPGARGS} --branch=app/org.test.Setuid/$ARCH/stable app >&2
update_repo
if ${FLATPAK} ${U} install -y test-repo org.test.Setuid &> err2.txt; then
assert_not_reached "Should not be able to install with setuid file"
fi
assert_file_has_content err2.txt [Ii]nvalid
ok "no setuid"
rm -rf app
${FLATPAK} build-init app org.test.App org.test.Platform org.test.Platform stable >&2
mkdir -p app/files/
touch app/files/exe
${FLATPAK} build-finish --command=hello.sh --sdk=org.test.Sdk app >&2
${FLATPAK} build-export --no-update-summary ${FL_GPGARGS} repos/test app stable >&2
update_repo
${FLATPAK} ${U} install -y test-repo org.test.App >&2
${FLATPAK} ${U} info -m org.test.App > out
assert_file_has_content out "^sdk=org\.test\.Sdk/$(flatpak --default-arch)/stable$"
ok "--sdk option"
rm -fr "$HOME/.var/app/org.test.Hello"
mkdir -p "$HOME/.var/app/org.test.Hello"
run --command=sh --persist=.persist org.test.Hello -c 'echo can-persist > .persist/rc'
sed -e 's,^,#--persist=.persist# ,g' < "$HOME/.var/app/org.test.Hello/.persist/rc" >&2
assert_file_has_content "$HOME/.var/app/org.test.Hello/.persist/rc" "can-persist"
ok "--persist=.persist persists a directory"
rm -fr "$HOME/.var/app/org.test.Hello"
mkdir -p "$HOME/.var/app/org.test.Hello"
# G_DEBUG='' to avoid the deprecation warning being fatal
G_DEBUG='' run --command=sh --persist=/.persist org.test.Hello -c 'echo can-persist > .persist/rc'
sed -e 's,^,#--persist=/.persist# ,g' < "$HOME/.var/app/org.test.Hello/.persist/rc" >&2
assert_file_has_content "$HOME/.var/app/org.test.Hello/.persist/rc" "can-persist"
ok "--persist=/.persist is a deprecated form of --persist=.persist"
rm -fr "$HOME/.var/app/org.test.Hello"
mkdir -p "$HOME/.var/app/org.test.Hello"
run --command=sh --persist=. org.test.Hello -c 'echo can-persist > .persistrc'
sed -e 's,^,#--persist=.# ,g' < "$HOME/.var/app/org.test.Hello/.persistrc" >&2
assert_file_has_content "$HOME/.var/app/org.test.Hello/.persistrc" "can-persist"
ok "--persist=. persists all files"
mkdir "${TEST_DATA_DIR}/inaccessible"
echo FOO > ${TEST_DATA_DIR}/inaccessible/secret-file
rm -fr "$HOME/.var/app/org.test.Hello"
mkdir -p "$HOME/.var/app/org.test.Hello"
ln -fns "${TEST_DATA_DIR}/inaccessible" "$HOME/.var/app/org.test.Hello/persist"
# G_DEBUG='' to avoid the warnings being fatal when we reject a --persist option.
# LC_ALL=C so we get the expected non-localized string.
LC_ALL=C G_DEBUG='' run --command=ls --persist=persist --persist=relative/../escape org.test.Hello -la ~/persist &> hello_out || true
sed -e 's,^,#--persist=symlink# ,g' < hello_out >&2
assert_file_has_content hello_out "not allowed to avoid sandbox escape"
assert_not_file_has_content hello_out "secret-file"
ok "--persist doesn't allow sandbox escape via a symlink (CVE-2024-42472)"
|