Blame tests/test-basic-root.sh

Packit Service 2a3f3d
#!/bin/bash
Packit Service 2a3f3d
#
Packit Service 2a3f3d
# Copyright (C) 2011 Colin Walters <walters@verbum.org>
Packit Service 2a3f3d
#
Packit Service 2a3f3d
# SPDX-License-Identifier: LGPL-2.0+
Packit Service 2a3f3d
#
Packit Service 2a3f3d
# This library is free software; you can redistribute it and/or
Packit Service 2a3f3d
# modify it under the terms of the GNU Lesser General Public
Packit Service 2a3f3d
# License as published by the Free Software Foundation; either
Packit Service 2a3f3d
# version 2 of the License, or (at your option) any later version.
Packit Service 2a3f3d
#
Packit Service 2a3f3d
# This library is distributed in the hope that it will be useful,
Packit Service 2a3f3d
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 2a3f3d
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 2a3f3d
# Lesser General Public License for more details.
Packit Service 2a3f3d
#
Packit Service 2a3f3d
# You should have received a copy of the GNU Lesser General Public
Packit Service 2a3f3d
# License along with this library; if not, write to the
Packit Service 2a3f3d
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Packit Service 2a3f3d
# Boston, MA 02111-1307, USA.
Packit Service 2a3f3d
Packit Service 2a3f3d
set -euo pipefail
Packit Service 2a3f3d
Packit Service 2a3f3d
. $(dirname $0)/libtest.sh
Packit Service 2a3f3d
Packit Service 2a3f3d
id=$(id -u)
Packit Service 2a3f3d
Packit Service 2a3f3d
if test ${id} != 0; then
Packit Service 2a3f3d
    skip "continued basic tests must be run as root (possibly in a container)"
Packit Service 2a3f3d
fi
Packit Service 2a3f3d
Packit Service 2a3f3d
setup_test_repository "bare"
Packit Service 2a3f3d
Packit Service 2a3f3d
echo "1..1"
Packit Service 2a3f3d
Packit Service 2a3f3d
nextid=$(($id + 1))
Packit Service 2a3f3d
Packit Service 2a3f3d
rm checkout-test2 -rf
Packit Service 2a3f3d
$OSTREE checkout test2 checkout-test2
Packit Service 2a3f3d
$OSTREE commit ${COMMIT_ARGS} -b test2 --tree=ref=test2 --owner-uid=$nextid
Packit Service 2a3f3d
$OSTREE ls test2 baz/cow > ls.txt
Packit Service 2a3f3d
assert_file_has_content ls.txt '-00644 '${nextid}' '${id}
Packit Service 2a3f3d
# As bare and running as root (e.g. Docker container), do some ownership tests
Packit Service 2a3f3d
# https://github.com/ostreedev/ostree/pull/801
Packit Service 2a3f3d
# Both hardlinks and copies should respect ownership, but we don't have -C yet;
Packit Service 2a3f3d
# add it when we do.
Packit Service 2a3f3d
for opt in -H; do
Packit Service 2a3f3d
    rm test2-co -rf
Packit Service 2a3f3d
    $OSTREE checkout ${opt} test2 test2-co
Packit Service 2a3f3d
    assert_streq "$(stat -c '%u' test2-co/baz/cow)" ${nextid}
Packit Service 2a3f3d
    assert_streq "$(stat -c '%u' test2-co/baz/alink)" ${nextid}
Packit Service 2a3f3d
done
Packit Service 2a3f3d
rm test2-co -rf
Packit Service 2a3f3d
# But user mode doesn't
Packit Service 2a3f3d
$OSTREE checkout -U test2 test2-co
Packit Service 2a3f3d
assert_streq "$(stat -c '%u' test2-co/baz/cow)" ${id}
Packit Service 2a3f3d
assert_streq "$(stat -c '%u' test2-co/baz/alink)" ${id}
Packit Service 2a3f3d
echo "ok ownership"