Mercurial > hg > toybox
comparison tests/useradd.test @ 1700:3b62d24bfa27 draft
Separate 'userdel' from testing syntax.
When I test toybox with toybox/tests/*.test scripts,
I got many false FAILs from it. So, I tried to fix useradd.test file.
author | Yeongdeok Suh <skyducks111@gmail.com> |
---|---|
date | Wed, 18 Feb 2015 13:06:26 -0600 |
parents | 8700cbe1cb29 |
children | 23acd6af27e4 |
comparison
equal
deleted
inserted
replaced
1699:dee053b7c775 | 1700:3b62d24bfa27 |
---|---|
3 # Copyright 2013 Divya Kothari <divya.s.kothari@gmail.com> | 3 # Copyright 2013 Divya Kothari <divya.s.kothari@gmail.com> |
4 # Copyright 2013 Robin Mittal <robinmittal.it@gmail.com> | 4 # Copyright 2013 Robin Mittal <robinmittal.it@gmail.com> |
5 | 5 |
6 [ -f testing.sh ] && . testing.sh | 6 [ -f testing.sh ] && . testing.sh |
7 | 7 |
8 # 70 characters long string; hereafter, we will use it as per our need. | 8 if [ "$(id -u)" -ne 0 ] |
9 _s70="abcdefghijklmnopqrstuvwxyz123456789abcdefghijklmnopqrstuvwxyz123456789" | 9 then |
10 echo "SKIPPED: chgrp (not root)" | |
11 continue 2>/dev/null | |
12 exit | |
13 fi | |
10 | 14 |
11 # Redirecting all output to /dev/null for grep, adduser and deluser | 15 # Redirecting all output to /dev/null for grep, adduser and deluser |
12 arg="&>/dev/null" | 16 arg="&>/dev/null" |
13 | 17 |
14 #testing "name" "command" "result" "infile" "stdin" | 18 #testing "name" "command" "result" "infile" "stdin" |
15 | 19 |
16 # Default password for adding user is: 'password' | 20 # Default password for adding user is: 'password' |
17 pass=`echo -ne 'password\npassword\n'` | 21 pass=`echo -ne 'password\npassword\n'` |
18 | 22 |
19 testing "adduser user_name (text)" "useradd toyTestUser $arg || | 23 user="toyTestUser" |
20 grep '^toyTestUser:' /etc/passwd $arg && test -d /home/toyTestUser && | 24 testing "adduser user_name (text)" "useradd $user $arg || |
21 userdel toyTestUser $arg && rm -rf /home/toyTestUser && echo 'yes'" \ | 25 grep '^$user:' /etc/passwd $arg && [ -d /home/$user ] && |
22 "yes\n" "" "$pass" | 26 echo 'yes'" "yes\n" "" "$pass" |
27 userdel -r $user $arg | |
23 | 28 |
24 testing "adduser user_name (alphanumeric)" "useradd toy1Test2User3 $arg || | 29 user="toy1Test2User3" |
25 grep '^toy1Test2User3:' /etc/passwd $arg && test -d /home/toy1Test2User3 && | 30 testing "adduser user_name (alphanumeric)" "useradd $user $arg || |
26 userdel toy1Test2User3 $arg && rm -rf /home/toy1Test2User3 && echo 'yes'" \ | 31 grep '^$user:' /etc/passwd $arg && [ -d /home/$user ] && |
27 "yes\n" "" "$pass" | 32 echo 'yes'" "yes\n" "" "$pass" |
33 userdel -r $user $arg | |
28 | 34 |
29 testing "adduser user_name (numeric)" "useradd 987654321 $arg || | 35 user="987654321" |
30 grep '^987654321:' /etc/passwd $arg && test -d /home/987654321 && | 36 testing "adduser user_name (numeric)" "useradd $user $arg || |
31 userdel 987654321 $arg && rm -rf /home/987654321 && echo 'yes'" \ | 37 grep '^$user:' /etc/passwd $arg && [ -d /home/$user ] && |
32 "yes\n" "" "$pass" | 38 echo 'yes'" "yes\n" "" "$pass" |
39 userdel -r $user $arg | |
33 | 40 |
34 testing "adduser user_name (with ./-/_)" "useradd toy.1Test-2User_3 $arg || | 41 user="toy.1Test-2User_3" |
35 grep '^toy.1Test-2User_3:' /etc/passwd $arg && | 42 testing "adduser user_name (with ./-/_)" "useradd $user $arg || |
36 test -d /home/toy.1Test-2User_3 && userdel toy.1Test-2User_3 $arg && | 43 grep '^$user:' /etc/passwd $arg && [ -d /home/$user ] && |
37 rm -rf /home/toy.1Test-2User_3 && echo 'yes'" "yes\n" "" "$pass" | 44 echo 'yes'" "yes\n" "" "$pass" |
45 userdel -r $user $arg | |
38 | 46 |
39 testing "adduser user_name (long string)" "useradd $_s70 $arg || | 47 # 70 characters long string; hereafter, we will use it as per our need. |
40 grep '^$_s70:' /etc/passwd $arg && test -d /home/$_s70 && | 48 user="abcdefghijklmnopqrstuvwxyz123456789abcdefghijklmnopqrstuvwxyz123456789" |
41 userdel $_s70 $arg && rm -rf /home/$_s70 && echo 'yes'" "yes\n" "" "$pass" | 49 testing "adduser user_name (long string)" "useradd $user $arg || |
50 grep '^$user:' /etc/passwd $arg && [ -d /home/$user ] && | |
51 echo 'yes'" "yes\n" "" "$pass" | |
52 userdel -r $user $arg | |
42 | 53 |
43 testing "adduser user_name with dir" "useradd -h $PWD/dir toyTestUser $arg || | 54 user="toyTestUser" |
44 grep '^toyTestUser:.*dir' /etc/passwd $arg && test -d $PWD/dir && | 55 testing "adduser user_name with dir" "useradd -h $PWD/dir $user $arg || |
45 userdel toyTestUser $arg && rm -rf $PWD/dir && echo 'yes'" "yes\n" "" "$pass" | 56 grep '^$user:.*dir' /etc/passwd $arg && [ -d $PWD/dir ] && |
57 echo 'yes'" "yes\n" "" "$pass" | |
58 userdel -r $user $arg | |
59 rm -rf $PWD/dir | |
46 | 60 |
47 gecos="aaa,bbb,ccc,ddd,eee" | 61 gecos="aaa,bbb,ccc,ddd,eee" |
48 testing "adduser user_name with gecos" "useradd -g '$gecos' toyTestUser $arg || | 62 testing "adduser user_name with gecos" "useradd -g '$gecos' $user $arg || |
49 grep '^toyTestUser:.*$gecos' /etc/passwd $arg && test -d /home/toyTestUser && | 63 grep '^$user:.*$gecos' /etc/passwd $arg && [ -d /home/$user ] && |
50 userdel toyTestUser $arg && rm -rf /home/toyTestUser && echo 'yes'" \ | 64 echo 'yes'" "yes\n" "" "$pass" |
51 "yes\n" "" "$pass" | 65 userdel -r $user $arg |
52 | 66 |
53 shl="/bin/sh" | 67 shl="/bin/sh" |
54 testing "adduser user_name with shell" "useradd -s $shl toyTestUser $arg || | 68 testing "adduser user_name with shell" "useradd -s $shl $user $arg || |
55 grep '^toyTestUser:.*$shl$' /etc/passwd $arg && test -d /home/toyTestUser && | 69 grep '^$user:.*$shl$' /etc/passwd $arg && [ -d /home/$user ] && |
56 userdel toyTestUser $arg && rm -rf /home/toyTestUser && echo 'yes'" \ | 70 echo 'yes'" "yes\n" "" "$pass" |
57 "yes\n" "" "$pass" | 71 userdel -r $user $arg |
58 | 72 |
59 g_name="root" | 73 g_name="root" |
60 g_id=`grep $g_name /etc/group | cut -d : -f 3` | 74 g_id=`grep $g_name':.*:.*' /etc/group | cut -d : -f 3` |
61 testing "adduser user_name with group" "useradd -G $g_name toyTestUser $arg || | 75 testing "adduser user_name with group" "useradd -G $g_name $user $arg || |
62 grep '^toyTestUser:.*:.*:$g_id:.*' /etc/passwd $arg && | 76 grep '^$user:.*:.*:$g_id:.*' /etc/passwd $arg && [ -d /home/$user ] && |
63 test -d /home/toyTestUser && userdel toyTestUser $arg && | 77 echo 'yes'" "yes\n" "" "$pass" |
64 rm -rf /home/toyTestUser && echo 'yes'" "yes\n" "" "$pass" | 78 userdel -r $user $arg |
65 | 79 |
66 testing "adduser user_name (system user)" "useradd -S toyTestUser $arg || | 80 testing "adduser user_name (system user)" "useradd -S $user $arg || |
67 grep '^toyTestUser:.*:.*:.*' /etc/passwd $arg && | 81 grep '^$user:.*:.*:.*' /etc/passwd $arg && [ ! -e /home/$user ] && |
68 test ! -e /home/toyTestUser && userdel toyTestUser $arg && echo 'yes'" \ | 82 echo 'yes'" "yes\n" "" "$pass" |
69 "yes\n" "" "$pass" | 83 userdel -r $user $arg |
70 | 84 |
71 testing "adduser user_name with -D" "useradd -D toyTestUser $arg || | 85 testing "adduser user_name with -D" "useradd -D $user $arg || |
72 grep '^toyTestUser:.*:.*:.*' /etc/passwd $arg && test -d /home/toyTestUser && | 86 grep '^$user:.*:.*:.*' /etc/passwd $arg && [ -d /home/$user ] && |
73 userdel toyTestUser $arg && rm -rf /home/toyTestUser && echo 'yes'" \ | 87 echo 'yes'" "yes\n" "" "$pass" |
74 "yes\n" "" "$pass" | 88 userdel -r $user $arg |
75 | 89 |
76 testing "adduser user_name with -H" "useradd -H toyTestUser $arg || | 90 testing "adduser user_name with -H" "useradd -H $user $arg || |
77 grep '^toyTestUser:.*:.*:.*' /etc/passwd $arg && | 91 grep '^$user:.*:.*:.*' /etc/passwd $arg && [ ! -e /home/$user ] && |
78 test ! -e /home/toyTestUser && userdel toyTestUser $arg && echo 'yes'" \ | 92 echo 'yes'" "yes\n" "" "$pass" |
79 "yes\n" "" "$pass" | 93 userdel -r $user $arg |
80 | 94 |
81 testing "adduser user_name with dir and -H" \ | 95 testing "adduser user_name with dir and -H" "useradd -H -h $PWD/dir $user $arg || |
82 "useradd -H -h $PWD/dir toyTestUser $arg || | 96 grep '^$user:.*dir' /etc/passwd $arg && [ ! -e $PWD/dir ] && |
83 grep '^toyTestUser:.*dir' /etc/passwd $arg && test ! -e $PWD/dir && | 97 echo 'yes'" "yes\n" "" "$pass" |
84 userdel toyTestUser $arg && echo 'yes'" "yes\n" "" "$pass" | 98 userdel -r $user $arg |
85 | 99 |
86 testing "adduser user_name with user_id" "useradd -u 49999 toyTestUser $arg || | 100 testing "adduser user_name with user_id" "useradd -u 49999 $user $arg || |
87 grep '^toyTestUser:x:49999:.*' /etc/passwd $arg && | 101 grep '^$user:x:49999:.*' /etc/passwd $arg && [ -d /home/$user ] && |
88 test -d /home/toyTestUser && userdel toyTestUser $arg && | 102 echo 'yes'" "yes\n" "" "$pass" |
89 rm -rf /home/toyTestUser && echo 'yes'" "yes\n" "" "$pass" | 103 userdel -r $user $arg |
90 | 104 |