aboutsummaryrefslogtreecommitdiff
path: root/tests/chown.test
blob: 56eed81e03911fcb0694080cce9b345e790fba82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash

[ -f testing.sh ] && . testing.sh

if [ "$(id -u)" -ne 0 ]
then
  echo "$SHOWSKIP: chown (not root)"
  return 2>/dev/null
  exit
fi

# We chown between user "root" and the last user in /etc/passwd,
# and group "root" and the last group in /etc/group.

USR="$(sed -n '$s/:.*//p' /etc/passwd)"
GRP="$(sed -n '$s/:.*//p' /etc/group)"

# Set up a little testing hierarchy

rm -rf testdir &&
mkdir testdir &&
touch testdir/file
F=testdir/file

# Wrapper to reset groups and return results

OUT="&& echo \$(ls -l testdir/file | awk '{print \$3,\$4}')"

#testing "name" "command" "result" "infile" "stdin"

# Basic smoketest
testing "initial" "chown root:root $F $OUT" "root root\n" "" ""
testing "usr:grp" "chown $USR:$GRP $F $OUT" "$USR $GRP\n" "" ""
testing "root"    "chown root $F $OUT" "root $GRP\n" "" ""
# TODO: can we test "owner:"?
testing ":grp"    "chown root:root $F && chown :$GRP $F $OUT" \
    "root $GRP\n" "" ""
testing ":"       "chown $USR:$GRP $F && chown : $F $OUT" \
    "$USR $GRP\n" "" ""

rm -rf testdir