aboutsummaryrefslogtreecommitdiff
path: root/tests/groupadd.test
blob: 6161ee2f1fee912df472bca1aa8e284902a0fcf4 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
# Copyright 2013 Divya Kothari <divya.s.kothari@gmail.com>
# Copyright 2013 Robin Mittal <robinmittal.it@gmail.com>

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

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

# 70 characters long string; hereafter, we will use it as per our need.
_s70="abcdefghijklmnopqrstuvwxyz123456789abcdefghijklmnopqrstuvwxyz123456789"

echo "# usage: addgroup [-g GID] [USER] GROUP
# Add a group or add a user to a group."

# Redirecting all output to /dev/null for grep and delgroup
arg="&>/dev/null"

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

testing "group_name (text)" "groupadd toyTestGroup &&
   grep '^toyTestGroup:' /etc/group $arg && groupdel toyTestGroup $arg &&
   echo 'yes'" "yes\n" "" ""
testing "group_name (alphanumeric)" "groupadd toy1Test2Group3 &&
   grep '^toy1Test2Group3:' /etc/group $arg && groupdel toy1Test2Group3 $arg &&
   echo 'yes'" "yes\n" "" ""
testing "group_name (numeric)" "groupadd 987654321 &&
   grep '^987654321:' /etc/group $arg && groupdel 987654321 $arg &&
   echo 'yes'" "yes\n" "" ""
testing "group_name (with ./-)" "groupadd toy.1Test-2Group.3 &&
   grep '^toy.1Test-2Group.3:' /etc/group $arg &&
   groupdel toy.1Test-2Group.3 $arg && echo 'yes'" "yes\n" "" ""

_s210=`echo $_s70$_s70$_s70`
testing "group_name (long string)" "groupadd $_s210 &&
   grep '^$_s210:' /etc/group $arg && groupdel $_s210 $arg && echo 'yes'" \
  "yes\n" "" ""
testing "group_name with group_id" "groupadd -g 49999 toyTestGroup &&
   grep '^toyTestGroup:' /etc/group $arg && groupdel toyTestGroup $arg &&
   echo 'yes'" "yes\n" "" ""
testing "group_name with group_id (system_group)" \
  "groupadd -g 49999 -S toyTestGroup && grep '^toyTestGroup:' /etc/group $arg &&
   groupdel toyTestGroup $arg && echo 'yes'" "yes\n" "" ""
testing "group_name (system_group)" "groupadd -S toyTestGroup &&
   grep '^toyTestGroup:' /etc/group $arg && groupdel toyTestGroup $arg &&
   echo 'yes'" "yes\n" "" ""
testing "group_name (add/del user)" "groupadd toyTestGroup &&
   grep '^toyTestGroup:' /etc/group $arg && groupadd $USER toyTestGroup &&
   grep '^toyTestGroup:.*:.*:.*$USER.*' /etc/group $arg &&
   groupdel $USER toyTestGroup $arg || groupdel toyTestGroup &&
   grep '^toyTestGroup:' /etc/group $arg || echo 'yes'" "yes\n" "" ""

 echo "Testing to add single group multiple times after removing it..."
 for each in {01..20}
 do
   testing "group_name ($each)" "groupadd toyTestGroup &&
      grep '^toyTestGroup:' /etc/group $arg && groupdel toyTestGroup $arg &&
      echo 'yes'" "yes\n" "" ""
 done