Debian Codegraph @

tests/t/lib/ProFTPD/Tests/Commands/STAT.pm

raw
1 package ProFTPD::Tests::Commands::STAT;
2
3 use lib qw(t/lib);
4 use base qw(ProFTPD::TestSuite::Child);
5 use strict;
6
7 use Cwd;
8 use File::Path qw(mkpath);
9 use File::Spec;
10 use IO::Handle;
11
12 use ProFTPD::TestSuite::FTP;
13 use ProFTPD::TestSuite::Utils qw(:auth :config :running :test :testsuite);
14
15 $| = 1;
16
17 my $order = 0;
18
19 my $TESTS = {
20 stat_file => {
21 order => ++$order,
22 test_class => [qw(forking)],
23 },
24
25 stat_dir => {
26 order => ++$order,
27 test_class => [qw(forking)],
28 },
29
30 stat_dir_with_files_bug3990 => {
31 order => ++$order,
32 test_class => [qw(bug forking)],
33 },
34
35 stat_symlink_showsymlinks_off => {
36 order => ++$order,
37 test_class => [qw(forking)],
38 },
39
40 stat_symlink_showsymlinks_on => {
41 order => ++$order,
42 test_class => [qw(forking)],
43 },
44
45 stat_symlink_showsymlinks_off_chrooted_bug4219 => {
46 order => ++$order,
47 test_class => [qw(forking rootprivs)],
48 },
49
50 stat_symlink_showsymlinks_on_chrooted_bug4219 => {
51 order => ++$order,
52 test_class => [qw(forking rootprivs)],
53 },
54
55 stat_system => {
56 order => ++$order,
57 test_class => [qw(forking)],
58 },
59
60 stat_enoent => {
61 order => ++$order,
62 test_class => [qw(forking)],
63 },
64
65 stat_listoptions_bug3295 => {
66 order => ++$order,
67 test_class => [qw(bug forking)],
68 },
69
70 };
71
72 sub new {
73 return shift()->SUPER::new(@_);
74 }
75
76 sub list_tests {
77 return testsuite_get_runnable_tests($TESTS);
78 }
79
80 sub stat_file {
81 my $self = shift;
82 my $tmpdir = $self->{tmpdir};
83 my $setup = test_setup($tmpdir, 'cmds');
84
85 my $test_file = File::Spec->rel2abs($setup->{config_file});
86
87 my $config = {
88 PidFile => $setup->{pid_file},
89 ScoreboardFile => $setup->{scoreboard_file},
90 SystemLog => $setup->{log_file},
91
92 AuthUserFile => $setup->{auth_user_file},
93 AuthGroupFile => $setup->{auth_group_file},
94 AuthOrder => 'mod_auth_file.c',
95
96 IfModules => {
97 'mod_delay.c' => {
98 DelayEngine => 'off',
99 },
100 },
101 };
102
103 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
104 $config);
105
106 # Open pipes, for use between the parent and child processes. Specifically,
107 # the child will indicate when it's done with its test by writing a message
108 # to the parent.
109 my ($rfh, $wfh);
110 unless (pipe($rfh, $wfh)) {
111 die("Can't open pipe: $!");
112 }
113
114 my $ex;
115
116 # Fork child
117 $self->handle_sigchld();
118 defined(my $pid = fork()) or die("Can't fork: $!");
119 if ($pid) {
120 eval {
121 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
122 $client->login($setup->{user}, $setup->{passwd});
123 $client->stat('cmds.conf');
124
125 my $resp_code = $client->response_code();
126 my $resp_msgs = $client->response_msgs();
127 my $resp_msg = $resp_msgs->[1];
128 $client->quit();
129
130 my $expected = 213;
131 $self->assert($expected == $resp_code,
132 test_msg("Expected response code $expected, got $resp_code"));
133
134 $expected = '^(\s+)?\S+\s+\d+\s+\S+\s+\S+\s+.*?\s+(\S+)$';
135 $self->assert(qr/$expected/, $resp_msg,
136 test_msg("Expected response message '$expected', got '$resp_msg'"));
137 };
138 if ($@) {
139 $ex = $@;
140 }
141
142 $wfh->print("done\n");
143 $wfh->flush();
144
145 } else {
146 eval { server_wait($setup->{config_file}, $rfh) };
147 if ($@) {
148 warn($@);
149 exit 1;
150 }
151
152 exit 0;
153 }
154
155 # Stop server
156 server_stop($setup->{pid_file});
157 $self->assert_child_ok($pid);
158
159 test_cleanup($setup->{log_file}, $ex);
160 }
161
162 sub stat_dir {
163 my $self = shift;
164 my $tmpdir = $self->{tmpdir};
165 my $setup = test_setup($tmpdir, 'cmds');
166
167 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
168 mkpath($test_dir);
169
170 if ($< == 0) {
171 unless (chmod(0755, $test_dir)) {
172 die("Can't set perms on $test_dir to 0755: $!");
173 }
174
175 unless (chown($setup->{uid}, $setup->{gid}, $test_dir)) {
176 die("Can't set owner of $test_dir to $setup->{uid}/$setup->{gid}: $!");
177 }
178 }
179
180 my $config = {
181 PidFile => $setup->{pid_file},
182 ScoreboardFile => $setup->{scoreboard_file},
183 SystemLog => $setup->{log_file},
184
185 AuthUserFile => $setup->{auth_user_file},
186 AuthGroupFile => $setup->{auth_group_file},
187 AuthOrder => 'mod_auth_file.c',
188
189 IfModules => {
190 'mod_delay.c' => {
191 DelayEngine => 'off',
192 },
193 },
194 };
195
196 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
197 $config);
198
199 # Open pipes, for use between the parent and child processes. Specifically,
200 # the child will indicate when it's done with its test by writing a message
201 # to the parent.
202 my ($rfh, $wfh);
203 unless (pipe($rfh, $wfh)) {
204 die("Can't open pipe: $!");
205 }
206
207 my $ex;
208
209 # Fork child
210 $self->handle_sigchld();
211 defined(my $pid = fork()) or die("Can't fork: $!");
212 if ($pid) {
213 eval {
214 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
215 $client->login($setup->{user}, $setup->{passwd});
216 $client->stat('test.d');
217
218 my $resp_code = $client->response_code();
219 my $resp_msgs = $client->response_msgs();
220 my $resp_msg = $resp_msgs->[1];
221 $client->quit();
222
223 my $expected = 212;
224 $self->assert($expected == $resp_code,
225 test_msg("Expected response code $expected, got $resp_code"));
226
227 $expected = '^(\s+)?\S+\s+\d+\s+\S+\s+\S+\s+.*?\s+(\S+)$';
228 $self->assert(qr/$expected/, $resp_msg,
229 test_msg("Expected response message '$expected', got '$resp_msg'"));
230 };
231 if ($@) {
232 $ex = $@;
233 }
234
235 $wfh->print("done\n");
236 $wfh->flush();
237
238 } else {
239 eval { server_wait($setup->{config_file}, $rfh) };
240 if ($@) {
241 warn($@);
242 exit 1;
243 }
244
245 exit 0;
246 }
247
248 # Stop server
249 server_stop($setup->{pid_file});
250 $self->assert_child_ok($pid);
251
252 test_cleanup($setup->{log_file}, $ex);
253 }
254
255 sub stat_dir_with_files_bug3990 {
256 my $self = shift;
257 my $tmpdir = $self->{tmpdir};
258 my $setup = test_setup($tmpdir, 'cmds');
259
260 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
261 mkpath($test_dir);
262
263 for (my $i = 0; $i < 5; $i++) {
264 my $test_file = File::Spec->rel2abs("$test_dir/file$i.dat");
265 if (open(my $fh, "> $test_file")) {
266 close($fh);
267
268 } else {
269 die("Can't open $test_file: $!");
270 }
271 }
272
273 for (my $i = 0; $i < 5; $i++) {
274 my $test_file = File::Spec->rel2abs("$test_dir/.hidden$i.dat");
275 if (open(my $fh, "> $test_file")) {
276 close($fh);
277
278 } else {
279 die("Can't open $test_file: $!");
280 }
281 }
282
283 # Make sure that, if we're running as root, that the home directory has
284 # permissions/privs set for the account we create
285 if ($< == 0) {
286 unless (chmod(0755, $test_dir)) {
287 die("Can't set perms on $test_dir to 0755: $!");
288 }
289
290 unless (chown($setup->{uid}, $setup->{gid}, $test_dir)) {
291 die("Can't set owner of $test_dir to $setup->{uid}/$setup->{gid}: $!");
292 }
293 }
294
295 my $config = {
296 PidFile => $setup->{pid_file},
297 ScoreboardFile => $setup->{scoreboard_file},
298 SystemLog => $setup->{log_file},
299
300 AuthUserFile => $setup->{auth_user_file},
301 AuthGroupFile => $setup->{auth_group_file},
302 AuthOrder => 'mod_auth_file.c',
303
304 IfModules => {
305 'mod_delay.c' => {
306 DelayEngine => 'off',
307 },
308 },
309 };
310
311 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
312 $config);
313
314 # Open pipes, for use between the parent and child processes. Specifically,
315 # the child will indicate when it's done with its test by writing a message
316 # to the parent.
317 my ($rfh, $wfh);
318 unless (pipe($rfh, $wfh)) {
319 die("Can't open pipe: $!");
320 }
321
322 my $ex;
323
324 # Fork child
325 $self->handle_sigchld();
326 defined(my $pid = fork()) or die("Can't fork: $!");
327 if ($pid) {
328 eval {
329 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
330 $client->login($setup->{user}, $setup->{passwd});
331 $client->stat('test.d');
332
333 my $resp_code = $client->response_code();
334 my $resp_msgs = $client->response_msgs();
335 my $resp_nmsgs = scalar(@$resp_msgs);
336 my $resp_msg = $resp_msgs->[1];
337 $client->quit();
338
339 my $expected = 212;
340 $self->assert($expected == $resp_code,
341 test_msg("Expected response code $expected, got $resp_code"));
342
343 $expected = '^(\s+)?\S+\s+\d+\s+\S+\s+\S+\s+.*?\s+(\S+)$';
344 $self->assert(qr/$expected/, $resp_msg,
345 test_msg("Expected response message '$expected', got '$resp_msg'"));
346
347 $expected = 14;
348 $self->assert($expected == $resp_nmsgs,
349 test_msg("Expected $expected response lines, got $resp_nmsgs"));
350 };
351 if ($@) {
352 $ex = $@;
353 }
354
355 $wfh->print("done\n");
356 $wfh->flush();
357
358 } else {
359 eval { server_wait($setup->{config_file}, $rfh) };
360 if ($@) {
361 warn($@);
362 exit 1;
363 }
364
365 exit 0;
366 }
367
368 # Stop server
369 server_stop($setup->{pid_file});
370 $self->assert_child_ok($pid);
371
372 test_cleanup($setup->{log_file}, $ex);
373 }
374
375 sub stat_symlink_showsymlinks_off {
376 my $self = shift;
377 my $tmpdir = $self->{tmpdir};
378 my $setup = test_setup($tmpdir, 'cmds');
379
380 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
381 mkpath($test_dir);
382
383 my $test_file = File::Spec->rel2abs("$test_dir/test.txt");
384 if (open(my $fh, "> $test_file")) {
385 unless (close($fh)) {
386 die("Can't write $test_file: $!");
387 }
388
389 } else {
390 die("Can't open $test_file: $!");
391 }
392
393 # Change to the test directory in order to create a relative path in the
394 # symlink we need
395
396 my $cwd = getcwd();
397 unless (chdir($test_dir)) {
398 die("Can't chdir to $test_dir: $!");
399 }
400
401 unless (symlink('./test.txt', './test.lnk')) {
402 die("Can't symlink 'test.lnk' to './test.txt': $!");
403 }
404
405 unless (chdir($cwd)) {
406 die("Can't chdir to $cwd: $!");
407 }
408
409 if ($< == 0) {
410 unless (chmod(0755, $test_dir)) {
411 die("Can't set perms on $test_dir to 0755: $!");
412 }
413
414 unless (chown($setup->{uid}, $setup->{gid}, $test_dir)) {
415 die("Can't set owner of $test_dir to $setup->{uid}/$setup->{gid}: $!");
416 }
417 }
418
419 my $config = {
420 PidFile => $setup->{pid_file},
421 ScoreboardFile => $setup->{scoreboard_file},
422 SystemLog => $setup->{log_file},
423
424 AuthUserFile => $setup->{auth_user_file},
425 AuthGroupFile => $setup->{auth_group_file},
426 AuthOrder => 'mod_auth_file.c',
427
428 ShowSymlinks => 'off',
429
430 IfModules => {
431 'mod_delay.c' => {
432 DelayEngine => 'off',
433 },
434 },
435 };
436
437 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
438 $config);
439
440 # Open pipes, for use between the parent and child processes. Specifically,
441 # the child will indicate when it's done with its test by writing a message
442 # to the parent.
443 my ($rfh, $wfh);
444 unless (pipe($rfh, $wfh)) {
445 die("Can't open pipe: $!");
446 }
447
448 my $ex;
449
450 # Fork child
451 $self->handle_sigchld();
452 defined(my $pid = fork()) or die("Can't fork: $!");
453 if ($pid) {
454 eval {
455 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
456 $client->login($setup->{user}, $setup->{passwd});
457 $client->stat('test.d/test.lnk');
458
459 my $resp_code = $client->response_code();
460 my $resp_msgs = $client->response_msgs();
461 my $resp_msg = $resp_msgs->[1];
462 $client->quit();
463
464 if ($ENV{TEST_VERBOSE}) {
465 use Data::Dumper;
466 print STDERR "# Response:\n", Dumper($resp_msgs), "\n";
467 }
468
469 my $expected = 213;
470 $self->assert($expected == $resp_code,
471 test_msg("Expected response code $expected, got $resp_code"));
472
473 $expected = '^(\s+)?\-\S+\s+\d+\s+\S+\s+\S+\s+.*?\s+(\S+)$';
474 $self->assert(qr/$expected/, $resp_msg,
475 test_msg("Expected response message '$expected', got '$resp_msg'"));
476 };
477 if ($@) {
478 $ex = $@;
479 }
480
481 $wfh->print("done\n");
482 $wfh->flush();
483
484 } else {
485 eval { server_wait($setup->{config_file}, $rfh) };
486 if ($@) {
487 warn($@);
488 exit 1;
489 }
490
491 exit 0;
492 }
493
494 # Stop server
495 server_stop($setup->{pid_file});
496 $self->assert_child_ok($pid);
497
498 test_cleanup($setup->{log_file}, $ex);
499 }
500
501 sub stat_symlink_showsymlinks_on {
502 my $self = shift;
503 my $tmpdir = $self->{tmpdir};
504 my $setup = test_setup($tmpdir, 'cmds');
505
506 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
507 mkpath($test_dir);
508
509 my $test_file = File::Spec->rel2abs("$test_dir/test.txt");
510 if (open(my $fh, "> $test_file")) {
511 unless (close($fh)) {
512 die("Can't write $test_file: $!");
513 }
514
515 } else {
516 die("Can't open $test_file: $!");
517 }
518
519 # Change to the test directory in order to create a relative path in the
520 # symlink we need
521
522 my $cwd = getcwd();
523 unless (chdir($test_dir)) {
524 die("Can't chdir to $test_dir: $!");
525 }
526
527 unless (symlink('./test.txt', './test.lnk')) {
528 die("Can't symlink 'test.lnk' to './test.txt': $!");
529 }
530
531 unless (chdir($cwd)) {
532 die("Can't chdir to $cwd: $!");
533 }
534
535 if ($< == 0) {
536 unless (chmod(0755, $test_dir)) {
537 die("Can't set perms on $test_dir to 0755: $!");
538 }
539
540 unless (chown($setup->{uid}, $setup->{gid}, $test_dir)) {
541 die("Can't set owner of $test_dir to $setup->{uid}/$setup->{gid}: $!");
542 }
543 }
544
545 my $config = {
546 PidFile => $setup->{pid_file},
547 ScoreboardFile => $setup->{scoreboard_file},
548 SystemLog => $setup->{log_file},
549
550 AuthUserFile => $setup->{auth_user_file},
551 AuthGroupFile => $setup->{auth_group_file},
552 AuthOrder => 'mod_auth_file.c',
553
554 ShowSymlinks => 'on',
555
556 IfModules => {
557 'mod_delay.c' => {
558 DelayEngine => 'off',
559 },
560 },
561 };
562
563 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
564 $config);
565
566 # Open pipes, for use between the parent and child processes. Specifically,
567 # the child will indicate when it's done with its test by writing a message
568 # to the parent.
569 my ($rfh, $wfh);
570 unless (pipe($rfh, $wfh)) {
571 die("Can't open pipe: $!");
572 }
573
574 my $ex;
575
576 # Fork child
577 $self->handle_sigchld();
578 defined(my $pid = fork()) or die("Can't fork: $!");
579 if ($pid) {
580 eval {
581 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
582 $client->login($setup->{user}, $setup->{passwd});
583 $client->stat('test.d/test.lnk');
584
585 my $resp_code = $client->response_code();
586 my $resp_msgs = $client->response_msgs();
587 my $resp_msg = $resp_msgs->[1];
588 $client->quit();
589
590 if ($ENV{TEST_VERBOSE}) {
591 use Data::Dumper;
592 print STDERR "# Response:\n", Dumper($resp_msgs), "\n";
593 }
594
595 my $expected = 213;
596 $self->assert($expected == $resp_code,
597 test_msg("Expected response code $expected, got $resp_code"));
598
599 $expected = '^(\s+)?l\S+\s+\d+\s+\S+\s+\S+\s+.*?\s+(\S+)$';
600 $self->assert(qr/$expected/, $resp_msg,
601 test_msg("Expected response message '$expected', got '$resp_msg'"));
602
603 $expected = '.*?test\.d\/test\.lnk \-> test\.d\/test\.txt$';
604 $self->assert(qr/$expected/, $resp_msg,
605 test_msg("Expected response message '$expected', got '$resp_msg'"));
606 };
607 if ($@) {
608 $ex = $@;
609 }
610
611 $wfh->print("done\n");
612 $wfh->flush();
613
614 } else {
615 eval { server_wait($setup->{config_file}, $rfh) };
616 if ($@) {
617 warn($@);
618 exit 1;
619 }
620
621 exit 0;
622 }
623
624 # Stop server
625 server_stop($setup->{pid_file});
626 $self->assert_child_ok($pid);
627
628 test_cleanup($setup->{log_file}, $ex);
629 }
630
631 sub stat_symlink_showsymlinks_off_chrooted_bug4219 {
632 my $self = shift;
633 my $tmpdir = $self->{tmpdir};
634 my $setup = test_setup($tmpdir, 'cmds');
635
636 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
637 mkpath($test_dir);
638
639 my $test_file = File::Spec->rel2abs("$test_dir/test.txt");
640 if (open(my $fh, "> $test_file")) {
641 unless (close($fh)) {
642 die("Can't write $test_file: $!");
643 }
644
645 } else {
646 die("Can't open $test_file: $!");
647 }
648
649 # Change to the test directory in order to create a relative path in the
650 # symlink we need
651
652 my $cwd = getcwd();
653 unless (chdir($test_dir)) {
654 die("Can't chdir to $test_dir: $!");
655 }
656
657 unless (symlink('./test.txt', './test.lnk')) {
658 die("Can't symlink 'test.lnk' to './test.txt': $!");
659 }
660
661 unless (chdir($cwd)) {
662 die("Can't chdir to $cwd: $!");
663 }
664
665 if ($< == 0) {
666 unless (chmod(0755, $test_dir)) {
667 die("Can't set perms on $test_dir to 0755: $!");
668 }
669
670 unless (chown($setup->{uid}, $setup->{gid}, $test_dir)) {
671 die("Can't set owner of $test_dir to $setup->{uid}/$setup->{gid}: $!");
672 }
673 }
674
675 my $config = {
676 PidFile => $setup->{pid_file},
677 ScoreboardFile => $setup->{scoreboard_file},
678 SystemLog => $setup->{log_file},
679
680 AuthUserFile => $setup->{auth_user_file},
681 AuthGroupFile => $setup->{auth_group_file},
682 AuthOrder => 'mod_auth_file.c',
683
684 DefaultRoot => '~',
685 ShowSymlinks => 'off',
686
687 IfModules => {
688 'mod_delay.c' => {
689 DelayEngine => 'off',
690 },
691 },
692 };
693
694 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
695 $config);
696
697 # Open pipes, for use between the parent and child processes. Specifically,
698 # the child will indicate when it's done with its test by writing a message
699 # to the parent.
700 my ($rfh, $wfh);
701 unless (pipe($rfh, $wfh)) {
702 die("Can't open pipe: $!");
703 }
704
705 my $ex;
706
707 # Fork child
708 $self->handle_sigchld();
709 defined(my $pid = fork()) or die("Can't fork: $!");
710 if ($pid) {
711 eval {
712 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
713 $client->login($setup->{user}, $setup->{passwd});
714 $client->stat('test.d/test.lnk');
715
716 my $resp_code = $client->response_code();
717 my $resp_msgs = $client->response_msgs();
718 my $resp_msg = $resp_msgs->[1];
719 $client->quit();
720
721 if ($ENV{TEST_VERBOSE}) {
722 use Data::Dumper;
723 print STDERR "# Response:\n", Dumper($resp_msgs), "\n";
724 }
725
726 my $expected = 213;
727 $self->assert($expected == $resp_code,
728 test_msg("Expected response code $expected, got $resp_code"));
729
730 $expected = '^(\s+)?\-\S+\s+\d+\s+\S+\s+\S+\s+.*?\s+(\S+)$';
731 $self->assert(qr/$expected/, $resp_msg,
732 test_msg("Expected response message '$expected', got '$resp_msg'"));
733 };
734 if ($@) {
735 $ex = $@;
736 }
737
738 $wfh->print("done\n");
739 $wfh->flush();
740
741 } else {
742 eval { server_wait($setup->{config_file}, $rfh) };
743 if ($@) {
744 warn($@);
745 exit 1;
746 }
747
748 exit 0;
749 }
750
751 # Stop server
752 server_stop($setup->{pid_file});
753 $self->assert_child_ok($pid);
754
755 test_cleanup($setup->{log_file}, $ex);
756 }
757
758 sub stat_symlink_showsymlinks_on_chrooted_bug4219 {
759 my $self = shift;
760 my $tmpdir = $self->{tmpdir};
761 my $setup = test_setup($tmpdir, 'cmds');
762
763 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
764 mkpath($test_dir);
765
766 my $test_file = File::Spec->rel2abs("$test_dir/test.txt");
767 if (open(my $fh, "> $test_file")) {
768 unless (close($fh)) {
769 die("Can't write $test_file: $!");
770 }
771
772 } else {
773 die("Can't open $test_file: $!");
774 }
775
776 # Change to the test directory in order to create a relative path in the
777 # symlink we need
778
779 my $cwd = getcwd();
780 unless (chdir($test_dir)) {
781 die("Can't chdir to $test_dir: $!");
782 }
783
784 unless (symlink('./test.txt', './test.lnk')) {
785 die("Can't symlink 'test.lnk' to './test.txt': $!");
786 }
787
788 unless (chdir($cwd)) {
789 die("Can't chdir to $cwd: $!");
790 }
791
792 if ($< == 0) {
793 unless (chmod(0755, $test_dir)) {
794 die("Can't set perms on $test_dir to 0755: $!");
795 }
796
797 unless (chown($setup->{uid}, $setup->{gid}, $test_dir)) {
798 die("Can't set owner of $test_dir to $setup->{uid}/$setup->{gid}: $!");
799 }
800 }
801
802 my $config = {
803 PidFile => $setup->{pid_file},
804 ScoreboardFile => $setup->{scoreboard_file},
805 SystemLog => $setup->{log_file},
806
807 AuthUserFile => $setup->{auth_user_file},
808 AuthGroupFile => $setup->{auth_group_file},
809 AuthOrder => 'mod_auth_file.c',
810
811 DefaultRoot => '~',
812 ShowSymlinks => 'on',
813
814 IfModules => {
815 'mod_delay.c' => {
816 DelayEngine => 'off',
817 },
818 },
819 };
820
821 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
822 $config);
823
824 # Open pipes, for use between the parent and child processes. Specifically,
825 # the child will indicate when it's done with its test by writing a message
826 # to the parent.
827 my ($rfh, $wfh);
828 unless (pipe($rfh, $wfh)) {
829 die("Can't open pipe: $!");
830 }
831
832 my $ex;
833
834 # Fork child
835 $self->handle_sigchld();
836 defined(my $pid = fork()) or die("Can't fork: $!");
837 if ($pid) {
838 eval {
839 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
840 $client->login($setup->{user}, $setup->{passwd});
841 $client->stat('test.d/test.lnk');
842
843 my $resp_code = $client->response_code();
844 my $resp_msgs = $client->response_msgs();
845 my $resp_msg = $resp_msgs->[1];
846 $client->quit();
847
848 if ($ENV{TEST_VERBOSE}) {
849 use Data::Dumper;
850 print STDERR "# Response:\n", Dumper($resp_msgs), "\n";
851 }
852
853 my $expected = 213;
854 $self->assert($expected == $resp_code,
855 test_msg("Expected response code $expected, got $resp_code"));
856
857 $expected = '^(\s+)?l\S+\s+\d+\s+\S+\s+\S+\s+.*?\s+(\S+)$';
858 $self->assert(qr/$expected/, $resp_msg,
859 test_msg("Expected response message '$expected', got '$resp_msg'"));
860
861 $expected = '.*?test\.d\/test\.lnk \-> \/test\.d\/test\.txt$';
862 $self->assert(qr/$expected/, $resp_msg,
863 test_msg("Expected response message '$expected', got '$resp_msg'"));
864 };
865 if ($@) {
866 $ex = $@;
867 }
868
869 $wfh->print("done\n");
870 $wfh->flush();
871
872 } else {
873 eval { server_wait($setup->{config_file}, $rfh) };
874 if ($@) {
875 warn($@);
876 exit 1;
877 }
878
879 exit 0;
880 }
881
882 # Stop server
883 server_stop($setup->{pid_file});
884 $self->assert_child_ok($pid);
885
886 test_cleanup($setup->{log_file}, $ex);
887 }
888
889 sub stat_system {
890 my $self = shift;
891 my $tmpdir = $self->{tmpdir};
892 my $setup = test_setup($tmpdir, 'cmds');
893
894 my $config = {
895 PidFile => $setup->{pid_file},
896 ScoreboardFile => $setup->{scoreboard_file},
897 SystemLog => $setup->{log_file},
898
899 AuthUserFile => $setup->{auth_user_file},
900 AuthGroupFile => $setup->{auth_group_file},
901 AuthOrder => 'mod_auth_file.c',
902
903 IfModules => {
904 'mod_delay.c' => {
905 DelayEngine => 'off',
906 },
907 },
908 };
909
910 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
911 $config);
912
913 # Open pipes, for use between the parent and child processes. Specifically,
914 # the child will indicate when it's done with its test by writing a message
915 # to the parent.
916 my ($rfh, $wfh);
917 unless (pipe($rfh, $wfh)) {
918 die("Can't open pipe: $!");
919 }
920
921 my $ex;
922
923 # Fork child
924 $self->handle_sigchld();
925 defined(my $pid = fork()) or die("Can't fork: $!");
926 if ($pid) {
927 eval {
928 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
929 $client->login($setup->{user}, $setup->{passwd});
930 $client->stat();
931
932 my $resp_code = $client->response_code();
933 my $resp_msgs = $client->response_msgs();
934 $client->quit();
935
936 my $expected = 211;
937 $self->assert($expected == $resp_code,
938 test_msg("Expected response code $expected, got $resp_code"));
939 };
940 if ($@) {
941 $ex = $@;
942 }
943
944 $wfh->print("done\n");
945 $wfh->flush();
946
947 } else {
948 eval { server_wait($setup->{config_file}, $rfh) };
949 if ($@) {
950 warn($@);
951 exit 1;
952 }
953
954 exit 0;
955 }
956
957 # Stop server
958 server_stop($setup->{pid_file});
959 $self->assert_child_ok($pid);
960
961 test_cleanup($setup->{log_file}, $ex);
962 }
963
964 sub stat_enoent {
965 my $self = shift;
966 my $tmpdir = $self->{tmpdir};
967 my $setup = test_setup($tmpdir, 'cmds');
968
969 my $config = {
970 PidFile => $setup->{pid_file},
971 ScoreboardFile => $setup->{scoreboard_file},
972 SystemLog => $setup->{log_file},
973
974 AuthUserFile => $setup->{auth_user_file},
975 AuthGroupFile => $setup->{auth_group_file},
976 AuthOrder => 'mod_auth_file.c',
977
978 IfModules => {
979 'mod_delay.c' => {
980 DelayEngine => 'off',
981 },
982 },
983 };
984
985 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
986 $config);
987
988 # Open pipes, for use between the parent and child processes. Specifically,
989 # the child will indicate when it's done with its test by writing a message
990 # to the parent.
991 my ($rfh, $wfh);
992 unless (pipe($rfh, $wfh)) {
993 die("Can't open pipe: $!");
994 }
995
996 my $ex;
997
998 # Fork child
999 $self->handle_sigchld();
1000 defined(my $pid = fork()) or die("Can't fork: $!");
1001 if ($pid) {
1002 eval {
1003 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
1004 $client->login($setup->{user}, $setup->{passwd});
1005
1006 my $enoent_file = 'foo.bar.baz.d';
1007
1008 eval { $client->stat($enoent_file) };
1009 unless ($@) {
1010 die("STAT succeeded unexpectedly");
1011 }
1012
1013 my $resp_code = $client->response_code();
1014 my $resp_msg = $client->response_msg();
1015 $client->quit();
1016
1017 my $expected = 450;
1018 $self->assert($expected == $resp_code,
1019 test_msg("Expected response code $expected, got $resp_code"));
1020
1021 $expected = "$enoent_file: No such file or directory";
1022 $self->assert($expected eq $resp_msg,
1023 test_msg("Expected response message '$expected', got '$resp_msg'"));
1024 };
1025 if ($@) {
1026 $ex = $@;
1027 }
1028
1029 $wfh->print("done\n");
1030 $wfh->flush();
1031
1032 } else {
1033 eval { server_wait($setup->{config_file}, $rfh) };
1034 if ($@) {
1035 warn($@);
1036 exit 1;
1037 }
1038
1039 exit 0;
1040 }
1041
1042 # Stop server
1043 server_stop($setup->{pid_file});
1044 $self->assert_child_ok($pid);
1045
1046 test_cleanup($setup->{log_file}, $ex);
1047 }
1048
1049 sub stat_listoptions_bug3295 {
1050 my $self = shift;
1051 my $tmpdir = $self->{tmpdir};
1052 my $setup = test_setup($tmpdir, 'cmds');
1053
1054 my $config = {
1055 PidFile => $setup->{pid_file},
1056 ScoreboardFile => $setup->{scoreboard_file},
1057 SystemLog => $setup->{log_file},
1058
1059 AuthUserFile => $setup->{auth_user_file},
1060 AuthGroupFile => $setup->{auth_group_file},
1061 AuthOrder => 'mod_auth_file.c',
1062
1063 ListOptions => '-1',
1064
1065 IfModules => {
1066 'mod_delay.c' => {
1067 DelayEngine => 'off',
1068 },
1069 },
1070 };
1071
1072 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1073 $config);
1074
1075 # Open pipes, for use between the parent and child processes. Specifically,
1076 # the child will indicate when it's done with its test by writing a message
1077 # to the parent.
1078 my ($rfh, $wfh);
1079 unless (pipe($rfh, $wfh)) {
1080 die("Can't open pipe: $!");
1081 }
1082
1083 my $ex;
1084
1085 # Fork child
1086 $self->handle_sigchld();
1087 defined(my $pid = fork()) or die("Can't fork: $!");
1088 if ($pid) {
1089 eval {
1090 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
1091 $client->login($setup->{user}, $setup->{passwd});
1092
1093 my ($resp_code, $resp_msg) = $client->stat('cmds.conf');
1094 $client->quit();
1095
1096 my $expected = 213;
1097 $self->assert($expected == $resp_code,
1098 test_msg("Expected response code $expected, got $resp_code"));
1099
1100 $expected = '^(\s+)?\S+\s+\d+\s+\S+\s+\S+\s+.*?\s+(\S+)$';
1101 $self->assert(qr/$expected/, $resp_msg,
1102 test_msg("Expected response message '$expected', got '$resp_msg'"));
1103 };
1104 if ($@) {
1105 $ex = $@;
1106 }
1107
1108 $wfh->print("done\n");
1109 $wfh->flush();
1110
1111 } else {
1112 eval { server_wait($setup->{config_file}, $rfh) };
1113 if ($@) {
1114 warn($@);
1115 exit 1;
1116 }
1117
1118 exit 0;
1119 }
1120
1121 # Stop server
1122 server_stop($setup->{pid_file});
1123 $self->assert_child_ok($pid);
1124
1125 test_cleanup($setup->{log_file}, $ex);
1126 }
1127
1128 1;