1# Before `make install' is performed this script should be runnable with
2# `make test'. After `make install' it should work as `perl test.pl'
3
4# $Id: test.pl,v 1.4 2000/05/02 16:07:48 ssnodgra Exp $
5
6######################### We start with some black magic to print on failure.
7
8# Change 1..1 below to 1..last_test_to_print .
9# (It may become useful if the test is moved to ./t subdirectory.)
10
11BEGIN { $| = 1; print "1..58\n"; }
12END {print "not ok 1\n" unless $loaded;}
13use Unix::AliasFile;
14use Unix::AutomountFile;
15use Unix::GroupFile;
16use Unix::PasswdFile;
17$loaded = 1;
18print "ok 1\n";
19
20######################### End of black magic.
21
22# Insert your test code below (better if it prints "ok 13"
23# (correspondingly "not ok 13") depending on the success of chunk 13
24# of the test code):
25$num = 2;
26
27#
28# Unix::PasswdFile tests
29#
30
31# Test 2 - initialize PasswdFile object
32print `cp passwd.orig passwd`;
33chmod 0644, "passwd";
34$pw = new Unix::PasswdFile "./passwd";
35$status = defined $pw ? "ok" : "not ok";
36print "$status ", $num++, "\n";
37
38# Test 3 - locking test
39$pw2 = new Unix::PasswdFile "./passwd";
40$status = !defined $pw2 ? "ok" : "not ok";
41print "$status ", $num++, "\n";
42
43# Test 4 - passwd accessor
44$status = $pw->passwd("lp") eq "x" ? "ok" : "not ok";
45print "$status ", $num++, "\n";
46
47# Test 5 - uid accessor
48$status = $pw->uid("adm") == 4 ? "ok" : "not ok";
49print "$status ", $num++, "\n";
50
51# Test 6 - gid accessor
52$status = $pw->gid("sys") == 3 ? "ok" : "not ok";
53print "$status ", $num++, "\n";
54
55# Test 7 - gecos accessor
56$status = $pw->gecos("myself") eq "Me" ? "ok" : "not ok";
57print "$status ", $num++, "\n";
58
59# Test 8 - home accessor
60$status = $pw->home("adm") eq "/usr/adm" ? "ok" : "not ok";
61print "$status ", $num++, "\n";
62
63# Test 9 - shell accessor
64$status = $pw->shell("root") eq "/bin/csh" ? "ok" : "not ok";
65print "$status ", $num++, "\n";
66
67# Test 10 - add user
68$pw->user("test", "*", 8192, 2048, "Testy Test", "/home/test", "/bin/ksh");
69$status = $pw->uid("test") == 8192 ? "ok" : "not ok";
70print "$status ", $num++, "\n";
71
72# Test 11 - modify user
73$pw->uid('test', 2112);
74$status = $pw->uid("test") == 2112 ? "ok" : "not ok";
75print "$status ", $num++, "\n";
76
77# Test 12 - delete user
78$pw->delete("myself");
79$status = !defined $pw->user("myself") ? "ok" : "not ok";
80print "$status ", $num++, "\n";
81
82# Test 13 - access undefined data
83$status = !defined $pw->uid("myself") ? "ok" : "not ok";
84print "$status ", $num++, "\n";
85
86# Test 14 - get maximum uid
87$status = $pw->maxuid == 60001 ? "ok" : "not ok";
88print "$status ", $num++, "\n";
89
90# Test 15 - get maximum uid with ignore
91$status = $pw->maxuid(60000) == 2112 ? "ok" : "not ok";
92print "$status ", $num++, "\n";
93
94# Test 16 - get list of users
95$status = $pw->users == 8 ? "ok" : "not ok";
96print "$status ", $num++, "\n";
97
98# Test 17 - commit the file
99$pw->commit();
100$status = !`diff passwd passwd.test` ? "ok" : "not ok";
101print "$status ", $num++, "\n";
102unlink "passwd";
103
104#
105# Unix::GroupFile tests
106#
107
108# Test 18 - initialize GroupFile object
109print `cp group.orig group`;
110chmod 0644, "group";
111$grp = new Unix::GroupFile "./group";
112$status = defined $grp ? "ok" : "not ok";
113print "$status ", $num++, "\n";
114
115# Test 19 - locking test
116$grp2 = new Unix::GroupFile "./group";
117$status = !defined $grp2 ? "ok" : "not ok";
118print "$status ", $num++, "\n";
119
120# Test 20 - gid accessor
121$status = $grp->gid("staff") == 10 ? "ok" : "not ok";
122print "$status ", $num++, "\n";
123
124# Test 21 - passwd accessor
125$status = $grp->passwd("daemon") eq "*" ? "ok" : "not ok";
126print "$status ", $num++, "\n";
127
128# Test 22 - add group
129$grp->group("mygroup", "", 5150, "root", "johndoe", "bongo");
130$status = $grp->gid("mygroup") == 5150 ? "ok" : "not ok";
131print "$status ", $num++, "\n";
132
133# Test 23 - add users to group
134$grp->add_user("mygroup", "dude1", "dude2");
135$status = $grp->members("mygroup") == 5 ? "ok" : "not ok";
136print "$status ", $num++, "\n";
137
138# Test 24 - remove users from group
139$grp->remove_user("mygroup", "root");
140$status = $grp->members("mygroup") == 4 ? "ok" : "not ok";
141print "$status ", $num++, "\n";
142
143# Test 25 - remove users from all groups
144$grp->remove_user("*", "bin");
145$status = $grp->members("sys") == 3 ? "ok" : "not ok";
146print "$status ", $num++, "\n";
147
148# Test 26 - modify group
149$grp->group("staff", "*", 20, "dilbert", "wally", "alice");
150$status = $grp->members("staff") == 3 ? "ok" : "not ok";
151print "$status ", $num++, "\n";
152
153# Test 27 - illegal attempt to reuse GID
154$status = !$grp->gid("mygroup", 20) ? "ok" : "not ok";
155print "$status ", $num++, "\n";
156
157# Test 28 - delete group
158$grp->delete("tty");
159$status = !$grp->group("tty") ? "ok" : "not ok";
160print "$status ", $num++, "\n";
161
162# Test 29 - get maximum GID
163$status = $grp->maxgid == 65534 ? "ok" : "not ok";
164print "$status ", $num++, "\n";
165
166# Test 30 - get list of groups
167$status = $grp->groups == 16 ? "ok" : "not ok";
168print "$status ", $num++, "\n";
169
170# Test 31 - rename a user
171$status = $grp->rename_user("adm", "admin") == 3 ? "ok" : "not ok";
172print "$status ", $num++, "\n";
173
174# Test 32 - commit the file
175$grp->commit();
176$status = !`diff group group.test` ? "ok" : "not ok";
177print "$status ", $num++, "\n";
178unlink "group";
179
180#
181# Unix::AliasFile tests
182#
183
184# Test 33 - initialize AliasFile object
185print `cp aliases.orig aliases`;
186chmod 0644, "aliases";
187$al = new Unix::AliasFile "./aliases";
188$status = defined $al ? "ok" : "not ok";
189print "$status ", $num++, "\n";
190
191# Test 34 - locking test
192$al2 = new Unix::AliasFile "./aliases";
193$status = !defined $al2 ? "ok" : "not ok";
194print "$status ", $num++, "\n";
195
196# Test 35 - alias accessor
197$status = $al->alias("staff") == 18 ? "ok" : "not ok";
198print "$status ", $num++, "\n";
199
200# Test 36 - add alias
201$al->alias("stooges", qw(larry curly moe));
202$status = $al->alias("stooges") == 3 ? "ok" : "not ok";
203print "$status ", $num++, "\n";
204
205# Test 37 - add users to alias
206$al->add_user("webmaster", "webguy", "perlgod", "webby");
207$status = $al->alias("webmaster") == 4 ? "ok" : "not ok";
208print "$status ", $num++, "\n";
209
210# Test 38 - remove users from alias
211$al->remove_user("staff", qw(sklower olson bogon test2));
212$status = $al->alias("staff") == 14 ? "ok" : "not ok";
213print "$status ", $num++, "\n";
214
215# Test 39 - remove users from all aliases
216$al->remove_user("*", "owner1");
217$status = $al->alias("owner-mylist-l") == 2 ? "ok" : "not ok";
218print "$status ", $num++, "\n";
219
220# Test 40 - access undefined data
221$status = !defined $al->alias("noalias") ? "ok" : "not ok";
222print "$status ", $num++, "\n";
223
224# Test 41 - modify alias
225$al->alias("root", ":include:/lists/superusers");
226$status = $al->alias("root") == 1 ? "ok" : "not ok";
227print "$status ", $num++, "\n";
228
229# Test 42 - delete alias
230$al->delete("abuse");
231$status = !defined $al->alias("abuse") ? "ok" : "not ok";
232print "$status ", $num++, "\n";
233
234# Test 43 - get list of aliases
235$status = $al->aliases == 20 ? "ok" : "not ok";
236print "$status ", $num++, "\n";
237
238# Test 44 - add comment
239$ret = $al->comment("stooges", "# Funny guys");
240$status = $ret ? "ok" : "not ok";
241print "$status ", $num++, "\n";
242
243# Test 45 - remove comment
244$ret = $al->uncomment("# Sample aliases:");
245$status = $ret ? "ok" : "not ok";
246print "$status ", $num++, "\n";
247
248# Test 46 - rename user
249$status = $al->rename_user("perlgod", "lwall") == 1 ? "ok" : "not ok";
250print "$status ", $num++, "\n";
251
252# Test 47 - commit the file
253$al->commit();
254$status = !`diff aliases aliases.test` ? "ok" : "not ok";
255print "$status ", $num++, "\n";
256unlink "aliases";
257
258#
259# Unix::AutomountFile tests
260#
261
262# Test 48 - initialize AutomountFile object
263print `cp auto_home.orig auto_home`;
264chmod 0644, "auto_home";
265$am = new Unix::AutomountFile "./auto_home";
266$status = defined $am ? "ok" : "not ok";
267print "$status ", $num++, "\n";
268
269# Test 49 - locking test
270$am2 = new Unix::AutomountFile "./auto_home";
271$status = !defined $am2 ? "ok" : "not ok";
272print "$status ", $num++, "\n";
273
274# Test 50 - options accessor
275$status = $am->options("fsi") eq "-rw,intr" ? "ok" : "not ok";
276print "$status ", $num++, "\n";
277
278# Test 51 - add automount point
279$am->automount("bozo", "fileserv1:/users/&", "fileserv2:/users/&");
280$status = $am->automount("bozo") == 2 ? "ok" : "not ok";
281print "$status ", $num++, "\n";
282
283# Test 52 - add servers to existing automount point
284$am->add_server("bozo", "fileserv3:/users/&");
285$status = $am->automount("bozo") == 3 ? "ok" : "not ok";
286print "$status ", $num++, "\n";
287
288# Test 53 - change automount options
289$am->options("bozo", "-rw,nosuid");
290$status = $am->options("bozo") eq "-rw,nosuid" ? "ok" : "not ok";
291print "$status ", $num++, "\n";
292
293# Test 54 - modify automount point
294$am->automount("ssnodgra", $am->automount("bozo"));
295$status = $am->automount("ssnodgra") == 3 ? "ok" : "not ok";
296print "$status ", $num++, "\n";
297
298# Test 55 - delete automount point
299$am->delete("bigguy");
300$status = !defined $am->automount("bigguy") ? "ok" : "not ok";
301print "$status ", $num++, "\n";
302
303# Test 56 - get list of mount points
304$status = $am->automounts == 6 ? "ok" : "not ok";
305print "$status ", $num++, "\n";
306
307# Test 57 - rename mount point
308$am->rename("coolguy", "linus");
309$status = $am->automount("linus") == 1 ? "ok" : "not ok";
310print "$status ", $num++, "\n";
311
312# Test 58 - commit the file
313$am->commit();
314$status = !`diff auto_home auto_home.test` ? "ok" : "not ok";
315print "$status ", $num++, "\n";
316unlink "auto_home";
317