chown.test 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/bin/bash
  2. [ -f testing.sh ] && . testing.sh
  3. if [ "$(id -u)" -ne 0 ]
  4. then
  5. echo "$SHOWSKIP: chown (not root)"
  6. return 2>/dev/null
  7. exit
  8. fi
  9. # We chown between user "root" and the last user in /etc/passwd,
  10. # and group "root" and the last group in /etc/group.
  11. USR="$(sed -n '$s/:.*//p' /etc/passwd)"
  12. GRP="$(sed -n '$s/:.*//p' /etc/group)"
  13. # Or if that fails, we assume we're on Android...
  14. : "${USR:=shell}"
  15. : "${GRP:=daemon}"
  16. # Set up a little testing hierarchy
  17. rm -rf testdir &&
  18. mkdir testdir &&
  19. touch testdir/file
  20. F=testdir/file
  21. # Wrapper to reset groups and return results
  22. OUT="&& stat --format '%U %G' $F"
  23. #testing "name" "command" "result" "infile" "stdin"
  24. # Basic smoketest
  25. testing "initial" "chown root:root $F $OUT" "root root\n" "" ""
  26. testing "usr:grp" "chown $USR:$GRP $F $OUT" "$USR $GRP\n" "" ""
  27. testing "root" "chown root $F $OUT" "root $GRP\n" "" ""
  28. # TODO: can we test "owner:"?
  29. testing ":grp" "chown root:root $F && chown :$GRP $F $OUT" \
  30. "root $GRP\n" "" ""
  31. testing ":" "chown $USR:$GRP $F && chown : $F $OUT" \
  32. "$USR $GRP\n" "" ""
  33. rm -rf testdir