blob: 90b6501939b9b30d6538c1413515eb56ef231678 (
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
#!/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: useradd (not root)"
continue 2>/dev/null
exit
fi
# Redirecting all output to /dev/null for grep, adduser and deluser
arg="&>/dev/null"
#testing "name" "command" "result" "infile" "stdin"
# Default password for adding user is: 'password'
pass=`echo -ne 'password\npassword\n'`
user="toyTestUser"
testing "useradd (text)" "useradd $user $arg ||
grep '^$user:' /etc/passwd $arg && [ -d /home/$user ] &&
echo 'yes'" "yes\n" "" "$pass"
userdel -r $user $arg
user="toy1Test2User3"
testing "useradd (alphanumeric)" "useradd $user $arg ||
grep '^$user:' /etc/passwd $arg && [ -d /home/$user ] &&
echo 'yes'" "yes\n" "" "$pass"
userdel -r $user $arg
user="987654321"
testing "useradd (numeric)" "useradd $user $arg ||
grep '^$user:' /etc/passwd $arg && [ -d /home/$user ] &&
echo 'yes'" "yes\n" "" "$pass"
userdel -r $user $arg
user="toy.1Test-2User_3"
testing "useradd (with ./-/_)" "useradd $user $arg ||
grep '^$user:' /etc/passwd $arg && [ -d /home/$user ] &&
echo 'yes'" "yes\n" "" "$pass"
userdel -r $user $arg
# 70 characters long string; hereafter, we will use it as per our need.
user="abcdefghijklmnopqrstuvwxyz123456789abcdefghijklmnopqrstuvwxyz123456789"
testing "useradd (long string)" "useradd $user $arg ||
grep '^$user:' /etc/passwd $arg && [ -d /home/$user ] &&
echo 'yes'" "yes\n" "" "$pass"
userdel -r $user $arg
user="toyTestUser"
testing "useradd dir" "useradd -h $PWD/dir $user $arg ||
grep '^$user:.*dir' /etc/passwd $arg && [ -d $PWD/dir ] &&
echo 'yes'" "yes\n" "" "$pass"
userdel -r $user $arg
rm -rf $PWD/dir
gecos="aaa,bbb,ccc,ddd,eee"
testing "useradd gecos" "useradd -g '$gecos' $user $arg ||
grep '^$user:.*$gecos' /etc/passwd $arg && [ -d /home/$user ] &&
echo 'yes'" "yes\n" "" "$pass"
userdel -r $user $arg
shl="/bin/sh"
testing "useradd shell" "useradd -s $shl $user $arg ||
grep '^$user:.*$shl$' /etc/passwd $arg && [ -d /home/$user ] &&
echo 'yes'" "yes\n" "" "$pass"
userdel -r $user $arg
g_name="root"
g_id=`grep $g_name':.*:.*' /etc/group | cut -d : -f 3`
testing "useradd group" "useradd -G $g_name $user $arg ||
grep '^$user:.*:.*:$g_id:.*' /etc/passwd $arg && [ -d /home/$user ] &&
echo 'yes'" "yes\n" "" "$pass"
userdel -r $user $arg
testing "useradd (system user)" "useradd -S $user $arg ||
grep '^$user:.*:.*:.*' /etc/passwd $arg && [ ! -e /home/$user ] &&
echo 'yes'" "yes\n" "" "$pass"
userdel -r $user $arg
testing "useradd -D" "useradd -D $user $arg ||
grep '^$user:.*:.*:.*' /etc/passwd $arg && [ -d /home/$user ] &&
echo 'yes'" "yes\n" "" "$pass"
userdel -r $user $arg
testing "useradd -H" "useradd -H $user $arg ||
grep '^$user:.*:.*:.*' /etc/passwd $arg && [ ! -e /home/$user ] &&
echo 'yes'" "yes\n" "" "$pass"
userdel -r $user $arg
testing "useradd dir and -H" "useradd -H -h $PWD/dir $user $arg ||
grep '^$user:.*dir' /etc/passwd $arg && [ ! -e $PWD/dir ] &&
echo 'yes'" "yes\n" "" "$pass"
userdel -r $user $arg
testing "useradd -u" "useradd -u 49999 $user $arg ||
grep '^$user:x:49999:.*' /etc/passwd $arg && [ -d /home/$user ] &&
echo 'yes'" "yes\n" "" "$pass"
userdel -r $user $arg
|