Debian Codegraph @

tests/t/lib/ProFTPD/Tests/Config/AuthOrder.pm

raw
1 package ProFTPD::Tests::Config::AuthOrder;
2
3 use lib qw(t/lib);
4 use base qw(ProFTPD::TestSuite::Child);
5 use strict;
6
7 use File::Spec;
8 use IO::Handle;
9
10 use ProFTPD::TestSuite::FTP;
11 use ProFTPD::TestSuite::Utils qw(:auth :config :running :test :testsuite);
12
13 $| = 1;
14
15 my $order = 0;
16
17 my $TESTS = {
18 authorder_unix_only => {
19 order => ++$order,
20 test_class => [qw(forking)],
21 },
22
23 authorder_unix_authoritative => {
24 order => ++$order,
25 test_class => [qw(forking)],
26 },
27
28 authorder_file_authoritative => {
29 order => ++$order,
30 test_class => [qw(forking)],
31 },
32
33 authorder_pam_authoritative => {
34 order => ++$order,
35 test_class => [qw(forking mod_auth_pam)],
36 },
37
38 };
39
40 sub new {
41 return shift()->SUPER::new(@_);
42 }
43
44 sub list_tests {
45 return testsuite_get_runnable_tests($TESTS);
46 }
47
48 sub authorder_unix_only {
49 my $self = shift;
50 my $tmpdir = $self->{tmpdir};
51
52 my $config_file = "$tmpdir/config.conf";
53 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
54 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
55
56 my $log_file = File::Spec->rel2abs('tests.log');
57
58 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
59 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
60
61 my $user = 'proftpd';
62 my $group = 'ftpd';
63 my $passwd = 'test';
64 my $home_dir = File::Spec->rel2abs($tmpdir);
65 my $uid = 500;
66 my $gid = 500;
67
68 # Make sure that, if we're running as root, that the home directory has
69 # permissions/privs set for the account we create
70 if ($< == 0) {
71 unless (chmod(0755, $home_dir)) {
72 die("Can't set perms on $home_dir to 0755: $!");
73 }
74
75 unless (chown($uid, $gid, $home_dir)) {
76 die("Can't set owner of $home_dir to $uid/$gid: $!");
77 }
78 }
79
80 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
81 '/bin/bash');
82 auth_group_write($auth_group_file, $group, $gid, $user);
83
84 my $config = {
85 PidFile => $pid_file,
86 ScoreboardFile => $scoreboard_file,
87 SystemLog => $log_file,
88 TraceLog => $log_file,
89 Trace => 'DEFAULT:10',
90
91 AuthUserFile => $auth_user_file,
92 AuthGroupFile => $auth_group_file,
93 AuthOrder => 'mod_auth_unix.c',
94
95 IfModules => {
96 'mod_delay.c' => {
97 DelayEngine => 'off',
98 },
99 },
100 };
101
102 my ($port, $config_user, $config_group) = config_write($config_file, $config);
103
104 # Open pipes, for use between the parent and child processes. Specifically,
105 # the child will indicate when it's done with its test by writing a message
106 # to the parent.
107 my ($rfh, $wfh);
108 unless (pipe($rfh, $wfh)) {
109 die("Can't open pipe: $!");
110 }
111
112 my $ex;
113
114 # Fork child
115 $self->handle_sigchld();
116 defined(my $pid = fork()) or die("Can't fork: $!");
117 if ($pid) {
118 eval {
119 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
120
121 eval { $client->login($user, $passwd) };
122 unless ($@) {
123 die("Login succeeded unexpectedly");
124 }
125
126 my $resp_code = $client->response_code();
127 my $resp_msg = $client->response_msg();
128
129 my $expected;
130
131 $expected = 530;
132 $self->assert($expected == $resp_code,
133 test_msg("Expected $expected, got $resp_code"));
134
135 $expected = 'Login incorrect.';
136 $self->assert($expected eq $resp_msg,
137 test_msg("Expected '$expected', got '$resp_msg'"));
138 };
139
140 if ($@) {
141 $ex = $@;
142 }
143
144 $wfh->print("done\n");
145 $wfh->flush();
146
147 } else {
148 eval { server_wait($config_file, $rfh) };
149 if ($@) {
150 warn($@);
151 exit 1;
152 }
153
154 exit 0;
155 }
156
157 # Stop server
158 server_stop($pid_file);
159
160 $self->assert_child_ok($pid);
161
162 if ($ex) {
163 die($ex);
164 }
165
166 unlink($log_file);
167 }
168
169 sub authorder_unix_authoritative {
170 my $self = shift;
171 my $tmpdir = $self->{tmpdir};
172
173 my $config_file = "$tmpdir/config.conf";
174 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
175 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
176
177 my $log_file = File::Spec->rel2abs('tests.log');
178
179 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
180 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
181
182 my $user = 'proftpd';
183 my $group = 'ftpd';
184 my $passwd = 'test';
185 my $home_dir = File::Spec->rel2abs($tmpdir);
186 my $uid = 500;
187 my $gid = 500;
188
189 # Make sure that, if we're running as root, that the home directory has
190 # permissions/privs set for the account we create
191 if ($< == 0) {
192 unless (chmod(0755, $home_dir)) {
193 die("Can't set perms on $home_dir to 0755: $!");
194 }
195
196 unless (chown($uid, $gid, $home_dir)) {
197 die("Can't set owner of $home_dir to $uid/$gid: $!");
198 }
199 }
200
201 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
202 '/bin/bash');
203 auth_group_write($auth_group_file, $group, $gid, $user);
204
205 my $config = {
206 PidFile => $pid_file,
207 ScoreboardFile => $scoreboard_file,
208 SystemLog => $log_file,
209 TraceLog => $log_file,
210 Trace => 'DEFAULT:10',
211
212 AuthUserFile => $auth_user_file,
213 AuthGroupFile => $auth_group_file,
214 AuthOrder => 'mod_auth_unix.c* mod_auth_file.c',
215
216 IfModules => {
217 'mod_delay.c' => {
218 DelayEngine => 'off',
219 },
220 },
221 };
222
223 my ($port, $config_user, $config_group) = config_write($config_file, $config);
224
225 # Open pipes, for use between the parent and child processes. Specifically,
226 # the child will indicate when it's done with its test by writing a message
227 # to the parent.
228 my ($rfh, $wfh);
229 unless (pipe($rfh, $wfh)) {
230 die("Can't open pipe: $!");
231 }
232
233 my $ex;
234
235 # Fork child
236 $self->handle_sigchld();
237 defined(my $pid = fork()) or die("Can't fork: $!");
238 if ($pid) {
239 eval {
240 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
241
242 eval { $client->login($user, $passwd) };
243 unless ($@) {
244 die("Login succeeded unexpectedly");
245 }
246
247 my $resp_code = $client->response_code();
248 my $resp_msg = $client->response_msg();
249
250 my $expected;
251
252 $expected = 530;
253 $self->assert($expected == $resp_code,
254 test_msg("Expected $expected, got $resp_code"));
255
256 $expected = 'Login incorrect.';
257 $self->assert($expected eq $resp_msg,
258 test_msg("Expected '$expected', got '$resp_msg'"));
259
260 };
261
262 if ($@) {
263 $ex = $@;
264 }
265
266 $wfh->print("done\n");
267 $wfh->flush();
268
269 } else {
270 eval { server_wait($config_file, $rfh) };
271 if ($@) {
272 warn($@);
273 exit 1;
274 }
275
276 exit 0;
277 }
278
279 # Stop server
280 server_stop($pid_file);
281
282 $self->assert_child_ok($pid);
283
284 if ($ex) {
285 die($ex);
286 }
287
288 unlink($log_file);
289 }
290
291 sub authorder_file_authoritative {
292 my $self = shift;
293 my $tmpdir = $self->{tmpdir};
294
295 my $config_file = "$tmpdir/config.conf";
296 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
297 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
298
299 my $log_file = File::Spec->rel2abs('tests.log');
300
301 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
302 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
303
304 my $user = 'proftpd';
305 my $group = 'ftpd';
306 my $passwd = 'test';
307 my $home_dir = File::Spec->rel2abs($tmpdir);
308 my $uid = 500;
309 my $gid = 500;
310
311 # Make sure that, if we're running as root, that the home directory has
312 # permissions/privs set for the account we create
313 if ($< == 0) {
314 unless (chmod(0755, $home_dir)) {
315 die("Can't set perms on $home_dir to 0755: $!");
316 }
317
318 unless (chown($uid, $gid, $home_dir)) {
319 die("Can't set owner of $home_dir to $uid/$gid: $!");
320 }
321 }
322
323 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
324 '/bin/bash');
325 auth_group_write($auth_group_file, $group, $gid, $user);
326
327 my $config = {
328 PidFile => $pid_file,
329 ScoreboardFile => $scoreboard_file,
330 SystemLog => $log_file,
331 TraceLog => $log_file,
332 Trace => 'DEFAULT:10',
333
334 AuthUserFile => $auth_user_file,
335 AuthGroupFile => $auth_group_file,
336 AuthOrder => 'mod_auth_file.c* mod_auth_unix.c',
337
338 IfModules => {
339 'mod_delay.c' => {
340 DelayEngine => 'off',
341 },
342 },
343 };
344
345 my ($port, $config_user, $config_group) = config_write($config_file, $config);
346
347 # Open pipes, for use between the parent and child processes. Specifically,
348 # the child will indicate when it's done with its test by writing a message
349 # to the parent.
350 my ($rfh, $wfh);
351 unless (pipe($rfh, $wfh)) {
352 die("Can't open pipe: $!");
353 }
354
355 my $ex;
356
357 # Fork child
358 $self->handle_sigchld();
359 defined(my $pid = fork()) or die("Can't fork: $!");
360 if ($pid) {
361 eval {
362 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
363
364 $client->login($user, $passwd);
365 $client->quit();
366 };
367
368 if ($@) {
369 $ex = $@;
370 }
371
372 $wfh->print("done\n");
373 $wfh->flush();
374
375 } else {
376 eval { server_wait($config_file, $rfh) };
377 if ($@) {
378 warn($@);
379 exit 1;
380 }
381
382 exit 0;
383 }
384
385 # Stop server
386 server_stop($pid_file);
387
388 $self->assert_child_ok($pid);
389
390 if ($ex) {
391 die($ex);
392 }
393
394 unlink($log_file);
395 }
396
397 sub authorder_pam_authoritative {
398 my $self = shift;
399 my $tmpdir = $self->{tmpdir};
400
401 my $config_file = "$tmpdir/config.conf";
402 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
403 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
404
405 my $log_file = File::Spec->rel2abs('tests.log');
406
407 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
408 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
409
410 my $user = 'proftpd';
411 my $group = 'ftpd';
412 my $passwd = 'test';
413 my $home_dir = File::Spec->rel2abs($tmpdir);
414 my $uid = 500;
415 my $gid = 500;
416
417 # Make sure that, if we're running as root, that the home directory has
418 # permissions/privs set for the account we create
419 if ($< == 0) {
420 unless (chmod(0755, $home_dir)) {
421 die("Can't set perms on $home_dir to 0755: $!");
422 }
423
424 unless (chown($uid, $gid, $home_dir)) {
425 die("Can't set owner of $home_dir to $uid/$gid: $!");
426 }
427 }
428
429 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
430 '/bin/bash');
431 auth_group_write($auth_group_file, $group, $gid, $user);
432
433 my $config = {
434 PidFile => $pid_file,
435 ScoreboardFile => $scoreboard_file,
436 SystemLog => $log_file,
437 TraceLog => $log_file,
438 Trace => 'DEFAULT:10',
439
440 AuthUserFile => $auth_user_file,
441 AuthGroupFile => $auth_group_file,
442 AuthOrder => 'mod_auth_pam.c* mod_auth_unix.c mod_auth_file.c',
443
444 IfModules => {
445 'mod_delay.c' => {
446 DelayEngine => 'off',
447 },
448 },
449 };
450
451 my ($port, $config_user, $config_group) = config_write($config_file, $config);
452
453 # Open pipes, for use between the parent and child processes. Specifically,
454 # the child will indicate when it's done with its test by writing a message
455 # to the parent.
456 my ($rfh, $wfh);
457 unless (pipe($rfh, $wfh)) {
458 die("Can't open pipe: $!");
459 }
460
461 my $ex;
462
463 # Fork child
464 $self->handle_sigchld();
465 defined(my $pid = fork()) or die("Can't fork: $!");
466 if ($pid) {
467 eval {
468 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
469
470 eval { $client->login($user, $passwd) };
471 unless ($@) {
472 die("Login succeeded unexpectedly");
473 }
474
475 my $resp_code = $client->response_code();
476 my $resp_msg = $client->response_msg();
477
478 my $expected;
479
480 $expected = 530;
481 $self->assert($expected == $resp_code,
482 test_msg("Expected $expected, got $resp_code"));
483
484 $expected = 'Login incorrect.';
485 $self->assert($expected eq $resp_msg,
486 test_msg("Expected '$expected', got '$resp_msg'"));
487
488 };
489
490 if ($@) {
491 $ex = $@;
492 }
493
494 $wfh->print("done\n");
495 $wfh->flush();
496
497 } else {
498 eval { server_wait($config_file, $rfh) };
499 if ($@) {
500 warn($@);
501 exit 1;
502 }
503
504 exit 0;
505 }
506
507 # Stop server
508 server_stop($pid_file);
509
510 $self->assert_child_ok($pid);
511
512 if ($ex) {
513 die($ex);
514 }
515
516 unlink($log_file);
517 }
518
519 1;