2017-03-26 12:03:47 +03:00
#!/bin/bash
#
# Copyright (C) 2011 Colin Walters <walters@verbum.org>
#
2018-01-30 22:26:26 +03:00
# SPDX-License-Identifier: LGPL-2.0+
#
2017-03-26 12:03:47 +03:00
# 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
2021-12-07 04:20:55 +03:00
# License along with this library. If not, see <https://www.gnu.org/licenses/>.
2017-03-26 12:03:47 +03:00
set -euo pipefail
. $( dirname $0 ) /libtest.sh
2018-12-04 17:37:20 +03:00
mode = "bare-user-only"
setup_test_repository " $mode "
2022-01-20 13:54:30 +03:00
extra_basic_tests = 7
2017-03-26 12:03:47 +03:00
. $( dirname $0 ) /basic-test.sh
2017-06-07 20:12:08 +03:00
2017-09-26 19:41:07 +03:00
$CMD_PREFIX ostree --version > version.yaml
2018-01-17 17:07:32 +03:00
python3 -c 'import yaml; yaml.safe_load(open("version.yaml"))'
2017-09-26 19:41:07 +03:00
echo "ok yaml version"
2017-06-07 20:12:08 +03:00
# Reset things so we don't inherit a lot of state from earlier tests
cd ${ test_tmpdir }
rm repo files -rf
ostree_repo_init repo init --mode= bare-user-only
# Init an archive repo where we'll store content that can't go into bare-user
cd ${ test_tmpdir }
rm repo-input -rf
ostree_repo_init repo-input init --mode= archive
2021-08-19 17:07:19 +03:00
2017-06-07 20:12:08 +03:00
cd ${ test_tmpdir }
cat > statoverride.txt <<EOF
2048 /some-setuid
EOF
mkdir -p files/
echo "a setuid file" > files/some-setuid
chmod 0644 files/some-setuid
$CMD_PREFIX ostree --repo= repo-input commit -b content-with-suid --statoverride= statoverride.txt --tree= dir = files
if $CMD_PREFIX ostree pull-local --repo= repo repo-input 2>err.txt; then
assert_not_reached "copying suid file into bare-user worked?"
fi
2017-09-18 22:46:03 +03:00
assert_file_has_content err.txt "Content object.*invalid mode.*with bits 040.*"
2017-06-07 20:12:08 +03:00
echo "ok failed to commit suid"
2017-06-07 20:18:04 +03:00
2022-01-20 13:54:30 +03:00
cd ${ test_tmpdir }
rm repo-input -rf
ostree_repo_init repo-input init --mode= archive
rm files -rf && mkdir files
if $CMD_PREFIX ostree --repo= repo-input commit -b metadata --tree= dir = files --add-metadata-string= '=FOO' 2>err.txt; then
assert_not_reached "committed an empty metadata key"
fi
assert_file_has_content err.txt "Empty metadata key"
$CMD_PREFIX ostree --repo= repo-input commit -b metadata --tree= dir = files --add-metadata-string= 'FOO='
echo "ok rejected invalid metadata"
2017-06-07 20:18:04 +03:00
cd ${ test_tmpdir }
rm repo-input -rf
ostree_repo_init repo-input init --mode= archive
rm files -rf && mkdir files
echo "a group writable file" > files/some-group-writable
chmod 0664 files/some-group-writable
$CMD_PREFIX ostree --repo= repo-input commit -b content-with-group-writable --tree= dir = files
2021-08-23 12:46:22 +03:00
$OSTREE pull-local repo-input
$OSTREE checkout -U -H content-with-group-writable groupwritable-co
2017-06-07 20:18:04 +03:00
assert_file_has_mode groupwritable-co/some-group-writable 664
echo "ok supported group writable"
2017-06-07 21:21:59 +03:00
cd ${ test_tmpdir }
rm repo-input -rf
ostree_repo_init repo-input init --mode= archive
rm files -rf && mkdir files
mkdir files/worldwritable-dir
chmod a+w files/worldwritable-dir
$CMD_PREFIX ostree --repo= repo-input commit -b content-with-dir-world-writable --tree= dir = files
2021-08-23 12:46:22 +03:00
$OSTREE pull-local repo-input
$OSTREE checkout -U -H content-with-dir-world-writable dir-co
2017-06-07 21:21:59 +03:00
assert_file_has_mode dir-co/worldwritable-dir 775
echo "ok didn't make world-writable dir"
2017-06-12 20:59:33 +03:00
2017-08-29 19:03:37 +03:00
if ! skip_one_without_user_xattrs; then
cd ${ test_tmpdir }
rm repo-input -rf
rm repo -rf
ostree_repo_init repo init --mode= bare-user-only
ostree_repo_init repo-input init --mode= bare-user
rm files -rf && mkdir files
echo afile > files/afile
ln -s afile files/afile-link
$CMD_PREFIX ostree --repo= repo-input commit --canonical-permissions -b testtree --tree= dir = files
afile_relobjpath = $( ostree_file_path_to_relative_object_path repo-input testtree /afile)
afile_link_relobjpath = $( ostree_file_path_to_relative_object_path repo-input testtree /afile-link)
$CMD_PREFIX ostree pull-local --repo= repo repo-input
assert_files_hardlinked repo/${ afile_relobjpath } repo-input/${ afile_relobjpath }
if files_are_hardlinked repo/${ afile_link_relobjpath } repo-input/${ afile_link_relobjpath } ; then
assert_not_reached "symlinks hardlinked across bare-user?"
fi
$OSTREE fsck -q
echo "ok hardlink pull from bare-user"
2017-06-12 20:59:33 +03:00
fi
2021-08-19 17:07:19 +03:00
cd ${ test_tmpdir }
rm repo -rf
ostree_repo_init repo init --mode= bare-user-only
rm files -rf && mkdir files
echo afile > files/afile
2021-08-23 12:46:22 +03:00
chmod 0777 files/afile
2021-08-19 17:07:19 +03:00
$OSTREE commit ${ COMMIT_ARGS } -b perms files
$OSTREE fsck
2021-08-20 13:58:24 +03:00
rm out -rf
$OSTREE checkout --force-copy perms out
2021-08-23 12:46:22 +03:00
assert_file_has_mode out/afile 755
2021-08-20 13:58:24 +03:00
$OSTREE checkout ${ CHECKOUT_H_ARGS } --union-identical perms out
2021-08-23 12:46:22 +03:00
assert_file_has_mode out/afile 755
2021-08-20 13:58:24 +03:00
echo "ok automatic canonical perms for bare-user-only"