2024-01-05 18:42:15 +00:00
|
|
|
# Copyright (C) 2024 Umorpha Systems
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
2024-01-05 02:13:25 +00:00
|
|
|
bats_require_minimum_version 1.7.0
|
|
|
|
bats_load_library bats-support
|
|
|
|
bats_load_library bats-assert
|
|
|
|
bats_load_library bats-file
|
|
|
|
|
|
|
|
teardown() {
|
|
|
|
if [ -n "${tmpdir:-}" ]; then
|
|
|
|
temp_del "$tmpdir"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-01-26 01:43:54 +00:00
|
|
|
_sudo() {
|
|
|
|
sudo ${TMPDIR:+TMPDIR="$TMPDIR"} "$@"
|
|
|
|
}
|
|
|
|
|
2024-01-05 02:13:25 +00:00
|
|
|
@test "osi-mount needs arguments" {
|
|
|
|
LC_ALL=C run --separate-stderr osi-mount
|
|
|
|
assert_failure 2
|
|
|
|
assert_equal "$output" ''
|
|
|
|
assert [ ${#stderr_lines[@]} -gt 1 ]
|
|
|
|
assert_regex "${stderr_lines[-1]}" "^Try .*osi-mount --help' for more information\$"
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "osi-mount --user" {
|
|
|
|
tmpdir="$(temp_make)"
|
|
|
|
|
|
|
|
truncate --size=100m "$tmpdir/tst.img"
|
|
|
|
mkfs.ext4 "$tmpdir/tst.img"
|
|
|
|
mkdir "$tmpdir/mnt"
|
|
|
|
|
|
|
|
echo 'Checking that it uses the current directory...'
|
2024-01-26 01:43:54 +00:00
|
|
|
run --separate-stderr _sudo osi-mount --user "$tmpdir/tst.img" "$tmpdir/mnt" pwd
|
2024-01-05 02:13:25 +00:00
|
|
|
assert_success
|
|
|
|
assert_equal "${output%$'\r'}" "$PWD"
|
|
|
|
assert_equal "$stderr" ''
|
|
|
|
|
2024-01-26 01:43:54 +00:00
|
|
|
echo 'Checking that it respects TMPDIR...'
|
|
|
|
mkdir "$tmpdir/tmp"
|
|
|
|
TMPDIR="$tmpdir/tmp" _sudo osi-mount --user "$tmpdir/tst.img" "$tmpdir/mnt" env >"$tmpdir/env.txt"
|
|
|
|
act=$(grep ^TMPDIR= "$tmpdir/env.txt")
|
|
|
|
assert_equal "${act%$'\r'}" "TMPDIR=$tmpdir/tmp"
|
|
|
|
|
2024-01-05 02:13:25 +00:00
|
|
|
echo 'Checking that it can write outside of the mountpoint...'
|
2024-01-26 01:43:54 +00:00
|
|
|
run --separate-stderr _sudo osi-mount --user "$tmpdir/tst.img" "$tmpdir/mnt" -- sh -c "echo foo>$tmpdir/x"
|
2024-01-05 02:13:25 +00:00
|
|
|
assert_success
|
|
|
|
assert_file_contains "$tmpdir/x" foo
|
|
|
|
assert_file_owner "$USER" "$tmpdir/x"
|
|
|
|
|
|
|
|
echo "Checking that it can't write inside of the mountpoint..."
|
2024-01-26 01:43:54 +00:00
|
|
|
run --separate-stderr _sudo osi-mount --user "$tmpdir/tst.img" "$tmpdir/mnt" -- sh -c "echo bar>$tmpdir/mnt/y"
|
2024-01-05 02:13:25 +00:00
|
|
|
assert_failure
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "osi-mount --root" {
|
|
|
|
tmpdir="$(temp_make)"
|
|
|
|
|
|
|
|
truncate --size=100m "$tmpdir/tst.img"
|
|
|
|
mkfs.ext4 "$tmpdir/tst.img"
|
|
|
|
mkdir "$tmpdir/mnt"
|
|
|
|
|
|
|
|
echo 'Checking that it uses the current directory...'
|
2024-01-26 01:43:54 +00:00
|
|
|
run --separate-stderr _sudo osi-mount --root "$tmpdir/tst.img" "$tmpdir/mnt" pwd
|
2024-01-05 02:13:25 +00:00
|
|
|
assert_success
|
|
|
|
assert_equal "${output%$'\r'}" "$PWD"
|
|
|
|
assert_equal "$stderr" ''
|
|
|
|
|
2024-01-26 01:43:54 +00:00
|
|
|
echo 'Checking that it respects TMPDIR...'
|
|
|
|
mkdir "$tmpdir/tmp"
|
|
|
|
TMPDIR="$tmpdir/tmp" _sudo osi-mount --root "$tmpdir/tst.img" "$tmpdir/mnt" env >"$tmpdir/env.txt"
|
|
|
|
cat -nv "$tmpdir/env.txt"
|
|
|
|
act=$(grep ^TMPDIR= "$tmpdir/env.txt")
|
|
|
|
assert_equal "${act%$'\r'}" "TMPDIR=$tmpdir/tmp"
|
|
|
|
|
2024-01-05 02:13:25 +00:00
|
|
|
echo "Checking that it can't write outside of the mountpoint..."
|
2024-01-26 01:43:54 +00:00
|
|
|
run --separate-stderr _sudo osi-mount --root "$tmpdir/tst.img" "$tmpdir/mnt" -- sh -c "echo foo>$tmpdir/x"
|
2024-01-05 02:13:25 +00:00
|
|
|
if [ -f "$tmpdir/x" ]; then
|
|
|
|
sudo rm -f -- "$tmpdir/x"
|
|
|
|
fi
|
|
|
|
assert_failure
|
|
|
|
assert_file_not_exists "$tmpdir/x"
|
|
|
|
|
|
|
|
echo 'Checking that it can write inside of the mountpoint...'
|
2024-01-26 01:43:54 +00:00
|
|
|
run --separate-stderr _sudo osi-mount --root "$tmpdir/tst.img" "$tmpdir/mnt" -- sh -c "echo bar>$tmpdir/mnt/y"
|
2024-01-05 02:13:25 +00:00
|
|
|
assert_success
|
|
|
|
assert_file_not_exists "$tmpdir/mnt/y"
|
2024-01-26 01:43:54 +00:00
|
|
|
run --separate-stderr _sudo osi-mount --user "$tmpdir/tst.img" "$tmpdir/mnt" -- cat "$tmpdir/mnt/y"
|
2024-01-05 02:13:25 +00:00
|
|
|
assert_success
|
|
|
|
assert_equal "${output%$'\r'}" 'bar'
|
|
|
|
}
|