Divya Kothari | ef0ed68 | 2014-07-04 21:20:02 -0500 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Copyright 2013 Divya Kothari <divya.s.kothari@gmail.com> |
| 4 | # Copyright 2013 Robin Mittal <robinmittal.it@gmail.com> |
| 5 | |
| 6 | [ -f testing.sh ] && . testing.sh |
| 7 | |
| 8 | # 70 characters long string; hereafter, we will use it as per our need. |
| 9 | _s70="abcdefghijklmnopqrstuvwxyz123456789abcdefghijklmnopqrstuvwxyz123456789" |
| 10 | |
| 11 | # Redirecting all output to /dev/null for grep, adduser and deluser |
| 12 | arg="&>/dev/null" |
| 13 | |
| 14 | #testing "name" "command" "result" "infile" "stdin" |
| 15 | |
| 16 | # Default password for adding user is: 'password' |
| 17 | pass=`echo -ne 'password\npassword\n'` |
| 18 | |
| 19 | testing "adduser user_name (text)" "useradd toyTestUser $arg || |
| 20 | grep '^toyTestUser:' /etc/passwd $arg && test -d /home/toyTestUser && |
| 21 | userdel toyTestUser $arg && rm -rf /home/toyTestUser && echo 'yes'" \ |
| 22 | "yes\n" "" "$pass" |
| 23 | |
| 24 | testing "adduser user_name (alphanumeric)" "useradd toy1Test2User3 $arg || |
| 25 | grep '^toy1Test2User3:' /etc/passwd $arg && test -d /home/toy1Test2User3 && |
| 26 | userdel toy1Test2User3 $arg && rm -rf /home/toy1Test2User3 && echo 'yes'" \ |
| 27 | "yes\n" "" "$pass" |
| 28 | |
| 29 | testing "adduser user_name (numeric)" "useradd 987654321 $arg || |
| 30 | grep '^987654321:' /etc/passwd $arg && test -d /home/987654321 && |
| 31 | userdel 987654321 $arg && rm -rf /home/987654321 && echo 'yes'" \ |
| 32 | "yes\n" "" "$pass" |
| 33 | |
| 34 | testing "adduser user_name (with ./-/_)" "useradd toy.1Test-2User_3 $arg || |
| 35 | grep '^toy.1Test-2User_3:' /etc/passwd $arg && |
| 36 | test -d /home/toy.1Test-2User_3 && userdel toy.1Test-2User_3 $arg && |
| 37 | rm -rf /home/toy.1Test-2User_3 && echo 'yes'" "yes\n" "" "$pass" |
| 38 | |
| 39 | testing "adduser user_name (long string)" "useradd $_s70 $arg || |
| 40 | grep '^$_s70:' /etc/passwd $arg && test -d /home/$_s70 && |
| 41 | userdel $_s70 $arg && rm -rf /home/$_s70 && echo 'yes'" "yes\n" "" "$pass" |
| 42 | |
| 43 | testing "adduser user_name with dir" "useradd -h $PWD/dir toyTestUser $arg || |
| 44 | grep '^toyTestUser:.*dir' /etc/passwd $arg && test -d $PWD/dir && |
| 45 | userdel toyTestUser $arg && rm -rf $PWD/dir && echo 'yes'" "yes\n" "" "$pass" |
| 46 | |
| 47 | gecos="aaa,bbb,ccc,ddd,eee" |
| 48 | testing "adduser user_name with gecos" "useradd -g '$gecos' toyTestUser $arg || |
| 49 | grep '^toyTestUser:.*$gecos' /etc/passwd $arg && test -d /home/toyTestUser && |
| 50 | userdel toyTestUser $arg && rm -rf /home/toyTestUser && echo 'yes'" \ |
| 51 | "yes\n" "" "$pass" |
| 52 | |
| 53 | shl="/bin/sh" |
| 54 | testing "adduser user_name with shell" "useradd -s $shl toyTestUser $arg || |
| 55 | grep '^toyTestUser:.*$shl$' /etc/passwd $arg && test -d /home/toyTestUser && |
| 56 | userdel toyTestUser $arg && rm -rf /home/toyTestUser && echo 'yes'" \ |
| 57 | "yes\n" "" "$pass" |
| 58 | |
| 59 | g_name="root" |
| 60 | g_id=`grep $g_name /etc/group | cut -d : -f 3` |
| 61 | testing "adduser user_name with group" "useradd -G $g_name toyTestUser $arg || |
| 62 | grep '^toyTestUser:.*:.*:$g_id:.*' /etc/passwd $arg && |
| 63 | test -d /home/toyTestUser && userdel toyTestUser $arg && |
| 64 | rm -rf /home/toyTestUser && echo 'yes'" "yes\n" "" "$pass" |
| 65 | |
| 66 | testing "adduser user_name (system user)" "useradd -S toyTestUser $arg || |
| 67 | grep '^toyTestUser:.*:.*:.*' /etc/passwd $arg && |
| 68 | test ! -e /home/toyTestUser && userdel toyTestUser $arg && echo 'yes'" \ |
| 69 | "yes\n" "" "$pass" |
| 70 | |
| 71 | testing "adduser user_name with -D" "useradd -D toyTestUser $arg || |
| 72 | grep '^toyTestUser:.*:.*:.*' /etc/passwd $arg && test -d /home/toyTestUser && |
| 73 | userdel toyTestUser $arg && rm -rf /home/toyTestUser && echo 'yes'" \ |
| 74 | "yes\n" "" "$pass" |
| 75 | |
| 76 | testing "adduser user_name with -H" "useradd -H toyTestUser $arg || |
| 77 | grep '^toyTestUser:.*:.*:.*' /etc/passwd $arg && |
| 78 | test ! -e /home/toyTestUser && userdel toyTestUser $arg && echo 'yes'" \ |
| 79 | "yes\n" "" "$pass" |
| 80 | |
| 81 | testing "adduser user_name with dir and -H" \ |
| 82 | "useradd -H -h $PWD/dir toyTestUser $arg || |
| 83 | grep '^toyTestUser:.*dir' /etc/passwd $arg && test ! -e $PWD/dir && |
| 84 | userdel toyTestUser $arg && echo 'yes'" "yes\n" "" "$pass" |
| 85 | |
| 86 | testing "adduser user_name with user_id" "useradd -u 49999 toyTestUser $arg || |
| 87 | grep '^toyTestUser:x:49999:.*' /etc/passwd $arg && |
| 88 | test -d /home/toyTestUser && userdel toyTestUser $arg && |
| 89 | rm -rf /home/toyTestUser && echo 'yes'" "yes\n" "" "$pass" |
| 90 | |