Debian Codegraph @

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

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