blob: 091dccf743ce6aeb96448370ce37da4bb736eb28 [file] [log] [blame]
Divya Kotharief0ed682014-07-04 21:20:02 -05001#!/bin/bash
2# Copyright 2013 Divya Kothari <divya.s.kothari@gmail.com>
3# Copyright 2013 Robin Mittal <robinmittal.it@gmail.com>
4
5[ -f testing.sh ] && . testing.sh
6
7# 70 characters long string; hereafter, we will use it as per our need.
8_s70="abcdefghijklmnopqrstuvwxyz123456789abcdefghijklmnopqrstuvwxyz123456789"
9
10echo "# usage: addgroup [-g GID] [USER] GROUP
11# Add a group or add a user to a group."
12
13# Redirecting all output to /dev/null for grep and delgroup
14arg="&>/dev/null"
15
16#testing "name" "command" "result" "infile" "stdin"
17
Rob Landley336c44a2016-03-02 15:20:04 -060018testing "group_name (text)" "groupadd toyTestGroup &&
Divya Kotharief0ed682014-07-04 21:20:02 -050019 grep '^toyTestGroup:' /etc/group $arg && groupdel toyTestGroup $arg &&
20 echo 'yes'" "yes\n" "" ""
Rob Landley336c44a2016-03-02 15:20:04 -060021testing "group_name (alphanumeric)" "groupadd toy1Test2Group3 &&
Divya Kotharief0ed682014-07-04 21:20:02 -050022 grep '^toy1Test2Group3:' /etc/group $arg && groupdel toy1Test2Group3 $arg &&
23 echo 'yes'" "yes\n" "" ""
Rob Landley336c44a2016-03-02 15:20:04 -060024testing "group_name (numeric)" "groupadd 987654321 &&
Divya Kotharief0ed682014-07-04 21:20:02 -050025 grep '^987654321:' /etc/group $arg && groupdel 987654321 $arg &&
26 echo 'yes'" "yes\n" "" ""
Rob Landley336c44a2016-03-02 15:20:04 -060027testing "group_name (with ./-)" "groupadd toy.1Test-2Group.3 &&
Divya Kotharief0ed682014-07-04 21:20:02 -050028 grep '^toy.1Test-2Group.3:' /etc/group $arg &&
29 groupdel toy.1Test-2Group.3 $arg && echo 'yes'" "yes\n" "" ""
30
31_s210=`echo $_s70$_s70$_s70`
Rob Landley336c44a2016-03-02 15:20:04 -060032testing "group_name (long string)" "groupadd $_s210 &&
Divya Kotharief0ed682014-07-04 21:20:02 -050033 grep '^$_s210:' /etc/group $arg && groupdel $_s210 $arg && echo 'yes'" \
34 "yes\n" "" ""
Rob Landley336c44a2016-03-02 15:20:04 -060035testing "group_name with group_id" "groupadd -g 49999 toyTestGroup &&
Divya Kotharief0ed682014-07-04 21:20:02 -050036 grep '^toyTestGroup:' /etc/group $arg && groupdel toyTestGroup $arg &&
37 echo 'yes'" "yes\n" "" ""
Rob Landley336c44a2016-03-02 15:20:04 -060038testing "group_name with group_id (system_group)" \
Divya Kotharief0ed682014-07-04 21:20:02 -050039 "groupadd -g 49999 -S toyTestGroup && grep '^toyTestGroup:' /etc/group $arg &&
40 groupdel toyTestGroup $arg && echo 'yes'" "yes\n" "" ""
Rob Landley336c44a2016-03-02 15:20:04 -060041testing "group_name (system_group)" "groupadd -S toyTestGroup &&
Divya Kotharief0ed682014-07-04 21:20:02 -050042 grep '^toyTestGroup:' /etc/group $arg && groupdel toyTestGroup $arg &&
43 echo 'yes'" "yes\n" "" ""
Rob Landley336c44a2016-03-02 15:20:04 -060044testing "group_name (add/del user)" "groupadd toyTestGroup &&
Divya Kotharief0ed682014-07-04 21:20:02 -050045 grep '^toyTestGroup:' /etc/group $arg && groupadd $USER toyTestGroup &&
46 grep '^toyTestGroup:.*:.*:.*$USER.*' /etc/group $arg &&
47 groupdel $USER toyTestGroup $arg || groupdel toyTestGroup &&
48 grep '^toyTestGroup:' /etc/group $arg || echo 'yes'" "yes\n" "" ""
49
50 echo "Testing to add single group multiple times after removing it..."
51 for each in {01..20}
52 do
Rob Landley336c44a2016-03-02 15:20:04 -060053 testing "group_name ($each)" "groupadd toyTestGroup &&
Divya Kotharief0ed682014-07-04 21:20:02 -050054 grep '^toyTestGroup:' /etc/group $arg && groupdel toyTestGroup $arg &&
55 echo 'yes'" "yes\n" "" ""
56 done