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