comparison scripts/test/chmod.test @ 1377:7a2aec0876fe draft

I have developed few testsuites for toybox commands - 1. lsattr/chattr 2. mount 3. chmod 4. pgrep/pkill 5. groupadd 6. groupdel 7. useradd
author Divya Kothari <divya.s.kothari@gmail.com>
date Fri, 04 Jul 2014 21:20:02 -0500
parents
children 6c54196fce62
comparison
equal deleted inserted replaced
1376:7dd487ddd7dc 1377:7a2aec0876fe
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 #testing "name" "command" "result" "infile" "stdin"
7
8 declare -a StrForMod=('---' '--x' '-w-' '-wx' 'r--' 'r-x' 'rw-' 'rwx')
9 #StrForMod[0]='---'
10 #StrForMod[1]='--x'
11 #StrForMod[2]='-w-'
12 #StrForMod[3]='-wx'
13 #StrForMod[4]='r--'
14 #StrForMod[5]='r-x'
15 #StrForMod[6]='rw-'
16 #StrForMod[7]='rwx'
17
18 # Creating test files to test chmod command
19 mkdir dir
20 touch file
21
22 for u in {0..7}
23 do
24 for g in {0..7}
25 do
26 for o in {0..7}
27 do
28 rm -rf dir && mkdir dir
29 uu=${StrForMod[$u]}
30 gg=${StrForMod[$g]}
31 oo=${StrForMod[$o]}
32 testing "chmod $u$g$o dir" "chmod $u$g$o dir &&
33 ls -ld dir | cut -d' ' -f 1" "d$uu$gg$oo\n" "" ""
34 done
35 done
36 done
37
38 for u in {0..7}
39 do
40 for g in {0..7}
41 do
42 for o in {0..7}
43 do
44 rm -rf file && touch file
45 uu=${StrForMod[$u]}
46 gg=${StrForMod[$g]}
47 oo=${StrForMod[$o]}
48 testing "chmod $u$g$o file" "chmod $u$g$o file &&
49 ls -ld file | cut -d' ' -f 1" "-$uu$gg$oo\n" "" ""
50 done
51 done
52 done
53
54 rm -rf dir file && mkdir dir && touch file
55 testing "chmod 750 dir 640 file" \
56 "chmod 750 dir 640 file 2>/dev/null ||
57 ls -ld dir file | cut -d' ' -f 1" "drwxr-x---\n-rwxr-x---\n" "" ""
58
59 rm -rf dir file && mkdir dir && touch file
60 testing "chmod 666 dir file" \
61 "chmod 666 dir file &&
62 ls -ld dir file | cut -d' ' -f 1" "drw-rw-rw-\n-rw-rw-rw-\n" "" ""
63
64 rm -rf dir file && mkdir dir && touch file
65 testing "chmod 765 *" "chmod 765 * &&
66 ls -ld dir file | cut -d' ' -f 1" "drwxrw-r-x\n-rwxrw-r-x\n" "" ""
67
68 ##### u,g,o,a=r,w,x
69 rm -rf dir file && mkdir dir && touch file
70 testing "chmod u=r dir file" "chmod u=r dir file &&
71 ls -ld dir file | cut -d' ' -f 1" "dr--r-xr-x\n-r--r--r--\n" "" ""
72
73 rm -rf dir file && mkdir dir && touch file
74 testing "chmod u=w dir file" "chmod u=w dir file &&
75 ls -ld dir file | cut -d' ' -f 1" "d-w-r-xr-x\n--w-r--r--\n" "" ""
76
77 rm -rf dir file && mkdir dir && touch file
78 testing "chmod u=x dir file" "chmod u=x dir file &&
79 ls -ld dir file | cut -d' ' -f 1" "d--xr-xr-x\n---xr--r--\n" "" ""
80
81 rm -rf dir file && mkdir dir && touch file
82 testing "chmod u+r dir file" "chmod u+r dir file &&
83 ls -ld dir file | cut -d' ' -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
84
85 rm -rf dir file && mkdir dir && touch file
86 testing "chmod u+w dir file" "chmod u+w dir file &&
87 ls -ld dir file | cut -d' ' -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
88
89 rm -rf dir file && mkdir dir && touch file
90 testing "chmod u+x dir file" "chmod u+x dir file &&
91 ls -ld dir file | cut -d' ' -f 1" "drwxr-xr-x\n-rwxr--r--\n" "" ""
92
93 rm -rf dir file && mkdir dir && touch file
94 testing "chmod u-r dir file" "chmod u-r dir file &&
95 ls -ld dir file | cut -d' ' -f 1" "d-wxr-xr-x\n--w-r--r--\n" "" ""
96
97 rm -rf dir file && mkdir dir && touch file
98 testing "chmod u-w dir file" "chmod u-w dir file &&
99 ls -ld dir file | cut -d' ' -f 1" "dr-xr-xr-x\n-r--r--r--\n" "" ""
100
101 rm -rf dir file && mkdir dir && touch file
102 testing "chmod u-x dir file" "chmod u-x dir file &&
103 ls -ld dir file | cut -d' ' -f 1" "drw-r-xr-x\n-rw-r--r--\n" "" ""
104
105 rm -rf dir file && mkdir dir && touch file
106 testing "chmod g=r dir file" "chmod g=r dir file &&
107 ls -ld dir file | cut -d' ' -f 1" "drwxr--r-x\n-rw-r--r--\n" "" ""
108
109 rm -rf dir file && mkdir dir && touch file
110 testing "chmod g=w dir file" "chmod g=w dir file &&
111 ls -ld dir file | cut -d' ' -f 1" "drwx-w-r-x\n-rw--w-r--\n" "" ""
112
113 rm -rf dir file && mkdir dir && touch file
114 testing "chmod g=x dir file" "chmod g=x dir file &&
115 ls -ld dir file | cut -d' ' -f 1" "drwx--xr-x\n-rw---xr--\n" "" ""
116
117 rm -rf dir file && mkdir dir && touch file
118 testing "chmod g+r dir file" "chmod g+r dir file &&
119 ls -ld dir file | cut -d' ' -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
120
121 rm -rf dir file && mkdir dir && touch file
122 testing "chmod g+w dir file" "chmod g+w dir file &&
123 ls -ld dir file | cut -d' ' -f 1" "drwxrwxr-x\n-rw-rw-r--\n" "" ""
124
125 rm -rf dir file && mkdir dir && touch file
126 testing "chmod g+x dir file" "chmod g+x dir file &&
127 ls -ld dir file | cut -d' ' -f 1" "drwxr-xr-x\n-rw-r-xr--\n" "" ""
128
129 rm -rf dir file && mkdir dir && touch file
130 testing "chmod g-r dir file" "chmod g-r dir file &&
131 ls -ld dir file | cut -d' ' -f 1" "drwx--xr-x\n-rw----r--\n" "" ""
132
133 rm -rf dir file && mkdir dir && touch file
134 testing "chmod g-w dir file" "chmod g-w dir file &&
135 ls -ld dir file | cut -d' ' -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
136
137 rm -rf dir file && mkdir dir && touch file
138 testing "chmod g-x dir file" "chmod g-x dir file &&
139 ls -ld dir file | cut -d' ' -f 1" "drwxr--r-x\n-rw-r--r--\n" "" ""
140
141 rm -rf dir file && mkdir dir && touch file
142 testing "chmod o=r dir file" "chmod o=r dir file &&
143 ls -ld dir file | cut -d' ' -f 1" "drwxr-xr--\n-rw-r--r--\n" "" ""
144
145 rm -rf dir file && mkdir dir && touch file
146 testing "chmod o=w dir file" "chmod o=w dir file &&
147 ls -ld dir file | cut -d' ' -f 1" "drwxr-x-w-\n-rw-r---w-\n" "" ""
148
149 rm -rf dir file && mkdir dir && touch file
150 testing "chmod o=x dir file" "chmod o=x dir file &&
151 ls -ld dir file | cut -d' ' -f 1" "drwxr-x--x\n-rw-r----x\n" "" ""
152
153 rm -rf dir file && mkdir dir && touch file
154 testing "chmod o+r dir file" "chmod o+r dir file &&
155 ls -ld dir file | cut -d' ' -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
156
157 rm -rf dir file && mkdir dir && touch file
158 testing "chmod o+w dir file" "chmod o+w dir file &&
159 ls -ld dir file | cut -d' ' -f 1" "drwxr-xrwx\n-rw-r--rw-\n" "" ""
160
161 rm -rf dir file && mkdir dir && touch file
162 testing "chmod o+x dir file" "chmod o+x dir file &&
163 ls -ld dir file | cut -d' ' -f 1" "drwxr-xr-x\n-rw-r--r-x\n" "" ""
164
165 rm -rf dir file && mkdir dir && touch file
166 testing "chmod o-r dir file" "chmod o-r dir file &&
167 ls -ld dir file | cut -d' ' -f 1" "drwxr-x--x\n-rw-r-----\n" "" ""
168
169 rm -rf dir file && mkdir dir && touch file
170 testing "chmod o-w dir file" "chmod o-w dir file &&
171 ls -ld dir file | cut -d' ' -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
172
173 rm -rf dir file && mkdir dir && touch file
174 testing "chmod o-x dir file" "chmod o-x dir file &&
175 ls -ld dir file | cut -d' ' -f 1" "drwxr-xr--\n-rw-r--r--\n" "" ""
176
177 rm -rf dir file && mkdir dir && touch file
178 testing "chmod a=r dir file" "chmod a=r dir file &&
179 ls -ld dir file | cut -d' ' -f 1" "dr--r--r--\n-r--r--r--\n" "" ""
180
181 rm -rf dir file && mkdir dir && touch file
182 testing "chmod a=w dir file" "chmod a=w dir file &&
183 ls -ld dir file | cut -d' ' -f 1" "d-w--w--w-\n--w--w--w-\n" "" ""
184
185 rm -rf dir file && mkdir dir && touch file
186 testing "chmod a=x dir file" "chmod a=x dir file &&
187 ls -ld dir file | cut -d' ' -f 1" "d--x--x--x\n---x--x--x\n" "" ""
188
189 rm -rf dir file && mkdir dir && touch file
190 testing "chmod a+r dir file" "chmod a+r dir file &&
191 ls -ld dir file | cut -d' ' -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
192
193 rm -rf dir file && mkdir dir && touch file
194 testing "chmod a+w dir file" "chmod a+w dir file &&
195 ls -ld dir file | cut -d' ' -f 1" "drwxrwxrwx\n-rw-rw-rw-\n" "" ""
196
197 rm -rf dir file && mkdir dir && touch file
198 testing "chmod a+x dir file" "chmod a+x dir file &&
199 ls -ld dir file | cut -d' ' -f 1" "drwxr-xr-x\n-rwxr-xr-x\n" "" ""
200
201 rm -rf dir file && mkdir dir && touch file
202 testing "chmod a-r dir file" "chmod a-r dir file &&
203 ls -ld dir file | cut -d' ' -f 1" "d-wx--x--x\n--w-------\n" "" ""
204
205 rm -rf dir file && mkdir dir && touch file
206 testing "chmod a-w dir file" "chmod a-w dir file &&
207 ls -ld dir file | cut -d' ' -f 1" "dr-xr-xr-x\n-r--r--r--\n" "" ""
208
209 rm -rf dir file && mkdir dir && touch file
210 testing "chmod a-x dir file" "chmod a-x dir file &&
211 ls -ld dir file | cut -d' ' -f 1" "drw-r--r--\n-rw-r--r--\n" "" ""
212
213 rm -rf dir file && mkdir dir && touch file
214 testing "chmod =r dir file" "chmod =r dir file &&
215 ls -ld dir file | cut -d' ' -f 1" "dr--r--r--\n-r--r--r--\n" "" ""
216
217 rm -rf dir file && mkdir dir && touch file
218 testing "chmod =w dir file" "chmod =w dir file &&
219 ls -ld dir file | cut -d' ' -f 1" "d-w-------\n--w-------\n" "" ""
220
221 rm -rf dir file && mkdir dir && touch file
222 testing "chmod =x dir file" "chmod =x dir file &&
223 ls -ld dir file | cut -d' ' -f 1" "d--x--x--x\n---x--x--x\n" "" ""
224
225 rm -rf dir file && mkdir dir && touch file
226 testing "chmod +r dir file" "chmod +r dir file &&
227 ls -ld dir file | cut -d' ' -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
228
229 rm -rf dir file && mkdir dir && touch file
230 testing "chmod +w dir file" "chmod +w dir file &&
231 ls -ld dir file | cut -d' ' -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
232
233 rm -rf dir file && mkdir dir && touch file
234 testing "chmod +x dir file" "chmod +x dir file &&
235 ls -ld dir file | cut -d' ' -f 1" "drwxr-xr-x\n-rwxr-xr-x\n" "" ""
236
237 rm -rf dir file && mkdir dir && touch file
238 testing "chmod -r dir file" "chmod -r dir file &&
239 ls -ld dir file | cut -d' ' -f 1" "d-wx--x--x\n--w-------\n" "" ""
240
241 rm -rf dir file && mkdir dir && touch file
242 testing "chmod -w dir file" "chmod -w dir file &&
243 ls -ld dir file | cut -d' ' -f 1" "dr-xr-xr-x\n-r--r--r--\n" "" ""
244
245 rm -rf dir file && mkdir dir && touch file
246 testing "chmod -x dir file" "chmod -x dir file &&
247 ls -ld dir file | cut -d' ' -f 1" "drw-r--r--\n-rw-r--r--\n" "" ""
248
249 # Removing test files for cleanup purpose
250 rm -rf dir file