Debian Codegraph @

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

raw
1 package ProFTPD::Tests::Config::ServerIdent;
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 serverident_absent => {
19 order => ++$order,
20 test_class => [qw(forking)],
21 },
22
23 serverident_off => {
24 order => ++$order,
25 test_class => [qw(forking)],
26 },
27
28 serverident_on => {
29 order => ++$order,
30 test_class => [qw(forking)],
31 },
32
33 serverident_on_with_servername => {
34 order => ++$order,
35 test_class => [qw(forking)],
36 },
37
38 serverident_on_with_ident => {
39 order => ++$order,
40 test_class => [qw(forking)],
41 },
42
43 serverident_on_with_var_L => {
44 order => ++$order,
45 test_class => [qw(forking)],
46 },
47
48 serverident_on_with_var_V => {
49 order => ++$order,
50 test_class => [qw(forking)],
51 },
52
53 serverident_on_with_var_v => {
54 order => ++$order,
55 test_class => [qw(forking)],
56 },
57
58 serverident_on_with_var_version => {
59 order => ++$order,
60 test_class => [qw(forking)],
61 },
62
63 };
64
65 sub new {
66 return shift()->SUPER::new(@_);
67 }
68
69 sub list_tests {
70 return testsuite_get_runnable_tests($TESTS);
71 }
72
73 sub serverident_absent {
74 my $self = shift;
75 my $tmpdir = $self->{tmpdir};
76 my $setup = test_setup($tmpdir, 'config');
77
78 my $config = {
79 PidFile => $setup->{pid_file},
80 ScoreboardFile => $setup->{scoreboard_file},
81 SystemLog => $setup->{log_file},
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);
109
110 my $resp_code = $client->response_code();
111 my $resp_msg = $client->response_msg();
112
113 my $expected;
114
115 $expected = 220;
116 $self->assert($expected == $resp_code,
117 test_msg("Expected response code $expected, got $resp_code"));
118
119 $expected = 'ProFTPD Server \(ProFTPD\) \[\S+\]';
120 $self->assert(qr/$expected/, $resp_msg,
121 test_msg("Expected response message '$expected', got '$resp_msg'"));
122 };
123
124 if ($@) {
125 $ex = $@;
126 }
127
128 $wfh->print("done\n");
129 $wfh->flush();
130
131 } else {
132 eval { server_wait($setup->{config_file}, $rfh) };
133 if ($@) {
134 warn($@);
135 exit 1;
136 }
137
138 exit 0;
139 }
140
141 # Stop server
142 server_stop($setup->{pid_file});
143
144 $self->assert_child_ok($pid);
145
146 test_cleanup($setup->{log_file}, $ex);
147 }
148
149 sub serverident_off {
150 my $self = shift;
151 my $tmpdir = $self->{tmpdir};
152 my $setup = test_setup($tmpdir, 'config');
153
154 my $config = {
155 PidFile => $setup->{pid_file},
156 ScoreboardFile => $setup->{scoreboard_file},
157 SystemLog => $setup->{log_file},
158
159 ServerIdent => 'off',
160
161 IfModules => {
162 'mod_delay.c' => {
163 DelayEngine => 'off',
164 },
165 },
166 };
167
168 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
169 $config);
170
171 # Open pipes, for use between the parent and child processes. Specifically,
172 # the child will indicate when it's done with its test by writing a message
173 # to the parent.
174 my ($rfh, $wfh);
175 unless (pipe($rfh, $wfh)) {
176 die("Can't open pipe: $!");
177 }
178
179 my $ex;
180
181 # Fork child
182 $self->handle_sigchld();
183 defined(my $pid = fork()) or die("Can't fork: $!");
184 if ($pid) {
185 eval {
186 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
187
188 my $resp_code = $client->response_code();
189 my $resp_msg = $client->response_msg();
190
191 my $expected;
192
193 $expected = 220;
194 $self->assert($expected == $resp_code,
195 test_msg("Expected response code $expected, got $resp_code"));
196
197 $expected = '\S+ FTP server ready';
198 $self->assert(qr/$expected/, $resp_msg,
199 test_msg("Expected response message '$expected', got '$resp_msg'"));
200 };
201
202 if ($@) {
203 $ex = $@;
204 }
205
206 $wfh->print("done\n");
207 $wfh->flush();
208
209 } else {
210 eval { server_wait($setup->{config_file}, $rfh) };
211 if ($@) {
212 warn($@);
213 exit 1;
214 }
215
216 exit 0;
217 }
218
219 # Stop server
220 server_stop($setup->{pid_file});
221
222 $self->assert_child_ok($pid);
223
224 test_cleanup($setup->{log_file}, $ex);
225 }
226
227 sub serverident_on {
228 my $self = shift;
229 my $tmpdir = $self->{tmpdir};
230 my $setup = test_setup($tmpdir, 'config');
231
232 my $config = {
233 PidFile => $setup->{pid_file},
234 ScoreboardFile => $setup->{scoreboard_file},
235 SystemLog => $setup->{log_file},
236
237 ServerIdent => 'on',
238
239 IfModules => {
240 'mod_delay.c' => {
241 DelayEngine => 'off',
242 },
243 },
244 };
245
246 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
247 $config);
248
249 # Open pipes, for use between the parent and child processes. Specifically,
250 # the child will indicate when it's done with its test by writing a message
251 # to the parent.
252 my ($rfh, $wfh);
253 unless (pipe($rfh, $wfh)) {
254 die("Can't open pipe: $!");
255 }
256
257 my $ex;
258
259 # Fork child
260 $self->handle_sigchld();
261 defined(my $pid = fork()) or die("Can't fork: $!");
262 if ($pid) {
263 eval {
264 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
265
266 my $resp_code = $client->response_code();
267 my $resp_msg = $client->response_msg();
268
269 my $expected;
270
271 $expected = 220;
272 $self->assert($expected == $resp_code,
273 test_msg("Expected response code $expected, got $resp_code"));
274
275 $expected = 'ProFTPD Server \(ProFTPD\) \[\S+\]';
276 $self->assert(qr/$expected/, $resp_msg,
277 test_msg("Expected response message '$expected', got '$resp_msg'"));
278 };
279
280 if ($@) {
281 $ex = $@;
282 }
283
284 $wfh->print("done\n");
285 $wfh->flush();
286
287 } else {
288 eval { server_wait($setup->{config_file}, $rfh) };
289 if ($@) {
290 warn($@);
291 exit 1;
292 }
293
294 exit 0;
295 }
296
297 # Stop server
298 server_stop($setup->{pid_file});
299
300 $self->assert_child_ok($pid);
301
302 test_cleanup($setup->{log_file}, $ex);
303 }
304
305 sub serverident_on_with_servername {
306 my $self = shift;
307 my $tmpdir = $self->{tmpdir};
308 my $setup = test_setup($tmpdir, 'config');
309
310 my $server_name = '"Meat Loaf"';
311
312 my $config = {
313 PidFile => $setup->{pid_file},
314 ScoreboardFile => $setup->{scoreboard_file},
315 SystemLog => $setup->{log_file},
316
317 ServerIdent => 'on',
318 ServerName => $server_name,
319
320 IfModules => {
321 'mod_delay.c' => {
322 DelayEngine => 'off',
323 },
324 },
325 };
326
327 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
328 $config);
329
330 # Open pipes, for use between the parent and child processes. Specifically,
331 # the child will indicate when it's done with its test by writing a message
332 # to the parent.
333 my ($rfh, $wfh);
334 unless (pipe($rfh, $wfh)) {
335 die("Can't open pipe: $!");
336 }
337
338 my $ex;
339
340 # Fork child
341 $self->handle_sigchld();
342 defined(my $pid = fork()) or die("Can't fork: $!");
343 if ($pid) {
344 eval {
345 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
346
347 my $resp_code = $client->response_code();
348 my $resp_msg = $client->response_msg();
349
350 my $expected;
351
352 $expected = 220;
353 $self->assert($expected == $resp_code,
354 test_msg("Expected response code $expected, got $resp_code"));
355
356 $server_name =~ s/\"//g;
357 $expected = 'ProFTPD Server \(' . $server_name . '\) \[\S+\]';
358 $self->assert(qr/$expected/, $resp_msg,
359 test_msg("Expected response message '$expected', got '$resp_msg'"));
360 };
361
362 if ($@) {
363 $ex = $@;
364 }
365
366 $wfh->print("done\n");
367 $wfh->flush();
368
369 } else {
370 eval { server_wait($setup->{config_file}, $rfh) };
371 if ($@) {
372 warn($@);
373 exit 1;
374 }
375
376 exit 0;
377 }
378
379 # Stop server
380 server_stop($setup->{pid_file});
381
382 $self->assert_child_ok($pid);
383
384 test_cleanup($setup->{log_file}, $ex);
385 }
386
387 sub serverident_on_with_ident {
388 my $self = shift;
389 my $tmpdir = $self->{tmpdir};
390 my $setup = test_setup($tmpdir, 'config');
391
392 my $server_name = '"Meat Loaf"';
393 my $ident_str = "Yarr!";
394
395 my $config = {
396 PidFile => $setup->{pid_file},
397 ScoreboardFile => $setup->{scoreboard_file},
398 SystemLog => $setup->{log_file},
399
400 ServerIdent => "on $ident_str",
401 ServerName => $server_name,
402
403 IfModules => {
404 'mod_delay.c' => {
405 DelayEngine => 'off',
406 },
407 },
408 };
409
410 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
411 $config);
412
413 # Open pipes, for use between the parent and child processes. Specifically,
414 # the child will indicate when it's done with its test by writing a message
415 # to the parent.
416 my ($rfh, $wfh);
417 unless (pipe($rfh, $wfh)) {
418 die("Can't open pipe: $!");
419 }
420
421 my $ex;
422
423 # Fork child
424 $self->handle_sigchld();
425 defined(my $pid = fork()) or die("Can't fork: $!");
426 if ($pid) {
427 eval {
428 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
429
430 my $resp_code = $client->response_code();
431 my $resp_msg = $client->response_msg();
432
433 my $expected;
434
435 $expected = 220;
436 $self->assert($expected == $resp_code,
437 test_msg("Expected response code $expected, got $resp_code"));
438
439 $expected = $ident_str;
440 $self->assert(qr/$expected/, $resp_msg,
441 test_msg("Expected response message '$expected', got '$resp_msg'"));
442 };
443
444 if ($@) {
445 $ex = $@;
446 }
447
448 $wfh->print("done\n");
449 $wfh->flush();
450
451 } else {
452 eval { server_wait($setup->{config_file}, $rfh) };
453 if ($@) {
454 warn($@);
455 exit 1;
456 }
457
458 exit 0;
459 }
460
461 # Stop server
462 server_stop($setup->{pid_file});
463
464 $self->assert_child_ok($pid);
465
466 test_cleanup($setup->{log_file}, $ex);
467 }
468
469 sub serverident_on_with_var_L {
470 my $self = shift;
471 my $tmpdir = $self->{tmpdir};
472 my $setup = test_setup($tmpdir, 'config');
473
474 my $ident_str = '"Server (%L)"';
475
476 my $config = {
477 PidFile => $setup->{pid_file},
478 ScoreboardFile => $setup->{scoreboard_file},
479 SystemLog => $setup->{log_file},
480
481 ServerIdent => "on $ident_str",
482
483 IfModules => {
484 'mod_delay.c' => {
485 DelayEngine => 'off',
486 },
487 },
488 };
489
490 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
491 $config);
492
493 # Open pipes, for use between the parent and child processes. Specifically,
494 # the child will indicate when it's done with its test by writing a message
495 # to the parent.
496 my ($rfh, $wfh);
497 unless (pipe($rfh, $wfh)) {
498 die("Can't open pipe: $!");
499 }
500
501 my $ex;
502
503 # Fork child
504 $self->handle_sigchld();
505 defined(my $pid = fork()) or die("Can't fork: $!");
506 if ($pid) {
507 eval {
508 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
509
510 my $resp_code = $client->response_code();
511 my $resp_msg = $client->response_msg();
512
513 my $expected;
514
515 $expected = 220;
516 $self->assert($expected == $resp_code,
517 test_msg("Expected response code $expected, got $resp_code"));
518
519 $expected = 'Server (127.0.0.1)';
520 $self->assert($expected eq $resp_msg,
521 test_msg("Expected response message '$expected', got '$resp_msg'"));
522 };
523
524 if ($@) {
525 $ex = $@;
526 }
527
528 $wfh->print("done\n");
529 $wfh->flush();
530
531 } else {
532 eval { server_wait($setup->{config_file}, $rfh) };
533 if ($@) {
534 warn($@);
535 exit 1;
536 }
537
538 exit 0;
539 }
540
541 # Stop server
542 server_stop($setup->{pid_file});
543
544 $self->assert_child_ok($pid);
545
546 test_cleanup($setup->{log_file}, $ex);
547 }
548
549 sub serverident_on_with_var_V {
550 my $self = shift;
551 my $tmpdir = $self->{tmpdir};
552 my $setup = test_setup($tmpdir, 'config');
553
554 my $ident_str = '"Server (%V)"';
555
556 my $config = {
557 PidFile => $setup->{pid_file},
558 ScoreboardFile => $setup->{scoreboard_file},
559 SystemLog => $setup->{log_file},
560
561 ServerIdent => "on $ident_str",
562
563 IfModules => {
564 'mod_delay.c' => {
565 DelayEngine => 'off',
566 },
567 },
568 };
569
570 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
571 $config);
572
573 # Open pipes, for use between the parent and child processes. Specifically,
574 # the child will indicate when it's done with its test by writing a message
575 # to the parent.
576 my ($rfh, $wfh);
577 unless (pipe($rfh, $wfh)) {
578 die("Can't open pipe: $!");
579 }
580
581 my $ex;
582
583 # Fork child
584 $self->handle_sigchld();
585 defined(my $pid = fork()) or die("Can't fork: $!");
586 if ($pid) {
587 eval {
588 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
589
590 my $resp_code = $client->response_code();
591 my $resp_msg = $client->response_msg();
592
593 my $expected;
594
595 $expected = 220;
596 $self->assert($expected == $resp_code,
597 test_msg("Expected response code $expected, got $resp_code"));
598
599 $expected = 'Server (127.0.0.1)';
600 $self->assert($expected eq $resp_msg,
601 test_msg("Expected response message '$expected', got '$resp_msg'"));
602 };
603
604 if ($@) {
605 $ex = $@;
606 }
607
608 $wfh->print("done\n");
609 $wfh->flush();
610
611 } else {
612 eval { server_wait($setup->{config_file}, $rfh) };
613 if ($@) {
614 warn($@);
615 exit 1;
616 }
617
618 exit 0;
619 }
620
621 # Stop server
622 server_stop($setup->{pid_file});
623
624 $self->assert_child_ok($pid);
625
626 test_cleanup($setup->{log_file}, $ex);
627 }
628
629 sub serverident_on_with_var_v {
630 my $self = shift;
631 my $tmpdir = $self->{tmpdir};
632 my $setup = test_setup($tmpdir, 'config');
633
634 my $ident_str = '"Server (%v)"';
635 my $server_name = 'Peeves';
636
637 my $config = {
638 PidFile => $setup->{pid_file},
639 ScoreboardFile => $setup->{scoreboard_file},
640 SystemLog => $setup->{log_file},
641
642 ServerIdent => "on $ident_str",
643 ServerName => $server_name,
644
645 IfModules => {
646 'mod_delay.c' => {
647 DelayEngine => 'off',
648 },
649 },
650 };
651
652 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
653 $config);
654
655 # Open pipes, for use between the parent and child processes. Specifically,
656 # the child will indicate when it's done with its test by writing a message
657 # to the parent.
658 my ($rfh, $wfh);
659 unless (pipe($rfh, $wfh)) {
660 die("Can't open pipe: $!");
661 }
662
663 my $ex;
664
665 # Fork child
666 $self->handle_sigchld();
667 defined(my $pid = fork()) or die("Can't fork: $!");
668 if ($pid) {
669 eval {
670 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
671
672 my $resp_code = $client->response_code();
673 my $resp_msg = $client->response_msg();
674
675 my $expected;
676
677 $expected = 220;
678 $self->assert($expected == $resp_code,
679 test_msg("Expected response code $expected, got $resp_code"));
680
681 $expected = "Server ($server_name)";
682 $self->assert($expected eq $resp_msg,
683 test_msg("Expected response message '$expected', got '$resp_msg'"));
684 };
685
686 if ($@) {
687 $ex = $@;
688 }
689
690 $wfh->print("done\n");
691 $wfh->flush();
692
693 } else {
694 eval { server_wait($setup->{config_file}, $rfh) };
695 if ($@) {
696 warn($@);
697 exit 1;
698 }
699
700 exit 0;
701 }
702
703 # Stop server
704 server_stop($setup->{pid_file});
705
706 $self->assert_child_ok($pid);
707
708 test_cleanup($setup->{log_file}, $ex);
709 }
710
711 sub serverident_on_with_var_version {
712 my $self = shift;
713 my $tmpdir = $self->{tmpdir};
714 my $setup = test_setup($tmpdir, 'config');
715
716 my $ident_str = '"Server (%{version})"';
717
718 my $config = {
719 PidFile => $setup->{pid_file},
720 ScoreboardFile => $setup->{scoreboard_file},
721 SystemLog => $setup->{log_file},
722
723 ServerIdent => "on $ident_str",
724
725 IfModules => {
726 'mod_delay.c' => {
727 DelayEngine => 'off',
728 },
729 },
730 };
731
732 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
733 $config);
734
735 # Open pipes, for use between the parent and child processes. Specifically,
736 # the child will indicate when it's done with its test by writing a message
737 # to the parent.
738 my ($rfh, $wfh);
739 unless (pipe($rfh, $wfh)) {
740 die("Can't open pipe: $!");
741 }
742
743 my $ex;
744
745 # Fork child
746 $self->handle_sigchld();
747 defined(my $pid = fork()) or die("Can't fork: $!");
748 if ($pid) {
749 eval {
750 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
751
752 my $resp_code = $client->response_code();
753 my $resp_msg = $client->response_msg();
754
755 my $expected;
756
757 $expected = 220;
758 $self->assert($expected == $resp_code,
759 test_msg("Expected response code $expected, got $resp_code"));
760
761 $expected = 'Server \(\d+\.\d+\.\d+(.*)?\)';
762 $self->assert(qr/$expected/, $resp_msg,
763 test_msg("Expected response message '$expected', got '$resp_msg'"));
764 };
765
766 if ($@) {
767 $ex = $@;
768 }
769
770 $wfh->print("done\n");
771 $wfh->flush();
772
773 } else {
774 eval { server_wait($setup->{config_file}, $rfh) };
775 if ($@) {
776 warn($@);
777 exit 1;
778 }
779
780 exit 0;
781 }
782
783 # Stop server
784 server_stop($setup->{pid_file});
785
786 $self->assert_child_ok($pid);
787
788 test_cleanup($setup->{log_file}, $ex);
789 }
790
791 1;