# Copyright (C) 2024 Umorpha Systems # SPDX-License-Identifier: AGPL-3.0-or-later 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 } @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...' run --separate-stderr sudo osi-mount --user "$tmpdir/tst.img" "$tmpdir/mnt" pwd assert_success assert_equal "${output%$'\r'}" "$PWD" assert_equal "$stderr" '' echo 'Checking that it can write outside of the mountpoint...' run --separate-stderr sudo osi-mount --user "$tmpdir/tst.img" "$tmpdir/mnt" -- sh -c "echo foo>$tmpdir/x" 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..." run --separate-stderr sudo osi-mount --user "$tmpdir/tst.img" "$tmpdir/mnt" -- sh -c "echo bar>$tmpdir/mnt/y" 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...' run --separate-stderr sudo osi-mount --root "$tmpdir/tst.img" "$tmpdir/mnt" pwd assert_success assert_equal "${output%$'\r'}" "$PWD" assert_equal "$stderr" '' echo "Checking that it can't write outside of the mountpoint..." run --separate-stderr sudo osi-mount --root "$tmpdir/tst.img" "$tmpdir/mnt" -- sh -c "echo foo>$tmpdir/x" 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...' run --separate-stderr sudo osi-mount --root "$tmpdir/tst.img" "$tmpdir/mnt" -- sh -c "echo bar>$tmpdir/mnt/y" assert_success assert_file_not_exists "$tmpdir/mnt/y" run --separate-stderr sudo osi-mount --user "$tmpdir/tst.img" "$tmpdir/mnt" -- cat "$tmpdir/mnt/y" assert_success assert_equal "${output%$'\r'}" 'bar' }