Home | History | Annotate | Download | only in tests
      1 #!/bin/bash
      2 
      3 [ -f testing.sh ] && . testing.sh
      4 
      5 if [ "$(id -u)" -ne 0 ]
      6 then
      7   echo "$SHOWSKIP: chown (not root)"
      8   continue 2>/dev/null
      9   exit
     10 fi
     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.
     14 
     15 USR="$(sed -n '$s/:.*//p' /etc/passwd)"
     16 GRP="$(sed -n '$s/:.*//p' /etc/group)"
     17 
     18 # Set up a little testing hierarchy
     19 
     20 rm -rf testdir &&
     21 mkdir testdir &&
     22 touch testdir/file
     23 F=testdir/file
     24 
     25 # Wrapper to reset groups and return results
     26 
     27 OUT="&& echo \$(ls -l testdir/file | awk '{print \$3,\$4}')"
     28 
     29 #testing "name" "command" "result" "infile" "stdin"
     30 
     31 # Basic smoketest
     32 testing "initial" "chown root:root $F $OUT" "root root\n" "" ""
     33 testing "usr:grp" "chown $USR:$GRP $F $OUT" "$USR $GRP\n" "" ""
     34 testing "root"    "chown root $F $OUT" "root $GRP\n" "" ""
     35 # TODO: can we test "owner:"?
     36 testing ":grp"    "chown root:root $F && chown :$GRP $F $OUT" \
     37     "root $GRP\n" "" ""
     38 testing ":"       "chown $USR:$GRP $F && chown : $F $OUT" \
     39     "$USR $GRP\n" "" ""
     40 
     41 rm -rf testdir
     42