Debian Codegraph @

tests/t/lib/ProFTPD/Tests/Modules/mod_facts.pm

raw
1 package ProFTPD::Tests::Modules::mod_facts;
2
3 use lib qw(t/lib);
4 use base qw(ProFTPD::TestSuite::Child);
5 use strict;
6
7 use File::Copy;
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 facts_advertise_off => {
21 order => ++$order,
22 test_class => [qw(forking)],
23 },
24
25 facts_default_issue1367 => {
26 order => ++$order,
27 test_class => [qw(bug forking)],
28 },
29
30 facts_ownername_with_space_issue1367 => {
31 order => ++$order,
32 test_class => [qw(bug forking)],
33 },
34
35 facts_groupname_with_space_issue1367 => {
36 order => ++$order,
37 test_class => [qw(bug forking)],
38 },
39
40 opts_mlst_invalid => {
41 order => ++$order,
42 test_class => [qw(forking)],
43 },
44
45 opts_mlst_clear => {
46 order => ++$order,
47 test_class => [qw(forking)],
48 },
49
50 opts_mlst_set => {
51 order => ++$order,
52 test_class => [qw(forking)],
53 },
54 };
55
56 sub new {
57 return shift()->SUPER::new(@_);
58 }
59
60 sub list_tests {
61 return testsuite_get_runnable_tests($TESTS);
62 }
63
64 sub facts_advertise_off {
65 my $self = shift;
66 my $tmpdir = $self->{tmpdir};
67 my $setup = test_setup($tmpdir, 'facts');
68
69 my $config = {
70 PidFile => $setup->{pid_file},
71 ScoreboardFile => $setup->{scoreboard_file},
72 SystemLog => $setup->{log_file},
73 TraceLog => $setup->{log_file},
74 Trace => 'facts:20',
75
76 AuthUserFile => $setup->{auth_user_file},
77 AuthGroupFile => $setup->{auth_group_file},
78 AuthOrder => 'mod_auth_file.c',
79
80 IfModules => {
81 'mod_delay.c' => {
82 DelayEngine => 'off',
83 },
84
85 'mod_facts.c' => {
86 FactsAdvertise => 'off',
87 },
88 },
89 };
90
91 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
92 $config);
93
94 # Open pipes, for use between the parent and child processes. Specifically,
95 # the child will indicate when it's done with its test by writing a message
96 # to the parent.
97 my ($rfh, $wfh);
98 unless (pipe($rfh, $wfh)) {
99 die("Can't open pipe: $!");
100 }
101
102 my $ex;
103
104 # Fork child
105 $self->handle_sigchld();
106 defined(my $pid = fork()) or die("Can't fork: $!");
107 if ($pid) {
108 eval {
109 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
110 $client->login($setup->{user}, $setup->{passwd});
111 $client->type('binary');
112
113 my $conn = $client->mlsd_raw();
114 unless ($conn) {
115 die("Failed to MLSD: " . $client->response_code() . ' ' .
116 $client->response_msg());
117 }
118
119 my $buf;
120 $conn->read($buf, 8192, 10);
121 eval { $conn->close() };
122
123 if ($ENV{TEST_VERBOSE}) {
124 print STDERR "# Response:\n$buf\n";
125 }
126
127 my $resp_code = $client->response_code();
128 my $resp_msg = $client->response_msg();
129 $self->assert_transfer_ok($resp_code, $resp_msg);
130
131 $client->quit();
132
133 # We have to be careful of the fact that readdir returns directory
134 # entries in an unordered fashion.
135 my $res = {};
136 my $lines = [split(/\r\n/, $buf)];
137 $self->assert(scalar(@$lines) > 1,
138 test_msg("Expected several MLSD lines, got " . scalar(@$lines)));
139
140 foreach my $line (@$lines) {
141 if ($line =~ /^modify=\S+;perm=\S+;type=\S+;unique=\S+;UNIX\.group=\d+;UNIX\.groupname=\S+;UNIX\.mode=\d+;UNIX\.owner=\d+;UNIX\.ownername=\S+; (.*?)$/) {
142 $res->{$1} = 1;
143 }
144 }
145
146 # Even though we have "FactsAdvertise off", the MLSD results should
147 # still have the default facts enabled.
148 my $expected = {
149 '.' => 1,
150 '..' => 1,
151 'facts.conf' => 1,
152 'facts.group' => 1,
153 'facts.passwd' => 1,
154 'facts.pid' => 1,
155 'facts.scoreboard' => 1,
156 'facts.scoreboard.lck' => 1,
157 };
158
159 my $ok = 1;
160 my $mismatch;
161 foreach my $name (keys(%$res)) {
162 unless (defined($expected->{$name})) {
163 $mismatch = $name;
164 $ok = 0;
165 last;
166 }
167 }
168
169 unless ($ok) {
170 die("Unexpected name '$mismatch' appeared in MLSD data")
171 }
172 };
173 if ($@) {
174 $ex = $@;
175 }
176
177 $wfh->print("done\n");
178 $wfh->flush();
179
180 } else {
181 eval { server_wait($setup->{config_file}, $rfh) };
182 if ($@) {
183 warn($@);
184 exit 1;
185 }
186
187 exit 0;
188 }
189
190 # Stop server
191 server_stop($setup->{pid_file});
192 $self->assert_child_ok($pid);
193
194 test_cleanup($setup->{log_file}, $ex);
195 }
196
197 sub facts_default_issue1367 {
198 my $self = shift;
199 my $tmpdir = $self->{tmpdir};
200 my $setup = test_setup($tmpdir, 'facts');
201
202 my $config = {
203 PidFile => $setup->{pid_file},
204 ScoreboardFile => $setup->{scoreboard_file},
205 SystemLog => $setup->{log_file},
206 TraceLog => $setup->{log_file},
207 Trace => 'facts:20',
208
209 AuthUserFile => $setup->{auth_user_file},
210 AuthGroupFile => $setup->{auth_group_file},
211 AuthOrder => 'mod_auth_file.c',
212
213 IfModules => {
214 'mod_delay.c' => {
215 DelayEngine => 'off',
216 },
217
218 'mod_facts.c' => {
219 FactsDefault => 'perm size unique UNIX.groupname UNIX.ownername',
220 },
221 },
222 };
223
224 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
225 $config);
226
227 # Open pipes, for use between the parent and child processes. Specifically,
228 # the child will indicate when it's done with its test by writing a message
229 # to the parent.
230 my ($rfh, $wfh);
231 unless (pipe($rfh, $wfh)) {
232 die("Can't open pipe: $!");
233 }
234
235 my $ex;
236
237 # Fork child
238 $self->handle_sigchld();
239 defined(my $pid = fork()) or die("Can't fork: $!");
240 if ($pid) {
241 eval {
242 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
243 $client->login($setup->{user}, $setup->{passwd});
244 $client->type('binary');
245
246 my $conn = $client->mlsd_raw();
247 unless ($conn) {
248 die("Failed to MLSD: " . $client->response_code() . ' ' .
249 $client->response_msg());
250 }
251
252 my $buf;
253 $conn->read($buf, 8192, 10);
254 eval { $conn->close() };
255
256 if ($ENV{TEST_VERBOSE}) {
257 print STDERR "# Response:\n$buf\n";
258 }
259
260 my $resp_code = $client->response_code();
261 my $resp_msg = $client->response_msg();
262 $self->assert_transfer_ok($resp_code, $resp_msg);
263
264 $client->quit();
265
266 # We have to be careful of the fact that readdir returns directory
267 # entries in an unordered fashion.
268 my $res = {};
269 my $lines = [split(/\r\n/, $buf)];
270 $self->assert(scalar(@$lines) > 1,
271 test_msg("Expected several MLSD lines, got " . scalar(@$lines)));
272
273 foreach my $line (@$lines) {
274 # Directory entries will not have the "size" fact.
275
276 if ($line =~ /^perm=\S+;(size=\d+;)?unique=\S+;UNIX\.groupname=\S+;UNIX\.ownername=\S+; (.*?)$/) {
277 $res->{$2} = 1;
278 }
279 }
280
281 my $expected = {
282 '.' => 1,
283 '..' => 1,
284 'facts.conf' => 1,
285 'facts.group' => 1,
286 'facts.passwd' => 1,
287 'facts.pid' => 1,
288 'facts.scoreboard' => 1,
289 'facts.scoreboard.lck' => 1,
290 };
291
292 my $ok = 1;
293 my $mismatch;
294 foreach my $name (keys(%$res)) {
295 unless (defined($expected->{$name})) {
296 $mismatch = $name;
297 $ok = 0;
298 last;
299 }
300 }
301
302 unless ($ok) {
303 die("Unexpected name '$mismatch' appeared in MLSD data")
304 }
305 };
306 if ($@) {
307 $ex = $@;
308 }
309
310 $wfh->print("done\n");
311 $wfh->flush();
312
313 } else {
314 eval { server_wait($setup->{config_file}, $rfh) };
315 if ($@) {
316 warn($@);
317 exit 1;
318 }
319
320 exit 0;
321 }
322
323 # Stop server
324 server_stop($setup->{pid_file});
325 $self->assert_child_ok($pid);
326
327 test_cleanup($setup->{log_file}, $ex);
328 }
329
330 sub facts_ownername_with_space_issue1367 {
331 my $self = shift;
332 my $tmpdir = $self->{tmpdir};
333
334 # To reproduce the behavior reported in Issue #1367, we deliberately
335 # use a username that includes spaces. The current mitigation is that
336 # mod_facts replaces all whitespace characters with '_' in such cases.
337
338 my $username = 'My ProFTPD User';
339 my $setup = test_setup($tmpdir, 'facts', $username);
340
341 my $expected_ownername = $username;
342 $expected_ownername =~ s/\s/_/g;
343
344 my $config = {
345 PidFile => $setup->{pid_file},
346 ScoreboardFile => $setup->{scoreboard_file},
347 SystemLog => $setup->{log_file},
348 TraceLog => $setup->{log_file},
349 Trace => 'facts:20',
350
351 AuthUserFile => $setup->{auth_user_file},
352 AuthGroupFile => $setup->{auth_group_file},
353 AuthOrder => 'mod_auth_file.c',
354
355 IfModules => {
356 'mod_delay.c' => {
357 DelayEngine => 'off',
358 },
359 },
360 };
361
362 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
363 $config);
364
365 # Open pipes, for use between the parent and child processes. Specifically,
366 # the child will indicate when it's done with its test by writing a message
367 # to the parent.
368 my ($rfh, $wfh);
369 unless (pipe($rfh, $wfh)) {
370 die("Can't open pipe: $!");
371 }
372
373 my $ex;
374
375 # Fork child
376 $self->handle_sigchld();
377 defined(my $pid = fork()) or die("Can't fork: $!");
378 if ($pid) {
379 eval {
380 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
381 $client->login($setup->{user}, $setup->{passwd});
382 $client->type('binary');
383
384 my $conn = $client->mlsd_raw();
385 unless ($conn) {
386 die("Failed to MLSD: " . $client->response_code() . ' ' .
387 $client->response_msg());
388 }
389
390 my $buf;
391 $conn->read($buf, 8192, 10);
392 eval { $conn->close() };
393
394 if ($ENV{TEST_VERBOSE}) {
395 print STDERR "# Response:\n$buf\n";
396 }
397
398 my $resp_code = $client->response_code();
399 my $resp_msg = $client->response_msg();
400 $self->assert_transfer_ok($resp_code, $resp_msg);
401
402 $client->quit();
403
404 # We have to be careful of the fact that readdir returns directory
405 # entries in an unordered fashion.
406 my $res = {};
407 my $lines = [split(/\r\n/, $buf)];
408 $self->assert(scalar(@$lines) > 1,
409 test_msg("Expected several MLSD lines, got " . scalar(@$lines)));
410
411 foreach my $line (@$lines) {
412 if ($line =~ /^modify=\S+;(size=\d+;)?perm=\S+;type=\S+;unique=\S+;UNIX\.group=\d+;UNIX\.groupname=\S+;UNIX\.mode=\d+;UNIX\.owner=\d+;UNIX\.ownername=(.*?); (.*?)$/) {
413 $res->{$3} = 1;
414
415 my $facts_ownername = $2;
416 $self->assert($facts_ownername eq $expected_ownername,
417 test_msg("Expected UNIX.ownername '$expected_ownername', got '$facts_ownername' in '$line'"));
418 }
419 }
420
421 my $expected = {
422 '.' => 1,
423 '..' => 1,
424 'facts.conf' => 1,
425 'facts.group' => 1,
426 'facts.passwd' => 1,
427 'facts.pid' => 1,
428 'facts.scoreboard' => 1,
429 'facts.scoreboard.lck' => 1,
430 };
431
432 my $ok = 1;
433 my $mismatch;
434 foreach my $name (keys(%$res)) {
435 unless (defined($expected->{$name})) {
436 $mismatch = $name;
437 $ok = 0;
438 last;
439 }
440 }
441
442 unless ($ok) {
443 die("Unexpected name '$mismatch' appeared in MLSD data")
444 }
445 };
446 if ($@) {
447 $ex = $@;
448 }
449
450 $wfh->print("done\n");
451 $wfh->flush();
452
453 } else {
454 eval { server_wait($setup->{config_file}, $rfh) };
455 if ($@) {
456 warn($@);
457 exit 1;
458 }
459
460 exit 0;
461 }
462
463 # Stop server
464 server_stop($setup->{pid_file});
465 $self->assert_child_ok($pid);
466
467 test_cleanup($setup->{log_file}, $ex);
468 }
469
470 sub facts_groupname_with_space_issue1367 {
471 my $self = shift;
472 my $tmpdir = $self->{tmpdir};
473
474 # To reproduce the behavior reported in Issue #1367, we deliberately
475 # use a group name that includes spaces. The current mitigation is that
476 # mod_facts replaces all whitespace characters with '_' in such cases.
477
478 my $groupname = 'My ProFTPD Group';
479 my $setup = test_setup($tmpdir, 'facts', undef, undef, $groupname);
480
481 my $expected_groupname = $groupname;
482 $expected_groupname =~ s/\s/_/g;
483
484 my $config = {
485 PidFile => $setup->{pid_file},
486 ScoreboardFile => $setup->{scoreboard_file},
487 SystemLog => $setup->{log_file},
488 TraceLog => $setup->{log_file},
489 Trace => 'facts:20',
490
491 AuthUserFile => $setup->{auth_user_file},
492 AuthGroupFile => $setup->{auth_group_file},
493 AuthOrder => 'mod_auth_file.c',
494
495 IfModules => {
496 'mod_delay.c' => {
497 DelayEngine => 'off',
498 },
499 },
500 };
501
502 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
503 $config);
504
505 # Open pipes, for use between the parent and child processes. Specifically,
506 # the child will indicate when it's done with its test by writing a message
507 # to the parent.
508 my ($rfh, $wfh);
509 unless (pipe($rfh, $wfh)) {
510 die("Can't open pipe: $!");
511 }
512
513 my $ex;
514
515 # Fork child
516 $self->handle_sigchld();
517 defined(my $pid = fork()) or die("Can't fork: $!");
518 if ($pid) {
519 eval {
520 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
521 $client->login($setup->{user}, $setup->{passwd});
522 $client->type('binary');
523
524 my $conn = $client->mlsd_raw();
525 unless ($conn) {
526 die("Failed to MLSD: " . $client->response_code() . ' ' .
527 $client->response_msg());
528 }
529
530 my $buf;
531 $conn->read($buf, 8192, 10);
532 eval { $conn->close() };
533
534 if ($ENV{TEST_VERBOSE}) {
535 print STDERR "# Response:\n$buf\n";
536 }
537
538 my $resp_code = $client->response_code();
539 my $resp_msg = $client->response_msg();
540 $self->assert_transfer_ok($resp_code, $resp_msg);
541
542 $client->quit();
543
544 # We have to be careful of the fact that readdir returns directory
545 # entries in an unordered fashion.
546 my $res = {};
547 my $lines = [split(/\r\n/, $buf)];
548 $self->assert(scalar(@$lines) > 1,
549 test_msg("Expected several MLSD lines, got " . scalar(@$lines)));
550
551 foreach my $line (@$lines) {
552 if ($line =~ /^modify=\S+;(size=\d+;)?perm=\S+;type=\S+;unique=\S+;UNIX\.group=\d+;UNIX\.groupname=(.*?);UNIX\.mode=\d+;UNIX\.owner=\d+;UNIX\.ownername=.*?; (.*?)$/) {
553 $res->{$3} = 1;
554
555 my $facts_groupname = $2;
556 $self->assert($facts_groupname eq $expected_groupname,
557 test_msg("Expected UNIX.groupname '$expected_groupname', got '$facts_groupname' in '$line'"));
558 }
559 }
560
561 my $expected = {
562 '.' => 1,
563 '..' => 1,
564 'facts.conf' => 1,
565 'facts.group' => 1,
566 'facts.passwd' => 1,
567 'facts.pid' => 1,
568 'facts.scoreboard' => 1,
569 'facts.scoreboard.lck' => 1,
570 };
571
572 my $ok = 1;
573 my $mismatch;
574 foreach my $name (keys(%$res)) {
575 unless (defined($expected->{$name})) {
576 $mismatch = $name;
577 $ok = 0;
578 last;
579 }
580 }
581
582 unless ($ok) {
583 die("Unexpected name '$mismatch' appeared in MLSD data")
584 }
585 };
586 if ($@) {
587 $ex = $@;
588 }
589
590 $wfh->print("done\n");
591 $wfh->flush();
592
593 } else {
594 eval { server_wait($setup->{config_file}, $rfh) };
595 if ($@) {
596 warn($@);
597 exit 1;
598 }
599
600 exit 0;
601 }
602
603 # Stop server
604 server_stop($setup->{pid_file});
605 $self->assert_child_ok($pid);
606
607 test_cleanup($setup->{log_file}, $ex);
608 }
609
610 sub opts_mlst_invalid {
611 my $self = shift;
612 my $tmpdir = $self->{tmpdir};
613 my $setup = test_setup($tmpdir, 'facts');
614
615 my $config = {
616 PidFile => $setup->{pid_file},
617 ScoreboardFile => $setup->{scoreboard_file},
618 SystemLog => $setup->{log_file},
619 TraceLog => $setup->{log_file},
620 Trace => 'DEFAULT:10 facts:20',
621
622 AuthUserFile => $setup->{auth_user_file},
623 AuthGroupFile => $setup->{auth_group_file},
624 AuthOrder => 'mod_auth_file.c',
625
626 IfModules => {
627 'mod_delay.c' => {
628 DelayEngine => 'off',
629 },
630 },
631 };
632
633 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
634 $config);
635
636 # Open pipes, for use between the parent and child processes. Specifically,
637 # the child will indicate when it's done with its test by writing a message
638 # to the parent.
639 my ($rfh, $wfh);
640 unless (pipe($rfh, $wfh)) {
641 die("Can't open pipe: $!");
642 }
643
644 my $ex;
645
646 # Fork child
647 $self->handle_sigchld();
648 defined(my $pid = fork()) or die("Can't fork: $!");
649 if ($pid) {
650 eval {
651 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
652 $client->login($setup->{user}, $setup->{passwd});
653
654 my $opts_args = 'MLST FOO BAR';
655
656 eval { $client->opts($opts_args) };
657 unless ($@) {
658 die("OPTS command succeeded unexpectedly");
659 }
660
661 my $resp_code = $client->response_code();
662 my $resp_msg = $client->response_msg();
663
664 my $expected = 501;
665 $self->assert($expected == $resp_code,
666 test_msg("Expected response code $expected, got $resp_code"));
667
668 $expected = "'OPTS MLST' not understood";
669 $self->assert($expected eq $resp_msg,
670 test_msg("Expected response message '$expected', got '$resp_msg'"));
671
672 $client->quit();
673 };
674 if ($@) {
675 $ex = $@;
676 }
677
678 $wfh->print("done\n");
679 $wfh->flush();
680
681 } else {
682 eval { server_wait($setup->{config_file}, $rfh) };
683 if ($@) {
684 warn($@);
685 exit 1;
686 }
687
688 exit 0;
689 }
690
691 # Stop server
692 server_stop($setup->{pid_file});
693 $self->assert_child_ok($pid);
694
695 test_cleanup($setup->{log_file}, $ex);
696 }
697
698 sub opts_mlst_clear {
699 my $self = shift;
700 my $tmpdir = $self->{tmpdir};
701 my $setup = test_setup($tmpdir, 'facts');
702
703 my $config = {
704 PidFile => $setup->{pid_file},
705 ScoreboardFile => $setup->{scoreboard_file},
706 SystemLog => $setup->{log_file},
707 TraceLog => $setup->{log_file},
708 Trace => 'DEFAULT:10 facts:20',
709
710 AuthUserFile => $setup->{auth_user_file},
711 AuthGroupFile => $setup->{auth_group_file},
712 AuthOrder => 'mod_auth_file.c',
713
714 IfModules => {
715 'mod_delay.c' => {
716 DelayEngine => 'off',
717 },
718 },
719 };
720
721 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
722 $config);
723
724 # Open pipes, for use between the parent and child processes. Specifically,
725 # the child will indicate when it's done with its test by writing a message
726 # to the parent.
727 my ($rfh, $wfh);
728 unless (pipe($rfh, $wfh)) {
729 die("Can't open pipe: $!");
730 }
731
732 my $ex;
733
734 # Fork child
735 $self->handle_sigchld();
736 defined(my $pid = fork()) or die("Can't fork: $!");
737 if ($pid) {
738 eval {
739 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
740 $client->login($setup->{user}, $setup->{passwd});
741
742 # First, discover the current MLST options via FEAT.
743 $client->feat();
744 my $resp_code = $client->response_code();
745 my $resp_msgs = $client->response_msgs();
746
747 my $expected = 211;
748 $self->assert($expected == $resp_code,
749 test_msg("Expected response code $expected, got $resp_code"));
750
751 my $current_mlst_facts;
752
753 my $nfeat = scalar(@$resp_msgs);
754 for (my $i = 0; $i < $nfeat; $i++) {
755 my $feat = $resp_msgs->[$i];
756
757 if ($feat =~ / MLST (.*)/) {
758 $current_mlst_facts = $1;
759 last;
760 }
761 }
762
763 $self->assert(defined($current_mlst_facts),
764 test_msg("Expected to find MLST facts via FEAT"));
765
766 my $opts_args = 'MLST';
767 my $resp_msg;
768 ($resp_code, $resp_msg) = $client->opts($opts_args);
769
770 $expected = 200;
771 $self->assert($expected == $resp_code,
772 test_msg("Expected response code $expected, got $resp_code"));
773
774 $expected = 'MLST OPTS';
775 $self->assert($expected eq $resp_msg,
776 test_msg("Expected response message '$expected', got '$resp_msg'"));
777
778 # Now, read the set MLST options again via FEAT.
779 $client->feat();
780 $resp_code = $client->response_code();
781 $resp_msgs = $client->response_msgs();
782
783 $expected = 211;
784 $self->assert($expected == $resp_code,
785 test_msg("Expected response code $expected, got $resp_code"));
786
787 my $new_mlst_facts;
788
789 $nfeat = scalar(@$resp_msgs);
790 for (my $i = 0; $i < $nfeat; $i++) {
791 my $feat = $resp_msgs->[$i];
792
793 if ($feat =~ / MLST (.*)/) {
794 $new_mlst_facts = $1;
795 last;
796 }
797 }
798
799 # In our new facts, we don't expect to see any '*', which indicate
800 # which, of the supported facts, are enabled.
801 $self->assert($new_mlst_facts !~ /\*/,
802 test_msg("Expected to see no enabled MLST facts via FEAT, saw '$new_mlst_facts'"));
803
804 $client->quit();
805 };
806 if ($@) {
807 $ex = $@;
808 }
809
810 $wfh->print("done\n");
811 $wfh->flush();
812
813 } else {
814 eval { server_wait($setup->{config_file}, $rfh) };
815 if ($@) {
816 warn($@);
817 exit 1;
818 }
819
820 exit 0;
821 }
822
823 # Stop server
824 server_stop($setup->{pid_file});
825 $self->assert_child_ok($pid);
826
827 test_cleanup($setup->{log_file}, $ex);
828 }
829
830 sub opts_mlst_set {
831 my $self = shift;
832 my $tmpdir = $self->{tmpdir};
833 my $setup = test_setup($tmpdir, 'facts');
834
835 my $config = {
836 PidFile => $setup->{pid_file},
837 ScoreboardFile => $setup->{scoreboard_file},
838 SystemLog => $setup->{log_file},
839 TraceLog => $setup->{log_file},
840 Trace => 'DEFAULT:10 facts:20',
841
842 AuthUserFile => $setup->{auth_user_file},
843 AuthGroupFile => $setup->{auth_group_file},
844 AuthOrder => 'mod_auth_file.c',
845
846 IfModules => {
847 'mod_delay.c' => {
848 DelayEngine => 'off',
849 },
850 },
851 };
852
853 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
854 $config);
855
856 # Open pipes, for use between the parent and child processes. Specifically,
857 # the child will indicate when it's done with its test by writing a message
858 # to the parent.
859 my ($rfh, $wfh);
860 unless (pipe($rfh, $wfh)) {
861 die("Can't open pipe: $!");
862 }
863
864 my $ex;
865
866 # Fork child
867 $self->handle_sigchld();
868 defined(my $pid = fork()) or die("Can't fork: $!");
869 if ($pid) {
870 eval {
871 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
872 $client->login($setup->{user}, $setup->{passwd});
873
874 # First, discover the current MLST options via FEAT.
875 $client->feat();
876 my $resp_code = $client->response_code();
877 my $resp_msgs = $client->response_msgs();
878
879 my $expected = 211;
880 $self->assert($expected == $resp_code,
881 test_msg("Expected response code $expected, got $resp_code"));
882
883 my $current_mlst_facts;
884
885 my $nfeat = scalar(@$resp_msgs);
886 for (my $i = 0; $i < $nfeat; $i++) {
887 my $feat = $resp_msgs->[$i];
888
889 if ($feat =~ / MLST (.*)/) {
890 $current_mlst_facts = $1;
891 last;
892 }
893 }
894
895 $self->assert(defined($current_mlst_facts),
896 test_msg("Expected to find MLST facts via FEAT"));
897
898 my $opts_args = 'MLST modify;size;type;';
899 my $resp_msg;
900 ($resp_code, $resp_msg) = $client->opts($opts_args);
901
902 $expected = 200;
903 $self->assert($expected == $resp_code,
904 test_msg("Expected response code $expected, got $resp_code"));
905
906 $expected = 'MLST OPTS modify;size;type;';
907 $self->assert($expected eq $resp_msg,
908 test_msg("Expected response message '$expected', got '$resp_msg'"));
909
910 # Now, read the set MLST options again via FEAT.
911 $client->feat();
912 $resp_code = $client->response_code();
913 $resp_msgs = $client->response_msgs();
914
915 $expected = 211;
916 $self->assert($expected == $resp_code,
917 test_msg("Expected response code $expected, got $resp_code"));
918
919 my $new_mlst_facts;
920
921 $nfeat = scalar(@$resp_msgs);
922 for (my $i = 0; $i < $nfeat; $i++) {
923 my $feat = $resp_msgs->[$i];
924
925 if ($feat =~ / MLST (.*)/) {
926 $new_mlst_facts = $1;
927 last;
928 }
929 }
930
931 $self->assert($new_mlst_facts =~ /modify\*;.*;size\*;type\*;/,
932 test_msg("Expected to see some enabled MLST facts via FEAT, saw '$new_mlst_facts'"));
933
934 $client->quit();
935 };
936 if ($@) {
937 $ex = $@;
938 }
939
940 $wfh->print("done\n");
941 $wfh->flush();
942
943 } else {
944 eval { server_wait($setup->{config_file}, $rfh) };
945 if ($@) {
946 warn($@);
947 exit 1;
948 }
949
950 exit 0;
951 }
952
953 # Stop server
954 server_stop($setup->{pid_file});
955 $self->assert_child_ok($pid);
956
957 test_cleanup($setup->{log_file}, $ex);
958 }
959
960 1;