blob: 95ad727a933492af14b4b97ec6b15029cd921fe8 [file] [log] [blame]
Elliott Hughes50d32072015-01-14 03:43:49 -06001#!/bin/bash
2
3[ -f testing.sh ] && . testing.sh
4
5if [ "$(id -u)" -ne 0 ]
6then
Rob Landley3f3049c2016-01-31 16:28:43 -06007 echo "$SHOWSKIP: chown (not root)"
Elliott Hughes50d32072015-01-14 03:43:49 -06008 continue 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.
14
15USR="$(sed -n '$s/:.*//p' /etc/passwd)"
16GRP="$(sed -n '$s/:.*//p' /etc/group)"
17
18# Set up a little testing hierarchy
19
20rm -rf testdir &&
21mkdir testdir &&
22touch testdir/file
23F=testdir/file
24
25# Wrapper to reset groups and return results
26
27OUT="&& echo \$(ls -l testdir/file | awk '{print \$3,\$4}')"
28
29#testing "name" "command" "result" "infile" "stdin"
30
31# Basic smoketest
Rob Landley336c44a2016-03-02 15:20:04 -060032testing "initial" "chown root:root $F $OUT" "root root\n" "" ""
33testing "usr:grp" "chown $USR:$GRP $F $OUT" "$USR $GRP\n" "" ""
34testing "root" "chown root $F $OUT" "root $GRP\n" "" ""
Elliott Hughes50d32072015-01-14 03:43:49 -060035# TODO: can we test "owner:"?
Rob Landley336c44a2016-03-02 15:20:04 -060036testing ":grp" "chown root:root $F && chown :$GRP $F $OUT" \
Elliott Hughes50d32072015-01-14 03:43:49 -060037 "root $GRP\n" "" ""
Rob Landley336c44a2016-03-02 15:20:04 -060038testing ":" "chown $USR:$GRP $F && chown : $F $OUT" \
Elliott Hughes50d32072015-01-14 03:43:49 -060039 "$USR $GRP\n" "" ""
40
41rm -rf testdir