annotate tests/useradd.test @ 1499:319e79bab052 draft

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