Debian Codegraph @

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

raw
1 package ProFTPD::Tests::Commands::HOST;
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 use Net::Address::IP::Local;
10
11 use ProFTPD::TestSuite::FTP;
12 use ProFTPD::TestSuite::Utils qw(:auth :config :running :test :testsuite);
13
14 $| = 1;
15
16 my $order = 0;
17
18 my $TESTS = {
19 host_after_login_fails => {
20 order => ++$order,
21 test_class => [qw(forking)],
22 },
23
24 host_login_succeeds => {
25 order => ++$order,
26 test_class => [qw(forking)],
27 },
28
29 # TODO:
30 # host_default_server_login_succeeds
31 # where we do NOT send HOST, and mark an aliased name-based host with
32 # DefaultServer
33
34 host_literal_ipv6_fails_useipv6_off => {
35 order => ++$order,
36 test_class => [qw(feature_ipv6 forking)],
37 },
38
39 host_literal_ipv6_with_port_fails => {
40 order => ++$order,
41 test_class => [qw(feature_ipv6 forking)],
42 },
43
44 host_invalid_ipv4_fails => {
45 order => ++$order,
46 test_class => [qw(forking)],
47 },
48
49 host_ipv4_with_port_fails => {
50 order => ++$order,
51 test_class => [qw(forking)],
52 },
53
54 host_unknown_host_fails => {
55 order => ++$order,
56 test_class => [qw(forking)],
57 },
58
59 host_known_ipv4_same_host_ok => {
60 order => ++$order,
61 test_class => [qw(forking)],
62 },
63
64 host_known_ipv6_same_host_ok => {
65 order => ++$order,
66 test_class => [qw(feature_ipv6 forking)],
67 },
68
69 host_known_ipv4_different_host_fails => {
70 order => ++$order,
71 test_class => [qw(forking)],
72 },
73
74 host_known_ipv6_different_host_fails => {
75 order => ++$order,
76 test_class => [qw(feature_ipv6 forking)],
77 },
78
79 host_known_dns_ok => {
80 order => ++$order,
81 test_class => [qw(forking)],
82 },
83
84 host_before_feat_ok => {
85 order => ++$order,
86 test_class => [qw(forking mod_tls)],
87 },
88
89 host_after_feat_ok => {
90 order => ++$order,
91 test_class => [qw(forking mod_tls)],
92 },
93
94 # Various config situations
95
96 # 2-vhost config, 2 vhost (same addr, different DNS) config,
97
98 host_config_limit_denied => {
99 order => ++$order,
100 test_class => [qw(forking)],
101 },
102 };
103
104 sub new {
105 return shift()->SUPER::new(@_);
106 }
107
108 sub list_tests {
109 return testsuite_get_runnable_tests($TESTS);
110 }
111
112 sub host_login_succeeds {
113 my $self = shift;
114 my $tmpdir = $self->{tmpdir};
115 my $setup = test_setup($tmpdir, 'cmds');
116
117 my $config = {
118 PidFile => $setup->{pid_file},
119 ScoreboardFile => $setup->{scoreboard_file},
120 SystemLog => $setup->{log_file},
121 TraceLog => $setup->{log_file},
122 Trace => 'DEFAULT:20',
123
124 AuthOrder => 'mod_auth_pam.c mod_auth_unix.c',
125 DefaultServer => 'on',
126
127 IfModules => {
128 'mod_delay.c' => {
129 DelayEngine => 'off',
130 },
131 },
132 };
133
134 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
135 $config);
136
137 if (open(my $fh, ">> $setup->{config_file}")) {
138 print $fh <<EOC;
139 <VirtualHost 127.0.0.1>
140 ServerAlias localhost
141 Port $port
142
143 AuthUserFile $setup->{auth_user_file}
144 AuthGroupFile $setup->{auth_group_file}
145 AuthOrder mod_auth_file.c
146
147 <IfModule mod_delay.c>
148 DelayEngine off
149 </IfModule>
150 </VirtualHost>
151 EOC
152 unless (close($fh)) {
153 die("Can't write $setup->{config_file}: $!");
154 }
155
156 } else {
157 die("Can't open $setup->{config_file}: $!");
158 }
159
160 # Open pipes, for use between the parent and child processes. Specifically,
161 # the child will indicate when it's done with its test by writing a message
162 # to the parent.
163 my ($rfh, $wfh);
164 unless (pipe($rfh, $wfh)) {
165 die("Can't open pipe: $!");
166 }
167
168 my $ex;
169
170 # Fork child
171 $self->handle_sigchld();
172 defined(my $pid = fork()) or die("Can't fork: $!");
173 if ($pid) {
174 eval {
175 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
176 $client->host('localhost');
177 $client->login($setup->{user}, $setup->{passwd});
178
179 my $resp_code = $client->response_code();
180 my $resp_msg = $client->response_msg();
181
182 my $expected;
183
184 $expected = 230;
185 $self->assert($expected == $resp_code,
186 test_msg("Expected response code $expected, got $resp_code"));
187
188 $expected = "User $setup->{user} logged in";
189 $self->assert($expected eq $resp_msg,
190 test_msg("Expected response message '$expected', got '$resp_msg'"));
191 };
192
193 if ($@) {
194 $ex = $@;
195 }
196
197 $wfh->print("done\n");
198 $wfh->flush();
199
200 } else {
201 eval { server_wait($setup->{config_file}, $rfh) };
202 if ($@) {
203 warn($@);
204 exit 1;
205 }
206
207 exit 0;
208 }
209
210 # Stop server
211 server_stop($setup->{pid_file});
212
213 $self->assert_child_ok($pid);
214
215 test_cleanup($setup->{log_file}, $ex);
216 }
217
218 sub host_after_login_fails {
219 my $self = shift;
220 my $tmpdir = $self->{tmpdir};
221 my $setup = test_setup($tmpdir, 'cmds');
222
223 my $config = {
224 PidFile => $setup->{pid_file},
225 ScoreboardFile => $setup->{scoreboard_file},
226 SystemLog => $setup->{log_file},
227 TraceLog => $setup->{log_file},
228 Trace => 'DEFAULT:20',
229
230 AuthUserFile => $setup->{auth_user_file},
231 AuthGroupFile => $setup->{auth_group_file},
232 AuthOrder => 'mod_auth_file.c',
233
234 IfModules => {
235 'mod_delay.c' => {
236 DelayEngine => 'off',
237 },
238 },
239 };
240
241 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
242 $config);
243
244 # Open pipes, for use between the parent and child processes. Specifically,
245 # the child will indicate when it's done with its test by writing a message
246 # to the parent.
247 my ($rfh, $wfh);
248 unless (pipe($rfh, $wfh)) {
249 die("Can't open pipe: $!");
250 }
251
252 my $ex;
253
254 # Fork child
255 $self->handle_sigchld();
256 defined(my $pid = fork()) or die("Can't fork: $!");
257 if ($pid) {
258 eval {
259 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
260 $client->login($setup->{user}, $setup->{passwd});
261
262 eval { $client->host('localhost') };
263 unless ($@) {
264 die("HOST after login succeeded unexpectedly");
265 }
266
267 my $resp_code = $client->response_code();
268 my $resp_msg = $client->response_msg();
269
270 my $expected;
271
272 $expected = 503;
273 $self->assert($expected == $resp_code,
274 test_msg("Expected response code $expected, got $resp_code"));
275
276 $expected = "Bad sequence of commands";
277 $self->assert($expected eq $resp_msg,
278 test_msg("Expected response message '$expected', got '$resp_msg'"));
279 };
280
281 if ($@) {
282 $ex = $@;
283 }
284
285 $wfh->print("done\n");
286 $wfh->flush();
287
288 } else {
289 eval { server_wait($setup->{config_file}, $rfh) };
290 if ($@) {
291 warn($@);
292 exit 1;
293 }
294
295 exit 0;
296 }
297
298 # Stop server
299 server_stop($setup->{pid_file});
300
301 $self->assert_child_ok($pid);
302
303 test_cleanup($setup->{log_file}, $ex);
304 }
305
306 sub host_literal_ipv6_fails_useipv6_off {
307 my $self = shift;
308 my $tmpdir = $self->{tmpdir};
309 my $setup = test_setup($tmpdir, 'cmds');
310
311 my $config = {
312 PidFile => $setup->{pid_file},
313 ScoreboardFile => $setup->{scoreboard_file},
314 SystemLog => $setup->{log_file},
315
316 AuthUserFile => $setup->{auth_user_file},
317 AuthGroupFile => $setup->{auth_group_file},
318 AuthOrder => 'mod_auth_file.c',
319
320 UseIPv6 => 'off',
321
322 IfModules => {
323 'mod_delay.c' => {
324 DelayEngine => 'off',
325 },
326 },
327 };
328
329 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
330 $config);
331
332 # Open pipes, for use between the parent and child processes. Specifically,
333 # the child will indicate when it's done with its test by writing a message
334 # to the parent.
335 my ($rfh, $wfh);
336 unless (pipe($rfh, $wfh)) {
337 die("Can't open pipe: $!");
338 }
339
340 my $ex;
341
342 # Fork child
343 $self->handle_sigchld();
344 defined(my $pid = fork()) or die("Can't fork: $!");
345 if ($pid) {
346 eval {
347 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
348
349 my $host = '[::1]';
350 eval { $client->host($host) };
351 unless ($@) {
352 die("HOST after login succeeded unexpectedly");
353 }
354
355 my $resp_code = $client->response_code();
356 my $resp_msg = $client->response_msg();
357
358 my $expected;
359
360 $expected = 501;
361 $self->assert($expected == $resp_code,
362 test_msg("Expected response code $expected, got $resp_code"));
363
364 $expected = "$host: Invalid hostname provided";
365 $self->assert($expected eq $resp_msg,
366 test_msg("Expected response message '$expected', got '$resp_msg'"));
367 };
368
369 if ($@) {
370 $ex = $@;
371 }
372
373 $wfh->print("done\n");
374 $wfh->flush();
375
376 } else {
377 eval { server_wait($setup->{config_file}, $rfh) };
378 if ($@) {
379 warn($@);
380 exit 1;
381 }
382
383 exit 0;
384 }
385
386 # Stop server
387 server_stop($setup->{pid_file});
388
389 $self->assert_child_ok($pid);
390
391 test_cleanup($setup->{log_file}, $ex);
392 }
393
394 sub host_literal_ipv6_with_port_fails {
395 my $self = shift;
396 my $tmpdir = $self->{tmpdir};
397 my $setup = test_setup($tmpdir, 'cmds');
398
399 my $config = {
400 PidFile => $setup->{pid_file},
401 ScoreboardFile => $setup->{scoreboard_file},
402 SystemLog => $setup->{log_file},
403
404 AuthUserFile => $setup->{auth_user_file},
405 AuthGroupFile => $setup->{auth_group_file},
406 AuthOrder => 'mod_auth_file.c',
407
408 UseIPv6 => 'on',
409
410 IfModules => {
411 'mod_delay.c' => {
412 DelayEngine => 'off',
413 },
414 },
415 };
416
417 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
418 $config);
419
420 # Open pipes, for use between the parent and child processes. Specifically,
421 # the child will indicate when it's done with its test by writing a message
422 # to the parent.
423 my ($rfh, $wfh);
424 unless (pipe($rfh, $wfh)) {
425 die("Can't open pipe: $!");
426 }
427
428 my $ex;
429
430 # Fork child
431 $self->handle_sigchld();
432 defined(my $pid = fork()) or die("Can't fork: $!");
433 if ($pid) {
434 eval {
435 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
436
437 my $host = "[::1]:$port";
438 eval { $client->host($host) };
439 unless ($@) {
440 die("HOST after login succeeded unexpectedly");
441 }
442
443 my $resp_code = $client->response_code();
444 my $resp_msg = $client->response_msg();
445
446 my $expected;
447
448 $expected = 501;
449 $self->assert($expected == $resp_code,
450 test_msg("Expected response code $expected, got $resp_code"));
451
452 $expected = "$host: Invalid IPv6 address provided";
453 $self->assert($expected eq $resp_msg,
454 test_msg("Expected response message '$expected', got '$resp_msg'"));
455 };
456
457 if ($@) {
458 $ex = $@;
459 }
460
461 $wfh->print("done\n");
462 $wfh->flush();
463
464 } else {
465 eval { server_wait($setup->{config_file}, $rfh) };
466 if ($@) {
467 warn($@);
468 exit 1;
469 }
470
471 exit 0;
472 }
473
474 # Stop server
475 server_stop($setup->{pid_file});
476
477 $self->assert_child_ok($pid);
478
479 test_cleanup($setup->{log_file}, $ex);
480 }
481
482 sub host_invalid_ipv4_fails {
483 my $self = shift;
484 my $tmpdir = $self->{tmpdir};
485 my $setup = test_setup($tmpdir, 'cmds');
486
487 my $config = {
488 PidFile => $setup->{pid_file},
489 ScoreboardFile => $setup->{scoreboard_file},
490 SystemLog => $setup->{log_file},
491
492 AuthUserFile => $setup->{auth_user_file},
493 AuthGroupFile => $setup->{auth_group_file},
494 AuthOrder => 'mod_auth_file.c',
495
496 IfModules => {
497 'mod_delay.c' => {
498 DelayEngine => 'off',
499 },
500 },
501 };
502
503 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
504 $config);
505
506 # Open pipes, for use between the parent and child processes. Specifically,
507 # the child will indicate when it's done with its test by writing a message
508 # to the parent.
509 my ($rfh, $wfh);
510 unless (pipe($rfh, $wfh)) {
511 die("Can't open pipe: $!");
512 }
513
514 my $ex;
515
516 # Fork child
517 $self->handle_sigchld();
518 defined(my $pid = fork()) or die("Can't fork: $!");
519 if ($pid) {
520 eval {
521 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
522
523 my $host = "300.400.500.600";
524 eval { $client->host($host) };
525 unless ($@) {
526 die("HOST after login succeeded unexpectedly");
527 }
528
529 my $resp_code = $client->response_code();
530 my $resp_msg = $client->response_msg();
531
532 my $expected;
533
534 $expected = 504;
535 $self->assert($expected == $resp_code,
536 test_msg("Expected response code $expected, got $resp_code"));
537
538 $expected = "$host: Unknown hostname provided";
539 $self->assert($expected eq $resp_msg,
540 test_msg("Expected response message '$expected', got '$resp_msg'"));
541 };
542
543 if ($@) {
544 $ex = $@;
545 }
546
547 $wfh->print("done\n");
548 $wfh->flush();
549
550 } else {
551 eval { server_wait($setup->{config_file}, $rfh) };
552 if ($@) {
553 warn($@);
554 exit 1;
555 }
556
557 exit 0;
558 }
559
560 # Stop server
561 server_stop($setup->{pid_file});
562
563 $self->assert_child_ok($pid);
564
565 test_cleanup($setup->{log_file}, $ex);
566 }
567
568 sub host_ipv4_with_port_fails {
569 my $self = shift;
570 my $tmpdir = $self->{tmpdir};
571 my $setup = test_setup($tmpdir, 'cmds');
572
573 my $config = {
574 PidFile => $setup->{pid_file},
575 ScoreboardFile => $setup->{scoreboard_file},
576 SystemLog => $setup->{log_file},
577
578 AuthUserFile => $setup->{auth_user_file},
579 AuthGroupFile => $setup->{auth_group_file},
580 AuthOrder => 'mod_auth_file.c',
581
582 IfModules => {
583 'mod_delay.c' => {
584 DelayEngine => 'off',
585 },
586 },
587 };
588
589 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
590 $config);
591
592 # Open pipes, for use between the parent and child processes. Specifically,
593 # the child will indicate when it's done with its test by writing a message
594 # to the parent.
595 my ($rfh, $wfh);
596 unless (pipe($rfh, $wfh)) {
597 die("Can't open pipe: $!");
598 }
599
600 my $ex;
601
602 # Fork child
603 $self->handle_sigchld();
604 defined(my $pid = fork()) or die("Can't fork: $!");
605 if ($pid) {
606 eval {
607 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
608
609 my $host = "127.0.0.1:$port";
610 eval { $client->host($host) };
611 unless ($@) {
612 die("HOST after login succeeded unexpectedly");
613 }
614
615 my $resp_code = $client->response_code();
616 my $resp_msg = $client->response_msg();
617
618 my $expected;
619
620 $expected = 501;
621 $self->assert($expected == $resp_code,
622 test_msg("Expected response code $expected, got $resp_code"));
623
624 $expected = "$host: Invalid hostname provided";
625 $self->assert($expected eq $resp_msg,
626 test_msg("Expected response message '$expected', got '$resp_msg'"));
627 };
628
629 if ($@) {
630 $ex = $@;
631 }
632
633 $wfh->print("done\n");
634 $wfh->flush();
635
636 } else {
637 eval { server_wait($setup->{config_file}, $rfh) };
638 if ($@) {
639 warn($@);
640 exit 1;
641 }
642
643 exit 0;
644 }
645
646 # Stop server
647 server_stop($setup->{pid_file});
648
649 $self->assert_child_ok($pid);
650
651 test_cleanup($setup->{log_file}, $ex);
652 }
653
654 sub host_unknown_host_fails {
655 my $self = shift;
656 my $tmpdir = $self->{tmpdir};
657 my $setup = test_setup($tmpdir, 'cmds');
658
659 my $config = {
660 PidFile => $setup->{pid_file},
661 ScoreboardFile => $setup->{scoreboard_file},
662 SystemLog => $setup->{log_file},
663
664 AuthUserFile => $setup->{auth_user_file},
665 AuthGroupFile => $setup->{auth_group_file},
666 AuthOrder => 'mod_auth_file.c',
667
668 IfModules => {
669 'mod_delay.c' => {
670 DelayEngine => 'off',
671 },
672 },
673 };
674
675 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
676 $config);
677
678 # Open pipes, for use between the parent and child processes. Specifically,
679 # the child will indicate when it's done with its test by writing a message
680 # to the parent.
681 my ($rfh, $wfh);
682 unless (pipe($rfh, $wfh)) {
683 die("Can't open pipe: $!");
684 }
685
686 my $ex;
687
688 # Fork child
689 $self->handle_sigchld();
690 defined(my $pid = fork()) or die("Can't fork: $!");
691 if ($pid) {
692 eval {
693 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
694 my $host = "nosuchname.proftpd.org";
695
696 eval { $client->host($host) };
697 unless ($@) {
698 die("HOST $host succeeded unexpectedly");
699 }
700
701 my $resp_code = $client->response_code();
702 my $resp_msg = $client->response_msg();
703
704 my $expected;
705
706 $expected = 504;
707 $self->assert($expected == $resp_code,
708 test_msg("Expected response code $expected, got $resp_code"));
709
710 $expected = "$host: Unknown hostname provided";
711 $self->assert($expected eq $resp_msg,
712 test_msg("Expected response message '$expected', got '$resp_msg'"));
713 };
714
715 if ($@) {
716 $ex = $@;
717 }
718
719 $wfh->print("done\n");
720 $wfh->flush();
721
722 } else {
723 eval { server_wait($setup->{config_file}, $rfh) };
724 if ($@) {
725 warn($@);
726 exit 1;
727 }
728
729 exit 0;
730 }
731
732 # Stop server
733 server_stop($setup->{pid_file});
734
735 $self->assert_child_ok($pid);
736
737 test_cleanup($setup->{log_file}, $ex);
738 }
739
740 sub host_known_ipv4_same_host_ok {
741 my $self = shift;
742 my $tmpdir = $self->{tmpdir};
743 my $setup = test_setup($tmpdir, 'cmds');
744
745 my $config = {
746 PidFile => $setup->{pid_file},
747 ScoreboardFile => $setup->{scoreboard_file},
748 SystemLog => $setup->{log_file},
749
750 AuthUserFile => $setup->{auth_user_file},
751 AuthGroupFile => $setup->{auth_group_file},
752 AuthOrder => 'mod_auth_file.c',
753
754 IfModules => {
755 'mod_delay.c' => {
756 DelayEngine => 'off',
757 },
758 },
759 };
760
761 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
762 $config);
763
764 # Open pipes, for use between the parent and child processes. Specifically,
765 # the child will indicate when it's done with its test by writing a message
766 # to the parent.
767 my ($rfh, $wfh);
768 unless (pipe($rfh, $wfh)) {
769 die("Can't open pipe: $!");
770 }
771
772 my $ex;
773
774 # Fork child
775 $self->handle_sigchld();
776 defined(my $pid = fork()) or die("Can't fork: $!");
777 if ($pid) {
778 eval {
779 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
780 my $host = "127.0.0.1";
781
782 $client->host($host);
783 my $resp_code = $client->response_code();
784 my $resp_msg = $client->response_msg();
785
786 my $expected;
787
788 $expected = 220;
789 $self->assert($expected == $resp_code,
790 test_msg("Expected response code $expected, got $resp_code"));
791
792 $expected = "HOST command successful";
793 $self->assert($expected eq $resp_msg,
794 test_msg("Expected response message '$expected', got '$resp_msg'"));
795 };
796
797 if ($@) {
798 $ex = $@;
799 }
800
801 $wfh->print("done\n");
802 $wfh->flush();
803
804 } else {
805 eval { server_wait($setup->{config_file}, $rfh) };
806 if ($@) {
807 warn($@);
808 exit 1;
809 }
810
811 exit 0;
812 }
813
814 # Stop server
815 server_stop($setup->{pid_file});
816
817 $self->assert_child_ok($pid);
818
819 test_cleanup($setup->{log_file}, $ex);
820 }
821
822 sub host_known_ipv6_same_host_ok {
823 my $self = shift;
824 my $tmpdir = $self->{tmpdir};
825 my $setup = test_setup($tmpdir, 'cmds');
826
827 my $config = {
828 PidFile => $setup->{pid_file},
829 ScoreboardFile => $setup->{scoreboard_file},
830 SystemLog => $setup->{log_file},
831
832 AuthUserFile => $setup->{auth_user_file},
833 AuthGroupFile => $setup->{auth_group_file},
834 AuthOrder => 'mod_auth_file.c',
835
836 UseIPv6 => 'on',
837 DefaultAddress => '::1',
838
839 IfModules => {
840 'mod_delay.c' => {
841 DelayEngine => 'off',
842 },
843 },
844 };
845
846 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
847 $config);
848
849 # Open pipes, for use between the parent and child processes. Specifically,
850 # the child will indicate when it's done with its test by writing a message
851 # to the parent.
852 my ($rfh, $wfh);
853 unless (pipe($rfh, $wfh)) {
854 die("Can't open pipe: $!");
855 }
856
857 my $ex;
858
859 # Fork child
860 $self->handle_sigchld();
861 defined(my $pid = fork()) or die("Can't fork: $!");
862 if ($pid) {
863 eval {
864 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
865 my $host = "[::ffff:127.0.0.1]";
866
867 $client->host($host);
868
869 my $resp_code = $client->response_code();
870 my $resp_msg = $client->response_msg();
871
872 my $expected;
873
874 $expected = 220;
875 $self->assert($expected == $resp_code,
876 test_msg("Expected response code $expected, got $resp_code"));
877
878 $expected = "HOST command successful";
879 $self->assert($expected eq $resp_msg,
880 test_msg("Expected response message '$expected', got '$resp_msg'"));
881 };
882
883 if ($@) {
884 $ex = $@;
885 }
886
887 $wfh->print("done\n");
888 $wfh->flush();
889
890 } else {
891 eval { server_wait($setup->{config_file}, $rfh) };
892 if ($@) {
893 warn($@);
894 exit 1;
895 }
896
897 exit 0;
898 }
899
900 # Stop server
901 server_stop($setup->{pid_file});
902
903 $self->assert_child_ok($pid);
904
905 test_cleanup($setup->{log_file}, $ex);
906 }
907
908 sub host_known_ipv4_different_host_fails {
909 my $self = shift;
910 my $tmpdir = $self->{tmpdir};
911 my $setup = test_setup($tmpdir, 'cmds');
912
913 my $vhost_addr = Net::Address::IP::Local->public_ipv4;
914 if (!defined($vhost_addr)) {
915 print STDERR "+ Unable to find additional IPv4 addresses, skipping test\n";
916 return;
917 }
918
919 my $config = {
920 PidFile => $setup->{pid_file},
921 ScoreboardFile => $setup->{scoreboard_file},
922 SystemLog => $setup->{log_file},
923
924 AuthUserFile => $setup->{auth_user_file},
925 AuthGroupFile => $setup->{auth_group_file},
926 AuthOrder => 'mod_auth_file.c',
927
928 IfModules => {
929 'mod_delay.c' => {
930 DelayEngine => 'off',
931 },
932 },
933 };
934
935 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
936 $config);
937
938 if (open(my $fh, ">> $setup->{config_file}")) {
939 print $fh <<EOC;
940 <VirtualHost $vhost_addr>
941 Port $port
942 ServerName "Other Virtual Host"
943 </VirtualHost>
944 EOC
945 unless (close($fh)) {
946 die("Can't write $setup->{config_file}: $!");
947 }
948
949 } else {
950 die("Can't open $setup->{config_file}: $!");
951 }
952
953 # Open pipes, for use between the parent and child processes. Specifically,
954 # the child will indicate when it's done with its test by writing a message
955 # to the parent.
956 my ($rfh, $wfh);
957 unless (pipe($rfh, $wfh)) {
958 die("Can't open pipe: $!");
959 }
960
961 my $ex;
962
963 # Fork child
964 $self->handle_sigchld();
965 defined(my $pid = fork()) or die("Can't fork: $!");
966 if ($pid) {
967 eval {
968 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
969 my $host = $vhost_addr;
970
971 eval { $client->host($host) };
972 unless ($@) {
973 die("HOST $host succeeded unexpectedly");
974 }
975
976 my $resp_code = $client->response_code();
977 my $resp_msg = $client->response_msg();
978
979 my $expected;
980
981 $expected = 504;
982 $self->assert($expected == $resp_code,
983 test_msg("Expected response code $expected, got $resp_code"));
984
985 $expected = "$host: Unknown hostname provided";
986 $self->assert($expected eq $resp_msg,
987 test_msg("Expected response message '$expected', got '$resp_msg'"));
988 };
989
990 if ($@) {
991 $ex = $@;
992 }
993
994 $wfh->print("done\n");
995 $wfh->flush();
996
997 } else {
998 eval { server_wait($setup->{config_file}, $rfh) };
999 if ($@) {
1000 warn($@);
1001 exit 1;
1002 }
1003
1004 exit 0;
1005 }
1006
1007 # Stop server
1008 server_stop($setup->{pid_file});
1009
1010 $self->assert_child_ok($pid);
1011
1012 test_cleanup($setup->{log_file}, $ex);
1013 }
1014
1015 sub host_known_ipv6_different_host_fails {
1016 my $self = shift;
1017 my $tmpdir = $self->{tmpdir};
1018 my $setup = test_setup($tmpdir, 'cmds');
1019
1020 my $vhost_addr = Net::Address::IP::Local->public_ipv6;
1021 if (!defined($vhost_addr)) {
1022 print STDERR "+ Unable to find additional IPv6 addresses, skipping test\n";
1023 return;
1024 }
1025
1026 my $config = {
1027 PidFile => $setup->{pid_file},
1028 ScoreboardFile => $setup->{scoreboard_file},
1029 SystemLog => $setup->{log_file},
1030
1031 AuthUserFile => $setup->{auth_user_file},
1032 AuthGroupFile => $setup->{auth_group_file},
1033 AuthOrder => 'mod_auth_file.c',
1034
1035 UseIPv6 => 'on',
1036 DefaultAddress => '::1',
1037
1038 IfModules => {
1039 'mod_delay.c' => {
1040 DelayEngine => 'off',
1041 },
1042 },
1043 };
1044
1045 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1046 $config);
1047
1048 if (open(my $fh, ">> $setup->{config_file}")) {
1049 print $fh <<EOC;
1050 <VirtualHost $vhost_addr>
1051 Port $port
1052 ServerName "Other Virtual Host"
1053 </VirtualHost>
1054 EOC
1055 unless (close($fh)) {
1056 die("Can't write $setup->{config_file}: $!");
1057 }
1058
1059 } else {
1060 die("Can't open $setup->{config_file}: $!");
1061 }
1062
1063 # Open pipes, for use between the parent and child processes. Specifically,
1064 # the child will indicate when it's done with its test by writing a message
1065 # to the parent.
1066 my ($rfh, $wfh);
1067 unless (pipe($rfh, $wfh)) {
1068 die("Can't open pipe: $!");
1069 }
1070
1071 my $ex;
1072
1073 # Fork child
1074 $self->handle_sigchld();
1075 defined(my $pid = fork()) or die("Can't fork: $!");
1076 if ($pid) {
1077 eval {
1078 my $client = ProFTPD::TestSuite::FTP->new('localhost', $port);
1079 my $host = ('[' . $vhost_addr . ']');
1080
1081 eval { $client->host($host) };
1082 unless ($@) {
1083 die("HOST $host succeeded unexpectedly");
1084 }
1085
1086 my $resp_code = $client->response_code();
1087 my $resp_msg = $client->response_msg();
1088
1089 my $expected;
1090
1091 $expected = 504;
1092 $self->assert($expected == $resp_code,
1093 test_msg("Expected response code $expected, got $resp_code"));
1094
1095 $expected = "$host: Unknown hostname provided";
1096 $self->assert($expected eq $resp_msg,
1097 test_msg("Expected response message '$expected', got '$resp_msg'"));
1098 };
1099
1100 if ($@) {
1101 $ex = $@;
1102 }
1103
1104 $wfh->print("done\n");
1105 $wfh->flush();
1106
1107 } else {
1108 eval { server_wait($setup->{config_file}, $rfh) };
1109 if ($@) {
1110 warn($@);
1111 exit 1;
1112 }
1113
1114 exit 0;
1115 }
1116
1117 # Stop server
1118 server_stop($setup->{pid_file});
1119
1120 $self->assert_child_ok($pid);
1121
1122 test_cleanup($setup->{log_file}, $ex);
1123 }
1124
1125 sub host_known_dns_ok {
1126 my $self = shift;
1127 my $tmpdir = $self->{tmpdir};
1128 my $setup = test_setup($tmpdir, 'cmds');
1129
1130 my $config = {
1131 PidFile => $setup->{pid_file},
1132 ScoreboardFile => $setup->{scoreboard_file},
1133 SystemLog => $setup->{log_file},
1134 TraceLog => $setup->{log_file},
1135 Trace => 'binding:20',
1136
1137 AuthUserFile => $setup->{auth_user_file},
1138 AuthGroupFile => $setup->{auth_group_file},
1139 AuthOrder => 'mod_auth_file.c',
1140
1141 IfModules => {
1142 'mod_delay.c' => {
1143 DelayEngine => 'off',
1144 },
1145 },
1146 };
1147
1148 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1149 $config);
1150
1151 if (open(my $fh, ">> $setup->{config_file}")) {
1152 my $dns_name = 'localhost';
1153
1154 print $fh <<EOC;
1155 <VirtualHost $dns_name>
1156 Port $port
1157 ServerName $dns_name
1158 ServerIdent off
1159 </VirtualHost>
1160 EOC
1161 unless (close($fh)) {
1162 die("Can't write $setup->{config_file}: $!");
1163 }
1164
1165 } else {
1166 die("Can't open $setup->{config_file}: $!");
1167 }
1168
1169 # Open pipes, for use between the parent and child processes. Specifically,
1170 # the child will indicate when it's done with its test by writing a message
1171 # to the parent.
1172 my ($rfh, $wfh);
1173 unless (pipe($rfh, $wfh)) {
1174 die("Can't open pipe: $!");
1175 }
1176
1177 my $ex;
1178
1179 # Fork child
1180 $self->handle_sigchld();
1181 defined(my $pid = fork()) or die("Can't fork: $!");
1182 if ($pid) {
1183 eval {
1184 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1185 my $host = "localhost";
1186
1187 $client->host($host);
1188 my $resp_code = $client->response_code();
1189 my $resp_msg = $client->response_msg();
1190
1191 my $expected;
1192
1193 $expected = 220;
1194 $self->assert($expected == $resp_code,
1195 test_msg("Expected response code $expected, got $resp_code"));
1196
1197 $expected = '127.0.0.1 FTP server ready';
1198 $self->assert($expected eq $resp_msg,
1199 test_msg("Expected response message '$expected', got '$resp_msg'"));
1200 };
1201
1202 if ($@) {
1203 $ex = $@;
1204 }
1205
1206 $wfh->print("done\n");
1207 $wfh->flush();
1208
1209 } else {
1210 eval { server_wait($setup->{config_file}, $rfh) };
1211 if ($@) {
1212 warn($@);
1213 exit 1;
1214 }
1215
1216 exit 0;
1217 }
1218
1219 # Stop server
1220 server_stop($setup->{pid_file});
1221
1222 $self->assert_child_ok($pid);
1223
1224 test_cleanup($setup->{log_file}, $ex);
1225 }
1226
1227 sub host_config_limit_denied {
1228 my $self = shift;
1229 my $tmpdir = $self->{tmpdir};
1230 my $setup = test_setup($tmpdir, 'cmds');
1231
1232 my $config = {
1233 PidFile => $setup->{pid_file},
1234 ScoreboardFile => $setup->{scoreboard_file},
1235 SystemLog => $setup->{log_file},
1236
1237 AuthUserFile => $setup->{auth_user_file},
1238 AuthGroupFile => $setup->{auth_group_file},
1239 AuthOrder => 'mod_auth_file.c',
1240
1241 IfModules => {
1242 'mod_delay.c' => {
1243 DelayEngine => 'off',
1244 },
1245 },
1246 };
1247
1248 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1249 $config);
1250
1251 if (open(my $fh, ">> $setup->{config_file}")) {
1252 print $fh <<EOC;
1253 <Limit HOST>
1254 DenyAll
1255 </Limit>
1256 EOC
1257 unless (close($fh)) {
1258 die("Can't write $setup->{config_file}: $!");
1259 }
1260
1261 } else {
1262 die("Can't open $setup->{config_file}: $!");
1263 }
1264
1265 # Open pipes, for use between the parent and child processes. Specifically,
1266 # the child will indicate when it's done with its test by writing a message
1267 # to the parent.
1268 my ($rfh, $wfh);
1269 unless (pipe($rfh, $wfh)) {
1270 die("Can't open pipe: $!");
1271 }
1272
1273 my $ex;
1274
1275 # Fork child
1276 $self->handle_sigchld();
1277 defined(my $pid = fork()) or die("Can't fork: $!");
1278 if ($pid) {
1279 eval {
1280 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1281
1282 my $host = "127.0.0.1";
1283 eval { $client->host($host) };
1284 unless ($@) {
1285 die("HOST after login succeeded unexpectedly");
1286 }
1287
1288 my $resp_code = $client->response_code();
1289 my $resp_msg = $client->response_msg();
1290
1291 my $expected;
1292
1293 $expected = 504;
1294 $self->assert($expected == $resp_code,
1295 test_msg("Expected response code $expected, got $resp_code"));
1296
1297 $expected = "$host: Permission denied";
1298 $self->assert($expected eq $resp_msg,
1299 test_msg("Expected response message '$expected', got '$resp_msg'"));
1300 };
1301
1302 if ($@) {
1303 $ex = $@;
1304 }
1305
1306 $wfh->print("done\n");
1307 $wfh->flush();
1308
1309 } else {
1310 eval { server_wait($setup->{config_file}, $rfh) };
1311 if ($@) {
1312 warn($@);
1313 exit 1;
1314 }
1315
1316 exit 0;
1317 }
1318
1319 # Stop server
1320 server_stop($setup->{pid_file});
1321
1322 $self->assert_child_ok($pid);
1323
1324 test_cleanup($setup->{log_file}, $ex);
1325 }
1326
1327 sub host_before_feat_ok {
1328 my $self = shift;
1329 my $tmpdir = $self->{tmpdir};
1330 my $setup = test_setup($tmpdir, 'cmds');
1331
1332 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
1333 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
1334
1335 my $server_alias = 'ftp.nospam.org';
1336 my $server_name = 'Other Virtual Host';
1337
1338 my $config = {
1339 PidFile => $setup->{pid_file},
1340 ScoreboardFile => $setup->{scoreboard_file},
1341 SystemLog => $setup->{log_file},
1342
1343 AuthUserFile => $setup->{auth_user_file},
1344 AuthGroupFile => $setup->{auth_group_file},
1345 AuthOrder => 'mod_auth_file.c',
1346
1347 IfModules => {
1348 'mod_delay.c' => {
1349 DelayEngine => 'off',
1350 },
1351 },
1352 };
1353
1354 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1355 $config);
1356
1357 if (open(my $fh, ">> $setup->{config_file}")) {
1358 print $fh <<EOC;
1359 <VirtualHost 127.0.0.1>
1360 Port $port
1361 ServerName "$server_name"
1362 ServerAlias $server_alias
1363
1364 TLSEngine on
1365 TLSLog $setup->{log_file}
1366 TLSRSACertificateFile $cert_file
1367 TLSCACertificateFile $ca_file
1368 </VirtualHost>
1369 EOC
1370 unless (close($fh)) {
1371 die("Can't write $setup->{config_file}: $!");
1372 }
1373
1374 } else {
1375 die("Can't open $setup->{config_file}: $!");
1376 }
1377
1378 # Open pipes, for use between the parent and child processes. Specifically,
1379 # the child will indicate when it's done with its test by writing a message
1380 # to the parent.
1381 my ($rfh, $wfh);
1382 unless (pipe($rfh, $wfh)) {
1383 die("Can't open pipe: $!");
1384 }
1385
1386 my $ex;
1387
1388 # Fork child
1389 $self->handle_sigchld();
1390 defined(my $pid = fork()) or die("Can't fork: $!");
1391 if ($pid) {
1392 eval {
1393 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1394 $client->host($server_alias);
1395 my $resp_code = $client->response_code();
1396 my $resp_msg = $client->response_msg();
1397
1398 my $expected;
1399
1400 $expected = 220;
1401 $self->assert($expected == $resp_code,
1402 test_msg("Expected response code $expected, got $resp_code"));
1403
1404 $expected = $server_name;
1405 $self->assert(qr/$expected/, $resp_msg,
1406 test_msg("Expected response message '$expected', got '$resp_msg'"));
1407
1408 $client->feat();
1409 $resp_code = $client->response_code();
1410 my $resp_msgs = $client->response_msgs();
1411
1412 $expected = 211;
1413 $self->assert($expected == $resp_code,
1414 test_msg("Expected response code $expected, got $resp_code"));
1415
1416 my $saw_auth_tls = 0;
1417 foreach my $feat (@$resp_msgs) {
1418 if ($feat =~ /AUTH TLS/) {
1419 $saw_auth_tls = 1;
1420 last;
1421 }
1422 }
1423
1424 $self->assert($saw_auth_tls,
1425 test_msg("Did not see expected 'AUTH TLS' feature listed via FEAT"));
1426
1427 $client->quit();
1428 };
1429
1430 if ($@) {
1431 $ex = $@;
1432 }
1433
1434 $wfh->print("done\n");
1435 $wfh->flush();
1436
1437 } else {
1438 eval { server_wait($setup->{config_file}, $rfh) };
1439 if ($@) {
1440 warn($@);
1441 exit 1;
1442 }
1443
1444 exit 0;
1445 }
1446
1447 # Stop server
1448 server_stop($setup->{pid_file});
1449
1450 $self->assert_child_ok($pid);
1451
1452 test_cleanup($setup->{log_file}, $ex);
1453 }
1454
1455 sub host_after_feat_ok {
1456 my $self = shift;
1457 my $tmpdir = $self->{tmpdir};
1458 my $setup = test_setup($tmpdir, 'cmds');
1459
1460 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
1461 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
1462
1463 my $server_alias = 'ftp.nospam.org';
1464 my $server_name = 'Other Virtual Host';
1465
1466 my $config = {
1467 PidFile => $setup->{pid_file},
1468 ScoreboardFile => $setup->{scoreboard_file},
1469 SystemLog => $setup->{log_file},
1470
1471 AuthUserFile => $setup->{auth_user_file},
1472 AuthGroupFile => $setup->{auth_group_file},
1473 AuthOrder => 'mod_auth_file.c',
1474
1475 IfModules => {
1476 'mod_delay.c' => {
1477 DelayEngine => 'off',
1478 },
1479 },
1480 };
1481
1482 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1483 $config);
1484
1485 if (open(my $fh, ">> $setup->{config_file}")) {
1486 print $fh <<EOC;
1487 <VirtualHost 127.0.0.1>
1488 Port $port
1489 ServerName "$server_name"
1490 ServerAlias $server_alias
1491
1492 TLSEngine on
1493 TLSLog $setup->{log_file}
1494 TLSRSACertificateFile $cert_file
1495 TLSCACertificateFile $ca_file
1496 </VirtualHost>
1497 EOC
1498 unless (close($fh)) {
1499 die("Can't write $setup->{config_file}: $!");
1500 }
1501
1502 } else {
1503 die("Can't open $setup->{config_file}: $!");
1504 }
1505
1506 # Open pipes, for use between the parent and child processes. Specifically,
1507 # the child will indicate when it's done with its test by writing a message
1508 # to the parent.
1509 my ($rfh, $wfh);
1510 unless (pipe($rfh, $wfh)) {
1511 die("Can't open pipe: $!");
1512 }
1513
1514 my $ex;
1515
1516 # Fork child
1517 $self->handle_sigchld();
1518 defined(my $pid = fork()) or die("Can't fork: $!");
1519 if ($pid) {
1520 eval {
1521 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1522 $client->feat();
1523
1524 my $resp_code = $client->response_code();
1525 my $resp_msgs = $client->response_msgs();
1526
1527 my $expected;
1528
1529 $expected = 211;
1530 $self->assert($expected == $resp_code,
1531 test_msg("Expected response code $expected, got $resp_code"));
1532
1533 my $saw_auth_tls = 0;
1534 foreach my $feat (@$resp_msgs) {
1535 if ($feat =~ /AUTH TLS/) {
1536 $saw_auth_tls = 1;
1537 last;
1538 }
1539 }
1540
1541 $self->assert(!$saw_auth_tls,
1542 test_msg("Saw 'AUTH TLS' feature listed via FEAT unexpectedly"));
1543
1544 $client->host($server_alias);
1545 $resp_code = $client->response_code();
1546 my $resp_msg = $client->response_msg();
1547
1548 $expected = 220;
1549 $self->assert($expected == $resp_code,
1550 test_msg("Expected response code $expected, got $resp_code"));
1551
1552 $expected = $server_name;
1553 $self->assert(qr/$expected/, $resp_msg,
1554 test_msg("Expected response message '$expected', got '$resp_msg'"));
1555
1556 $client->quit();
1557 };
1558
1559 if ($@) {
1560 $ex = $@;
1561 }
1562
1563 $wfh->print("done\n");
1564 $wfh->flush();
1565
1566 } else {
1567 eval { server_wait($setup->{config_file}, $rfh) };
1568 if ($@) {
1569 warn($@);
1570 exit 1;
1571 }
1572
1573 exit 0;
1574 }
1575
1576 # Stop server
1577 server_stop($setup->{pid_file});
1578
1579 $self->assert_child_ok($pid);
1580
1581 test_cleanup($setup->{log_file}, $ex);
1582 }
1583
1584 1;