Debian Codegraph @

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

raw
1 package ProFTPD::Tests::Commands::RANG;
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 rang_ok => {
19 order => ++$order,
20 test_class => [qw(forking)],
21 },
22
23 rang_ok_feat => {
24 order => ++$order,
25 test_class => [qw(forking)],
26 },
27
28 rang_ok_help => {
29 order => ++$order,
30 test_class => [qw(forking)],
31 },
32
33 rang_ok_reset => {
34 order => ++$order,
35 test_class => [qw(forking)],
36 },
37
38 rang_fails_login_required => {
39 order => ++$order,
40 test_class => [qw(forking)],
41 },
42
43 rang_fails_ascii => {
44 order => ++$order,
45 test_class => [qw(forking)],
46 },
47
48 rang_fails_invalid_start => {
49 order => ++$order,
50 test_class => [qw(forking)],
51 },
52
53 rang_fails_invalid_end => {
54 order => ++$order,
55 test_class => [qw(forking)],
56 },
57
58 rang_fails_negative_start => {
59 order => ++$order,
60 test_class => [qw(forking)],
61 },
62
63 rang_fails_negative_end => {
64 order => ++$order,
65 test_class => [qw(forking)],
66 },
67
68 rang_fails_start_after_end => {
69 order => ++$order,
70 test_class => [qw(forking)],
71 },
72
73 rang_retr_ok_with_sendfile => {
74 order => ++$order,
75 test_class => [qw(feature_sendfile forking)],
76 },
77
78 rang_retr_ok_no_sendfile => {
79 order => ++$order,
80 test_class => [qw(forking)],
81 },
82
83 rang_retr_ok_end_exceeds_file_size => {
84 order => ++$order,
85 test_class => [qw(forking)],
86 },
87
88 rang_retr_fails_bad_start => {
89 order => ++$order,
90 test_class => [qw(forking)],
91 },
92
93 rang_stor_ok => {
94 order => ++$order,
95 test_class => [qw(forking)],
96 },
97
98 rang_stor_ok_no_existing_file => {
99 order => ++$order,
100 test_class => [qw(forking)],
101 },
102
103 rang_stor_fails_bad_start => {
104 order => ++$order,
105 test_class => [qw(forking)],
106 },
107
108 rang_stor_fails_too_little_data => {
109 order => ++$order,
110 test_class => [qw(forking)],
111 },
112
113 rang_stor_fails_too_much_data => {
114 order => ++$order,
115 test_class => [qw(forking)],
116 },
117
118 rang_appe_fails => {
119 order => ++$order,
120 test_class => [qw(forking)],
121 },
122
123 rang_stou_fails => {
124 order => ++$order,
125 test_class => [qw(forking)],
126 },
127
128 rang_config_limit_deny => {
129 order => ++$order,
130 test_class => [qw(forking)],
131 },
132
133 };
134
135 sub new {
136 return shift()->SUPER::new(@_);
137 }
138
139 sub list_tests {
140 return testsuite_get_runnable_tests($TESTS);
141 }
142
143 sub rang_ok {
144 my $self = shift;
145 my $tmpdir = $self->{tmpdir};
146 my $setup = test_setup($tmpdir, 'cmds');
147
148 my $config = {
149 PidFile => $setup->{pid_file},
150 ScoreboardFile => $setup->{scoreboard_file},
151 SystemLog => $setup->{log_file},
152
153 AuthUserFile => $setup->{auth_user_file},
154 AuthGroupFile => $setup->{auth_group_file},
155 AuthOrder => 'mod_auth_file.c',
156
157 IfModules => {
158 'mod_delay.c' => {
159 DelayEngine => 'off',
160 },
161 },
162 };
163
164 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
165 $config);
166
167 # Open pipes, for use between the parent and child processes. Specifically,
168 # the child will indicate when it's done with its test by writing a message
169 # to the parent.
170 my ($rfh, $wfh);
171 unless (pipe($rfh, $wfh)) {
172 die("Can't open pipe: $!");
173 }
174
175 my $ex;
176
177 # Fork child
178 $self->handle_sigchld();
179 defined(my $pid = fork()) or die("Can't fork: $!");
180 if ($pid) {
181 eval {
182 # Allow for server startup
183 sleep(1);
184
185 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0);
186 $client->login($setup->{user}, $setup->{passwd});
187 $client->type('binary');
188 my ($resp_code, $resp_msg) = $client->rang(0, 2);
189
190 my $expected = 350;
191 $self->assert($expected == $resp_code,
192 test_msg("Expected response code $expected, got $resp_code"));
193
194 $expected = "Transferring byte range of 3 bytes starting from 0";
195 $self->assert($expected eq $resp_msg,
196 test_msg("Expected response message '$expected', got '$resp_msg'"));
197
198 $client->quit();
199 };
200 if ($@) {
201 $ex = $@;
202 }
203
204 $wfh->print("done\n");
205 $wfh->flush();
206
207 } else {
208 eval { server_wait($setup->{config_file}, $rfh) };
209 if ($@) {
210 warn($@);
211 exit 1;
212 }
213
214 exit 0;
215 }
216
217 # Stop server
218 server_stop($setup->{pid_file});
219 $self->assert_child_ok($pid);
220
221 test_cleanup($setup->{log_file}, $ex);
222 }
223
224 sub rang_ok_feat {
225 my $self = shift;
226 my $tmpdir = $self->{tmpdir};
227 my $setup = test_setup($tmpdir, 'cmds');
228
229 my $config = {
230 PidFile => $setup->{pid_file},
231 ScoreboardFile => $setup->{scoreboard_file},
232 SystemLog => $setup->{log_file},
233
234 AuthUserFile => $setup->{auth_user_file},
235 AuthGroupFile => $setup->{auth_group_file},
236 AuthOrder => 'mod_auth_file.c',
237
238 IfModules => {
239 'mod_delay.c' => {
240 DelayEngine => 'off',
241 },
242 },
243 };
244
245 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
246 $config);
247
248 # Open pipes, for use between the parent and child processes. Specifically,
249 # the child will indicate when it's done with its test by writing a message
250 # to the parent.
251 my ($rfh, $wfh);
252 unless (pipe($rfh, $wfh)) {
253 die("Can't open pipe: $!");
254 }
255
256 my $ex;
257
258 # Fork child
259 $self->handle_sigchld();
260 defined(my $pid = fork()) or die("Can't fork: $!");
261 if ($pid) {
262 eval {
263 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0);
264 $client->feat();
265
266 my $resp_code = $client->response_code();
267 my $resp_msgs = $client->response_msgs();
268
269 my $expected = 211;
270 $self->assert($expected == $resp_code,
271 test_msg("Expected response code $expected, got $resp_code"));
272
273 my $saw_rang_stream = 0;
274 foreach my $feat (@$resp_msgs) {
275 if ($feat =~ /RANG STREAM/i) {
276 $saw_rang_stream = 1;
277 last;
278 }
279 }
280
281 $self->assert($saw_rang_stream,
282 test_msg("Did not see 'RANG STREAM' feature listed via FEAT"));
283
284 $client->quit();
285 };
286 if ($@) {
287 $ex = $@;
288 }
289
290 $wfh->print("done\n");
291 $wfh->flush();
292
293 } else {
294 eval { server_wait($setup->{config_file}, $rfh) };
295 if ($@) {
296 warn($@);
297 exit 1;
298 }
299
300 exit 0;
301 }
302
303 # Stop server
304 server_stop($setup->{pid_file});
305 $self->assert_child_ok($pid);
306
307 test_cleanup($setup->{log_file}, $ex);
308 }
309
310 sub rang_ok_help {
311 my $self = shift;
312 my $tmpdir = $self->{tmpdir};
313 my $setup = test_setup($tmpdir, 'cmds');
314
315 my $config = {
316 PidFile => $setup->{pid_file},
317 ScoreboardFile => $setup->{scoreboard_file},
318 SystemLog => $setup->{log_file},
319
320 AuthUserFile => $setup->{auth_user_file},
321 AuthGroupFile => $setup->{auth_group_file},
322 AuthOrder => 'mod_auth_file.c',
323
324 IfModules => {
325 'mod_delay.c' => {
326 DelayEngine => 'off',
327 },
328 },
329 };
330
331 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
332 $config);
333
334 # Open pipes, for use between the parent and child processes. Specifically,
335 # the child will indicate when it's done with its test by writing a message
336 # to the parent.
337 my ($rfh, $wfh);
338 unless (pipe($rfh, $wfh)) {
339 die("Can't open pipe: $!");
340 }
341
342 my $ex;
343
344 # Fork child
345 $self->handle_sigchld();
346 defined(my $pid = fork()) or die("Can't fork: $!");
347 if ($pid) {
348 eval {
349 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0);
350 $client->help();
351
352 my $resp_code = $client->response_code();
353 my $resp_msgs = $client->response_msgs();
354
355 my $expected = 214;
356 $self->assert($expected == $resp_code,
357 test_msg("Expected response code $expected, got $resp_code"));
358
359 my $saw_rang_stream = 0;
360 foreach my $feat (@$resp_msgs) {
361 if ($feat =~ /RANG/i) {
362 $saw_rang_stream = 1;
363 last;
364 }
365 }
366
367 $self->assert($saw_rang_stream,
368 test_msg("Did not see 'RANG' feature listed via HELP"));
369
370 $client->quit();
371 };
372 if ($@) {
373 $ex = $@;
374 }
375
376 $wfh->print("done\n");
377 $wfh->flush();
378
379 } else {
380 eval { server_wait($setup->{config_file}, $rfh) };
381 if ($@) {
382 warn($@);
383 exit 1;
384 }
385
386 exit 0;
387 }
388
389 # Stop server
390 server_stop($setup->{pid_file});
391 $self->assert_child_ok($pid);
392
393 test_cleanup($setup->{log_file}, $ex);
394 }
395
396 sub rang_ok_reset {
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
406 AuthUserFile => $setup->{auth_user_file},
407 AuthGroupFile => $setup->{auth_group_file},
408 AuthOrder => 'mod_auth_file.c',
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 # Allow for server startup
436 sleep(1);
437
438 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0);
439 $client->login($setup->{user}, $setup->{passwd});
440 my ($resp_code, $resp_msg) = $client->rang(1, 0);
441
442 my $expected = 350;
443 $self->assert($expected == $resp_code,
444 test_msg("Expected response code $expected, got $resp_code"));
445
446 $expected = "Reset byte transfer range";
447 $self->assert($expected eq $resp_msg,
448 test_msg("Expected response message '$expected', got '$resp_msg'"));
449
450 $client->quit();
451 };
452 if ($@) {
453 $ex = $@;
454 }
455
456 $wfh->print("done\n");
457 $wfh->flush();
458
459 } else {
460 eval { server_wait($setup->{config_file}, $rfh) };
461 if ($@) {
462 warn($@);
463 exit 1;
464 }
465
466 exit 0;
467 }
468
469 # Stop server
470 server_stop($setup->{pid_file});
471 $self->assert_child_ok($pid);
472
473 test_cleanup($setup->{log_file}, $ex);
474 }
475
476 sub rang_fails_login_required {
477 my $self = shift;
478 my $tmpdir = $self->{tmpdir};
479 my $setup = test_setup($tmpdir, 'cmds');
480
481 my $config = {
482 PidFile => $setup->{pid_file},
483 ScoreboardFile => $setup->{scoreboard_file},
484 SystemLog => $setup->{log_file},
485
486 IfModules => {
487 'mod_delay.c' => {
488 DelayEngine => 'off',
489 },
490 },
491 };
492
493 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
494 $config);
495
496 # Open pipes, for use between the parent and child processes. Specifically,
497 # the child will indicate when it's done with its test by writing a message
498 # to the parent.
499 my ($rfh, $wfh);
500 unless (pipe($rfh, $wfh)) {
501 die("Can't open pipe: $!");
502 }
503
504 my $ex;
505
506 # Fork child
507 $self->handle_sigchld();
508 defined(my $pid = fork()) or die("Can't fork: $!");
509 if ($pid) {
510 eval {
511 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
512 $client->type('binary');
513
514 eval { $client->rang(0, 1) };
515 unless ($@) {
516 die("REST succeeded unexpectedly");
517 }
518
519 my $resp_code = $client->response_code();
520 my $resp_msg = $client->response_msg();
521
522 my $expected = 530;
523 $self->assert($expected == $resp_code,
524 test_msg("Expected response code $expected, got $resp_code"));
525
526 $expected = "Please login with USER and PASS";
527 $self->assert($expected eq $resp_msg,
528 test_msg("Expected response message '$expected', got '$resp_msg'"));
529 };
530 if ($@) {
531 $ex = $@;
532 }
533
534 $wfh->print("done\n");
535 $wfh->flush();
536
537 } else {
538 eval { server_wait($setup->{config_file}, $rfh) };
539 if ($@) {
540 warn($@);
541 exit 1;
542 }
543
544 exit 0;
545 }
546
547 # Stop server
548 server_stop($setup->{pid_file});
549 $self->assert_child_ok($pid);
550
551 test_cleanup($setup->{log_file}, $ex);
552 }
553
554 sub rang_fails_ascii {
555 my $self = shift;
556 my $tmpdir = $self->{tmpdir};
557 my $setup = test_setup($tmpdir, 'cmds');
558
559 my $config = {
560 PidFile => $setup->{pid_file},
561 ScoreboardFile => $setup->{scoreboard_file},
562 SystemLog => $setup->{log_file},
563
564 AuthUserFile => $setup->{auth_user_file},
565 AuthGroupFile => $setup->{auth_group_file},
566 AuthOrder => 'mod_auth_file.c',
567
568 IfModules => {
569 'mod_delay.c' => {
570 DelayEngine => 'off',
571 },
572 },
573 };
574
575 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
576 $config);
577
578 # Open pipes, for use between the parent and child processes. Specifically,
579 # the child will indicate when it's done with its test by writing a message
580 # to the parent.
581 my ($rfh, $wfh);
582 unless (pipe($rfh, $wfh)) {
583 die("Can't open pipe: $!");
584 }
585
586 my $ex;
587
588 # Fork child
589 $self->handle_sigchld();
590 defined(my $pid = fork()) or die("Can't fork: $!");
591 if ($pid) {
592 eval {
593 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0);
594 $client->login($setup->{user}, $setup->{passwd});
595 eval { $client->rang(0, 2) };
596 unless ($@) {
597 die("RANG succeeded unexpectedly");
598 }
599
600 my $resp_code = $client->response_code();
601 my $resp_msg = $client->response_msg();
602
603 my $expected = 551;
604 $self->assert($expected == $resp_code,
605 test_msg("Expected response code $expected, got $resp_code"));
606
607 $expected = "RANG: Transfer ranges not allowed in ASCII mode";
608 $self->assert($expected eq $resp_msg,
609 test_msg("Expected response message '$expected', got '$resp_msg'"));
610
611 $client->quit();
612 };
613 if ($@) {
614 $ex = $@;
615 }
616
617 $wfh->print("done\n");
618 $wfh->flush();
619
620 } else {
621 eval { server_wait($setup->{config_file}, $rfh) };
622 if ($@) {
623 warn($@);
624 exit 1;
625 }
626
627 exit 0;
628 }
629
630 # Stop server
631 server_stop($setup->{pid_file});
632 $self->assert_child_ok($pid);
633
634 test_cleanup($setup->{log_file}, $ex);
635 }
636
637 sub rang_fails_invalid_start {
638 my $self = shift;
639 my $tmpdir = $self->{tmpdir};
640 my $setup = test_setup($tmpdir, 'cmds');
641
642 my $config = {
643 PidFile => $setup->{pid_file},
644 ScoreboardFile => $setup->{scoreboard_file},
645 SystemLog => $setup->{log_file},
646
647 AuthUserFile => $setup->{auth_user_file},
648 AuthGroupFile => $setup->{auth_group_file},
649 AuthOrder => 'mod_auth_file.c',
650
651 IfModules => {
652 'mod_delay.c' => {
653 DelayEngine => 'off',
654 },
655 },
656 };
657
658 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
659 $config);
660
661 # Open pipes, for use between the parent and child processes. Specifically,
662 # the child will indicate when it's done with its test by writing a message
663 # to the parent.
664 my ($rfh, $wfh);
665 unless (pipe($rfh, $wfh)) {
666 die("Can't open pipe: $!");
667 }
668
669 my $ex;
670
671 # Fork child
672 $self->handle_sigchld();
673 defined(my $pid = fork()) or die("Can't fork: $!");
674 if ($pid) {
675 eval {
676 # Allow for server startup
677 sleep(1);
678
679 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0);
680 $client->login($setup->{user}, $setup->{passwd});
681 $client->type('binary');
682 eval { $client->rang('a', 'b') };
683 unless ($@) {
684 die("RANG succeeded unexpectedly");
685 }
686
687 my $resp_code = $client->response_code();
688 my $resp_msg = $client->response_msg();
689
690 my $expected = 501;
691 $self->assert($expected == $resp_code,
692 test_msg("Expected response code $expected, got $resp_code"));
693
694 $expected = "RANG requires a value greater than or equal to 0";
695 $self->assert($expected eq $resp_msg,
696 test_msg("Expected response message '$expected', got '$resp_msg'"));
697
698 $client->quit();
699 };
700 if ($@) {
701 $ex = $@;
702 }
703
704 $wfh->print("done\n");
705 $wfh->flush();
706
707 } else {
708 eval { server_wait($setup->{config_file}, $rfh) };
709 if ($@) {
710 warn($@);
711 exit 1;
712 }
713
714 exit 0;
715 }
716
717 # Stop server
718 server_stop($setup->{pid_file});
719 $self->assert_child_ok($pid);
720
721 test_cleanup($setup->{log_file}, $ex);
722 }
723
724 sub rang_fails_invalid_end {
725 my $self = shift;
726 my $tmpdir = $self->{tmpdir};
727 my $setup = test_setup($tmpdir, 'cmds');
728
729 my $config = {
730 PidFile => $setup->{pid_file},
731 ScoreboardFile => $setup->{scoreboard_file},
732 SystemLog => $setup->{log_file},
733
734 AuthUserFile => $setup->{auth_user_file},
735 AuthGroupFile => $setup->{auth_group_file},
736 AuthOrder => 'mod_auth_file.c',
737
738 IfModules => {
739 'mod_delay.c' => {
740 DelayEngine => 'off',
741 },
742 },
743 };
744
745 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
746 $config);
747
748 # Open pipes, for use between the parent and child processes. Specifically,
749 # the child will indicate when it's done with its test by writing a message
750 # to the parent.
751 my ($rfh, $wfh);
752 unless (pipe($rfh, $wfh)) {
753 die("Can't open pipe: $!");
754 }
755
756 my $ex;
757
758 # Fork child
759 $self->handle_sigchld();
760 defined(my $pid = fork()) or die("Can't fork: $!");
761 if ($pid) {
762 eval {
763 # Allow for server startup
764 sleep(1);
765
766 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0);
767 $client->login($setup->{user}, $setup->{passwd});
768 $client->type('binary');
769 eval { $client->rang(0, 'b') };
770 unless ($@) {
771 die("RANG succeeded unexpectedly");
772 }
773
774 my $resp_code = $client->response_code();
775 my $resp_msg = $client->response_msg();
776
777 my $expected = 501;
778 $self->assert($expected == $resp_code,
779 test_msg("Expected response code $expected, got $resp_code"));
780
781 $expected = "RANG requires a value greater than or equal to 0";
782 $self->assert($expected eq $resp_msg,
783 test_msg("Expected response message '$expected', got '$resp_msg'"));
784
785 $client->quit();
786 };
787 if ($@) {
788 $ex = $@;
789 }
790
791 $wfh->print("done\n");
792 $wfh->flush();
793
794 } else {
795 eval { server_wait($setup->{config_file}, $rfh) };
796 if ($@) {
797 warn($@);
798 exit 1;
799 }
800
801 exit 0;
802 }
803
804 # Stop server
805 server_stop($setup->{pid_file});
806 $self->assert_child_ok($pid);
807
808 test_cleanup($setup->{log_file}, $ex);
809 }
810
811 sub rang_fails_negative_start {
812 my $self = shift;
813 my $tmpdir = $self->{tmpdir};
814 my $setup = test_setup($tmpdir, 'cmds');
815
816 my $config = {
817 PidFile => $setup->{pid_file},
818 ScoreboardFile => $setup->{scoreboard_file},
819 SystemLog => $setup->{log_file},
820
821 AuthUserFile => $setup->{auth_user_file},
822 AuthGroupFile => $setup->{auth_group_file},
823 AuthOrder => 'mod_auth_file.c',
824
825 IfModules => {
826 'mod_delay.c' => {
827 DelayEngine => 'off',
828 },
829 },
830 };
831
832 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
833 $config);
834
835 # Open pipes, for use between the parent and child processes. Specifically,
836 # the child will indicate when it's done with its test by writing a message
837 # to the parent.
838 my ($rfh, $wfh);
839 unless (pipe($rfh, $wfh)) {
840 die("Can't open pipe: $!");
841 }
842
843 my $ex;
844
845 # Fork child
846 $self->handle_sigchld();
847 defined(my $pid = fork()) or die("Can't fork: $!");
848 if ($pid) {
849 eval {
850 # Allow for server startup
851 sleep(1);
852
853 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0);
854 $client->login($setup->{user}, $setup->{passwd});
855 $client->type('binary');
856 eval { $client->rang(-1, 1) };
857 unless ($@) {
858 die("RANG succeeded unexpectedly");
859 }
860
861 my $resp_code = $client->response_code();
862 my $resp_msg = $client->response_msg();
863
864 my $expected = 501;
865 $self->assert($expected == $resp_code,
866 test_msg("Expected response code $expected, got $resp_code"));
867
868 $expected = "RANG requires a value greater than or equal to 0";
869 $self->assert($expected eq $resp_msg,
870 test_msg("Expected response message '$expected', got '$resp_msg'"));
871
872 $client->quit();
873 };
874 if ($@) {
875 $ex = $@;
876 }
877
878 $wfh->print("done\n");
879 $wfh->flush();
880
881 } else {
882 eval { server_wait($setup->{config_file}, $rfh) };
883 if ($@) {
884 warn($@);
885 exit 1;
886 }
887
888 exit 0;
889 }
890
891 # Stop server
892 server_stop($setup->{pid_file});
893 $self->assert_child_ok($pid);
894
895 test_cleanup($setup->{log_file}, $ex);
896 }
897
898 sub rang_fails_negative_end {
899 my $self = shift;
900 my $tmpdir = $self->{tmpdir};
901 my $setup = test_setup($tmpdir, 'cmds');
902
903 my $config = {
904 PidFile => $setup->{pid_file},
905 ScoreboardFile => $setup->{scoreboard_file},
906 SystemLog => $setup->{log_file},
907
908 AuthUserFile => $setup->{auth_user_file},
909 AuthGroupFile => $setup->{auth_group_file},
910 AuthOrder => 'mod_auth_file.c',
911
912 IfModules => {
913 'mod_delay.c' => {
914 DelayEngine => 'off',
915 },
916 },
917 };
918
919 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
920 $config);
921
922 # Open pipes, for use between the parent and child processes. Specifically,
923 # the child will indicate when it's done with its test by writing a message
924 # to the parent.
925 my ($rfh, $wfh);
926 unless (pipe($rfh, $wfh)) {
927 die("Can't open pipe: $!");
928 }
929
930 my $ex;
931
932 # Fork child
933 $self->handle_sigchld();
934 defined(my $pid = fork()) or die("Can't fork: $!");
935 if ($pid) {
936 eval {
937 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0);
938 $client->login($setup->{user}, $setup->{passwd});
939 $client->type('binary');
940 eval { $client->rang(1, -1) };
941 unless ($@) {
942 die("RANG succeeded unexpectedly");
943 }
944
945 my $resp_code = $client->response_code();
946 my $resp_msg = $client->response_msg();
947
948 my $expected = 501;
949 $self->assert($expected == $resp_code,
950 test_msg("Expected response code $expected, got $resp_code"));
951
952 $expected = "RANG requires a value greater than or equal to 0";
953 $self->assert($expected eq $resp_msg,
954 test_msg("Expected response message '$expected', got '$resp_msg'"));
955
956 $client->quit();
957 };
958 if ($@) {
959 $ex = $@;
960 }
961
962 $wfh->print("done\n");
963 $wfh->flush();
964
965 } else {
966 eval { server_wait($setup->{config_file}, $rfh) };
967 if ($@) {
968 warn($@);
969 exit 1;
970 }
971
972 exit 0;
973 }
974
975 # Stop server
976 server_stop($setup->{pid_file});
977 $self->assert_child_ok($pid);
978
979 test_cleanup($setup->{log_file}, $ex);
980 }
981
982 sub rang_fails_start_after_end {
983 my $self = shift;
984 my $tmpdir = $self->{tmpdir};
985 my $setup = test_setup($tmpdir, 'cmds');
986
987 my $config = {
988 PidFile => $setup->{pid_file},
989 ScoreboardFile => $setup->{scoreboard_file},
990 SystemLog => $setup->{log_file},
991
992 AuthUserFile => $setup->{auth_user_file},
993 AuthGroupFile => $setup->{auth_group_file},
994 AuthOrder => 'mod_auth_file.c',
995
996 IfModules => {
997 'mod_delay.c' => {
998 DelayEngine => 'off',
999 },
1000 },
1001 };
1002
1003 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1004 $config);
1005
1006 # Open pipes, for use between the parent and child processes. Specifically,
1007 # the child will indicate when it's done with its test by writing a message
1008 # to the parent.
1009 my ($rfh, $wfh);
1010 unless (pipe($rfh, $wfh)) {
1011 die("Can't open pipe: $!");
1012 }
1013
1014 my $ex;
1015
1016 # Fork child
1017 $self->handle_sigchld();
1018 defined(my $pid = fork()) or die("Can't fork: $!");
1019 if ($pid) {
1020 eval {
1021 # Allow for server startup
1022 sleep(1);
1023
1024 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0);
1025 $client->login($setup->{user}, $setup->{passwd});
1026 $client->type('binary');
1027 eval { $client->rang(5, 3) };
1028 unless ($@) {
1029 die("RANG succeeded unexpectedly");
1030 }
1031
1032 my $resp_code = $client->response_code();
1033 my $resp_msg = $client->response_msg();
1034
1035 my $expected = 501;
1036 $self->assert($expected == $resp_code,
1037 test_msg("Expected response code $expected, got $resp_code"));
1038
1039 $expected = "RANG start must be less than end";
1040 $self->assert($expected eq $resp_msg,
1041 test_msg("Expected response message '$expected', got '$resp_msg'"));
1042
1043 $client->quit();
1044 };
1045 if ($@) {
1046 $ex = $@;
1047 }
1048
1049 $wfh->print("done\n");
1050 $wfh->flush();
1051
1052 } else {
1053 eval { server_wait($setup->{config_file}, $rfh) };
1054 if ($@) {
1055 warn($@);
1056 exit 1;
1057 }
1058
1059 exit 0;
1060 }
1061
1062 # Stop server
1063 server_stop($setup->{pid_file});
1064 $self->assert_child_ok($pid);
1065
1066 test_cleanup($setup->{log_file}, $ex);
1067 }
1068
1069 sub rang_retr_ok_with_sendfile {
1070 my $self = shift;
1071 my $tmpdir = $self->{tmpdir};
1072 my $setup = test_setup($tmpdir, 'cmds');
1073
1074 my $test_file = File::Spec->rel2abs("$tmpdir/test.dat");
1075 if (open(my $fh, "> $test_file")) {
1076 print $fh "Hello, World!\n";
1077
1078 unless (close($fh)) {
1079 die("Can't write $test_file: $!");
1080 }
1081
1082 # Make sure that, if we're running as root, that the test file has
1083 # permissions/privs set for the account we create
1084 if ($< == 0) {
1085 unless (chown($setup->{uid}, $setup->{gid}, $test_file)) {
1086 die("Can't set owner of $test_file to $setup->{uid}/$setup->{gid}: $!");
1087 }
1088 }
1089
1090 } else {
1091 die("Can't open $test_file: $!");
1092 }
1093
1094 my $config = {
1095 PidFile => $setup->{pid_file},
1096 ScoreboardFile => $setup->{scoreboard_file},
1097 SystemLog => $setup->{log_file},
1098
1099 AuthUserFile => $setup->{auth_user_file},
1100 AuthGroupFile => $setup->{auth_group_file},
1101 AuthOrder => 'mod_auth_file.c',
1102
1103 UseSendfile => 'on',
1104
1105 IfModules => {
1106 'mod_delay.c' => {
1107 DelayEngine => 'off',
1108 },
1109 },
1110 };
1111
1112 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1113 $config);
1114
1115 # Open pipes, for use between the parent and child processes. Specifically,
1116 # the child will indicate when it's done with its test by writing a message
1117 # to the parent.
1118 my ($rfh, $wfh);
1119 unless (pipe($rfh, $wfh)) {
1120 die("Can't open pipe: $!");
1121 }
1122
1123 my $ex;
1124
1125 # Fork child
1126 $self->handle_sigchld();
1127 defined(my $pid = fork()) or die("Can't fork: $!");
1128 if ($pid) {
1129 eval {
1130 # Allow for server startup
1131 sleep(1);
1132
1133 my $io_timeout = 5;
1134 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0,
1135 $io_timeout, $io_timeout);
1136 $client->login($setup->{user}, $setup->{passwd});
1137 $client->type('binary');
1138 $client->rang(1, 3);
1139
1140 my $conn = $client->retr_raw('test.dat');
1141 unless ($conn) {
1142 die("RETR test.dat failed: " . $client->response_code() . ' ' .
1143 $client->response_msg());
1144 }
1145
1146 my $buf;
1147 my $len = $conn->read($buf, 1024, $io_timeout);
1148 sleep(1);
1149 eval { $conn->close($io_timeout) };
1150
1151 my $resp_code = $client->response_code();
1152 my $resp_msg = $client->response_msg();
1153 $self->assert_transfer_ok($resp_code, $resp_msg);
1154 $client->quit();
1155
1156 $self->assert($len == 3, "Expected len 3, got $len");
1157 $self->assert($buf eq 'ell', "Expected 'ell', got '$buf'");
1158 };
1159 if ($@) {
1160 $ex = $@;
1161 }
1162
1163 $wfh->print("done\n");
1164 $wfh->flush();
1165
1166 } else {
1167 eval { server_wait($setup->{config_file}, $rfh) };
1168 if ($@) {
1169 warn($@);
1170 exit 1;
1171 }
1172
1173 exit 0;
1174 }
1175
1176 # Stop server
1177 server_stop($setup->{pid_file});
1178 $self->assert_child_ok($pid);
1179
1180 test_cleanup($setup->{log_file}, $ex);
1181 }
1182
1183 sub rang_retr_ok_no_sendfile {
1184 my $self = shift;
1185 my $tmpdir = $self->{tmpdir};
1186 my $setup = test_setup($tmpdir, 'cmds');
1187
1188 my $test_file = File::Spec->rel2abs("$tmpdir/test.dat");
1189 if (open(my $fh, "> $test_file")) {
1190 print $fh "Hello, World!\n";
1191
1192 unless (close($fh)) {
1193 die("Can't write $test_file: $!");
1194 }
1195
1196 } else {
1197 die("Can't open $test_file: $!");
1198 }
1199
1200 my $config = {
1201 PidFile => $setup->{pid_file},
1202 ScoreboardFile => $setup->{scoreboard_file},
1203 SystemLog => $setup->{log_file},
1204
1205 AuthUserFile => $setup->{auth_user_file},
1206 AuthGroupFile => $setup->{auth_group_file},
1207 AuthOrder => 'mod_auth_file.c',
1208
1209 UseSendfile => 'off',
1210
1211 IfModules => {
1212 'mod_delay.c' => {
1213 DelayEngine => 'off',
1214 },
1215 },
1216 };
1217
1218 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1219 $config);
1220
1221 # Open pipes, for use between the parent and child processes. Specifically,
1222 # the child will indicate when it's done with its test by writing a message
1223 # to the parent.
1224 my ($rfh, $wfh);
1225 unless (pipe($rfh, $wfh)) {
1226 die("Can't open pipe: $!");
1227 }
1228
1229 my $ex;
1230
1231 # Fork child
1232 $self->handle_sigchld();
1233 defined(my $pid = fork()) or die("Can't fork: $!");
1234 if ($pid) {
1235 eval {
1236 # Allow for server startup
1237 sleep(1);
1238
1239 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0);
1240 $client->login($setup->{user}, $setup->{passwd});
1241 $client->type('binary');
1242 $client->rang(1, 3);
1243
1244 my $conn = $client->retr_raw('test.dat');
1245 unless ($conn) {
1246 die("RETR test.dat failed: " . $client->response_code() . ' ' .
1247 $client->response_msg());
1248 }
1249
1250 my $buf;
1251 my $len = $conn->read($buf, 1024);
1252 eval { $conn->close() };
1253
1254 my $resp_code = $client->response_code();
1255 my $resp_msg = $client->response_msg();
1256 $self->assert_transfer_ok($resp_code, $resp_msg);
1257 $client->quit();
1258
1259 $self->assert($len == 3, "Expected len 3, got $len");
1260 $self->assert($buf eq 'ell', "Expected 'ell', got '$buf'");
1261 };
1262 if ($@) {
1263 $ex = $@;
1264 }
1265
1266 $wfh->print("done\n");
1267 $wfh->flush();
1268
1269 } else {
1270 eval { server_wait($setup->{config_file}, $rfh) };
1271 if ($@) {
1272 warn($@);
1273 exit 1;
1274 }
1275
1276 exit 0;
1277 }
1278
1279 # Stop server
1280 server_stop($setup->{pid_file});
1281 $self->assert_child_ok($pid);
1282
1283 test_cleanup($setup->{log_file}, $ex);
1284 }
1285
1286 sub rang_retr_ok_end_exceeds_file_size {
1287 my $self = shift;
1288 my $tmpdir = $self->{tmpdir};
1289 my $setup = test_setup($tmpdir, 'cmds');
1290
1291 my $test_file = File::Spec->rel2abs("$tmpdir/test.dat");
1292 if (open(my $fh, "> $test_file")) {
1293 print $fh "Hello, World!\n";
1294
1295 unless (close($fh)) {
1296 die("Can't write $test_file: $!");
1297 }
1298
1299 } else {
1300 die("Can't open $test_file: $!");
1301 }
1302
1303 my $config = {
1304 PidFile => $setup->{pid_file},
1305 ScoreboardFile => $setup->{scoreboard_file},
1306 SystemLog => $setup->{log_file},
1307
1308 AuthUserFile => $setup->{auth_user_file},
1309 AuthGroupFile => $setup->{auth_group_file},
1310 AuthOrder => 'mod_auth_file.c',
1311
1312 IfModules => {
1313 'mod_delay.c' => {
1314 DelayEngine => 'off',
1315 },
1316 },
1317 };
1318
1319 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1320 $config);
1321
1322 # Open pipes, for use between the parent and child processes. Specifically,
1323 # the child will indicate when it's done with its test by writing a message
1324 # to the parent.
1325 my ($rfh, $wfh);
1326 unless (pipe($rfh, $wfh)) {
1327 die("Can't open pipe: $!");
1328 }
1329
1330 my $ex;
1331
1332 # Fork child
1333 $self->handle_sigchld();
1334 defined(my $pid = fork()) or die("Can't fork: $!");
1335 if ($pid) {
1336 eval {
1337 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0);
1338 $client->login($setup->{user}, $setup->{passwd});
1339 $client->type('binary');
1340 $client->rang(0, 200);
1341
1342 my $conn = $client->retr_raw('test.dat');
1343 unless ($conn) {
1344 die("RETR test.dat failed: " . $client->response_code() . ' ' .
1345 $client->response_msg());
1346 }
1347
1348 my $buf;
1349 my $len = $conn->read($buf, 1024);
1350 eval { $conn->close() };
1351
1352 my $resp_code = $client->response_code();
1353 my $resp_msg = $client->response_msg();
1354 $self->assert_transfer_ok($resp_code, $resp_msg);
1355 $client->quit();
1356
1357 $self->assert($len == 14, "Expected len 14, got $len");
1358 $self->assert($buf eq "Hello, World!\n", "Expected 'Hello, World!\n', got '$buf'");
1359 };
1360 if ($@) {
1361 $ex = $@;
1362 }
1363
1364 $wfh->print("done\n");
1365 $wfh->flush();
1366
1367 } else {
1368 eval { server_wait($setup->{config_file}, $rfh) };
1369 if ($@) {
1370 warn($@);
1371 exit 1;
1372 }
1373
1374 exit 0;
1375 }
1376
1377 # Stop server
1378 server_stop($setup->{pid_file});
1379 $self->assert_child_ok($pid);
1380
1381 test_cleanup($setup->{log_file}, $ex);
1382 }
1383
1384 sub rang_retr_fails_bad_start {
1385 my $self = shift;
1386 my $tmpdir = $self->{tmpdir};
1387 my $setup = test_setup($tmpdir, 'cmds');
1388
1389 my $test_file = File::Spec->rel2abs("$tmpdir/test.dat");
1390 if (open(my $fh, "> $test_file")) {
1391 print $fh "Hello, World!\n";
1392
1393 unless (close($fh)) {
1394 die("Can't write $test_file: $!");
1395 }
1396
1397 } else {
1398 die("Can't open $test_file: $!");
1399 }
1400
1401 my $config = {
1402 PidFile => $setup->{pid_file},
1403 ScoreboardFile => $setup->{scoreboard_file},
1404 SystemLog => $setup->{log_file},
1405
1406 AuthUserFile => $setup->{auth_user_file},
1407 AuthGroupFile => $setup->{auth_group_file},
1408 AuthOrder => 'mod_auth_file.c',
1409
1410 IfModules => {
1411 'mod_delay.c' => {
1412 DelayEngine => 'off',
1413 },
1414 },
1415 };
1416
1417 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1418 $config);
1419
1420 # Open pipes, for use between the parent and child processes. Specifically,
1421 # the child will indicate when it's done with its test by writing a message
1422 # to the parent.
1423 my ($rfh, $wfh);
1424 unless (pipe($rfh, $wfh)) {
1425 die("Can't open pipe: $!");
1426 }
1427
1428 my $ex;
1429
1430 # Fork child
1431 $self->handle_sigchld();
1432 defined(my $pid = fork()) or die("Can't fork: $!");
1433 if ($pid) {
1434 eval {
1435 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0);
1436 $client->login($setup->{user}, $setup->{passwd});
1437 $client->type('binary');
1438 $client->rang(200, 400);
1439
1440 my $conn = $client->retr_raw('test.dat');
1441 if ($conn) {
1442 die("RETR test.dat succeeded unexpectedly");
1443 }
1444
1445 my $resp_code = $client->response_code();
1446 my $resp_msg = $client->response_msg();
1447
1448 my $expected = 554;
1449 $self->assert($resp_code == $expected,
1450 "Expected response code $expected, got $resp_code");
1451
1452 $expected = "RANG: invalid test.dat argument";
1453 $self->assert($resp_msg eq $expected,
1454 "Expected response message '$expected', got '$resp_msg'");
1455
1456 $client->quit();
1457 };
1458 if ($@) {
1459 $ex = $@;
1460 }
1461
1462 $wfh->print("done\n");
1463 $wfh->flush();
1464
1465 } else {
1466 eval { server_wait($setup->{config_file}, $rfh) };
1467 if ($@) {
1468 warn($@);
1469 exit 1;
1470 }
1471
1472 exit 0;
1473 }
1474
1475 # Stop server
1476 server_stop($setup->{pid_file});
1477 $self->assert_child_ok($pid);
1478
1479 test_cleanup($setup->{log_file}, $ex);
1480 }
1481
1482 sub rang_stor_ok {
1483 my $self = shift;
1484 my $tmpdir = $self->{tmpdir};
1485 my $setup = test_setup($tmpdir, 'cmds');
1486
1487 my $test_file = File::Spec->rel2abs("$tmpdir/test.dat");
1488 if (open(my $fh, "> $test_file")) {
1489 print $fh "Hello, World!\n";
1490
1491 unless (close($fh)) {
1492 die("Can't write $test_file: $!");
1493 }
1494
1495 # Make sure that, if we're running as root, that the test file has
1496 # permissions/privs set for the account we create
1497 if ($< == 0) {
1498 unless (chown($setup->{uid}, $setup->{gid}, $test_file)) {
1499 die("Can't set owner of $test_file to $setup->{uid}/$setup->{gid}: $!");
1500 }
1501 }
1502
1503 } else {
1504 die("Can't open $test_file: $!");
1505 }
1506
1507 my $config = {
1508 PidFile => $setup->{pid_file},
1509 ScoreboardFile => $setup->{scoreboard_file},
1510 SystemLog => $setup->{log_file},
1511
1512 AuthUserFile => $setup->{auth_user_file},
1513 AuthGroupFile => $setup->{auth_group_file},
1514 AuthOrder => 'mod_auth_file.c',
1515
1516 AllowOverwrite => 'on',
1517 AllowStoreRestart => 'on',
1518
1519 IfModules => {
1520 'mod_delay.c' => {
1521 DelayEngine => 'off',
1522 },
1523 },
1524 };
1525
1526 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1527 $config);
1528
1529 # Open pipes, for use between the parent and child processes. Specifically,
1530 # the child will indicate when it's done with its test by writing a message
1531 # to the parent.
1532 my ($rfh, $wfh);
1533 unless (pipe($rfh, $wfh)) {
1534 die("Can't open pipe: $!");
1535 }
1536
1537 my $ex;
1538
1539 # Fork child
1540 $self->handle_sigchld();
1541 defined(my $pid = fork()) or die("Can't fork: $!");
1542 if ($pid) {
1543 eval {
1544 # Allow for server startup
1545 sleep(1);
1546
1547 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0);
1548 $client->login($setup->{user}, $setup->{passwd});
1549 $client->type('binary');
1550 $client->rang(0, 0);
1551
1552 my $conn = $client->stor_raw('test.dat');
1553 unless ($conn) {
1554 die("STOR test.dat failed: " . $client->response_code() . ' ' .
1555 $client->response_msg());
1556 }
1557
1558 my $buf = 'h';
1559 $conn->write($buf, length($buf));
1560 eval { $conn->close() };
1561
1562 my $resp_code = $client->response_code();
1563 my $resp_msg = $client->response_msg();
1564 $self->assert_transfer_ok($resp_code, $resp_msg);
1565 $client->quit();
1566
1567 if (open(my $fh, "< $test_file")) {
1568 my $line = <$fh>;
1569 chomp($line);
1570 close($fh);
1571
1572 $self->assert($line eq 'hello, World!',
1573 "Expected 'hello, World!', got '$line'");
1574
1575 } else {
1576 die("Can't read $test_file: $!");
1577 }
1578 };
1579 if ($@) {
1580 $ex = $@;
1581 }
1582
1583 $wfh->print("done\n");
1584 $wfh->flush();
1585
1586 } else {
1587 eval { server_wait($setup->{config_file}, $rfh) };
1588 if ($@) {
1589 warn($@);
1590 exit 1;
1591 }
1592
1593 exit 0;
1594 }
1595
1596 # Stop server
1597 server_stop($setup->{pid_file});
1598 $self->assert_child_ok($pid);
1599
1600 test_cleanup($setup->{log_file}, $ex);
1601 }
1602
1603 sub rang_stor_ok_no_existing_file {
1604 my $self = shift;
1605 my $tmpdir = $self->{tmpdir};
1606 my $setup = test_setup($tmpdir, 'cmds');
1607
1608 my $test_file = File::Spec->rel2abs("$tmpdir/test.dat");
1609
1610 my $config = {
1611 PidFile => $setup->{pid_file},
1612 ScoreboardFile => $setup->{scoreboard_file},
1613 SystemLog => $setup->{log_file},
1614
1615 AuthUserFile => $setup->{auth_user_file},
1616 AuthGroupFile => $setup->{auth_group_file},
1617 AuthOrder => 'mod_auth_file.c',
1618
1619 AllowOverwrite => 'on',
1620 AllowStoreRestart => 'on',
1621
1622 IfModules => {
1623 'mod_delay.c' => {
1624 DelayEngine => 'off',
1625 },
1626 },
1627 };
1628
1629 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1630 $config);
1631
1632 # Open pipes, for use between the parent and child processes. Specifically,
1633 # the child will indicate when it's done with its test by writing a message
1634 # to the parent.
1635 my ($rfh, $wfh);
1636 unless (pipe($rfh, $wfh)) {
1637 die("Can't open pipe: $!");
1638 }
1639
1640 my $ex;
1641
1642 # Fork child
1643 $self->handle_sigchld();
1644 defined(my $pid = fork()) or die("Can't fork: $!");
1645 if ($pid) {
1646 eval {
1647 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0);
1648 $client->login($setup->{user}, $setup->{passwd});
1649 $client->type('binary');
1650 $client->rang(0, 5);
1651
1652 my $conn = $client->stor_raw('test.dat');
1653 unless ($conn) {
1654 die("STOR test.dat failed: " . $client->response_code() . ' ' .
1655 $client->response_msg());
1656 }
1657
1658 my $buf = 'hello!';
1659 $conn->write($buf, length($buf));
1660 eval { $conn->close() };
1661
1662 my $resp_code = $client->response_code();
1663 my $resp_msg = $client->response_msg();
1664 $self->assert_transfer_ok($resp_code, $resp_msg);
1665 $client->quit();
1666
1667 if (open(my $fh, "< $test_file")) {
1668 my $line = <$fh>;
1669 chomp($line);
1670 close($fh);
1671
1672 $self->assert($line eq 'hello!', "Expected 'hello!', got '$line'");
1673
1674 } else {
1675 die("Can't read $test_file: $!");
1676 }
1677 };
1678 if ($@) {
1679 $ex = $@;
1680 }
1681
1682 $wfh->print("done\n");
1683 $wfh->flush();
1684
1685 } else {
1686 eval { server_wait($setup->{config_file}, $rfh) };
1687 if ($@) {
1688 warn($@);
1689 exit 1;
1690 }
1691
1692 exit 0;
1693 }
1694
1695 # Stop server
1696 server_stop($setup->{pid_file});
1697 $self->assert_child_ok($pid);
1698
1699 test_cleanup($setup->{log_file}, $ex);
1700 }
1701
1702 sub rang_stor_fails_bad_start {
1703 my $self = shift;
1704 my $tmpdir = $self->{tmpdir};
1705 my $setup = test_setup($tmpdir, 'cmds');
1706
1707 my $test_file = File::Spec->rel2abs("$tmpdir/test.dat");
1708
1709 my $config = {
1710 PidFile => $setup->{pid_file},
1711 ScoreboardFile => $setup->{scoreboard_file},
1712 SystemLog => $setup->{log_file},
1713
1714 AuthUserFile => $setup->{auth_user_file},
1715 AuthGroupFile => $setup->{auth_group_file},
1716 AuthOrder => 'mod_auth_file.c',
1717
1718 AllowOverwrite => 'on',
1719 AllowStoreRestart => 'on',
1720
1721 IfModules => {
1722 'mod_delay.c' => {
1723 DelayEngine => 'off',
1724 },
1725 },
1726 };
1727
1728 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1729 $config);
1730
1731 # Open pipes, for use between the parent and child processes. Specifically,
1732 # the child will indicate when it's done with its test by writing a message
1733 # to the parent.
1734 my ($rfh, $wfh);
1735 unless (pipe($rfh, $wfh)) {
1736 die("Can't open pipe: $!");
1737 }
1738
1739 my $ex;
1740
1741 # Fork child
1742 $self->handle_sigchld();
1743 defined(my $pid = fork()) or die("Can't fork: $!");
1744 if ($pid) {
1745 eval {
1746 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0);
1747 $client->login($setup->{user}, $setup->{passwd});
1748 $client->type('binary');
1749 $client->rang(1, 5);
1750
1751 my $conn = $client->stor_raw('test.dat');
1752 if ($conn) {
1753 die("STOR test.dat succeeded unexpectedly");
1754 }
1755
1756 my $resp_code = $client->response_code();
1757 my $resp_msg = $client->response_msg();
1758 $client->quit();
1759
1760 my $expected = 554;
1761 $self->assert($resp_code == $expected,
1762 "Expected response code $expected, got $resp_code");
1763
1764 $expected = 'RANG: invalid test.dat argument';
1765 $self->assert($resp_msg eq $expected,
1766 "Expected response message '$expected', got '$resp_msg'");
1767 };
1768 if ($@) {
1769 $ex = $@;
1770 }
1771
1772 $wfh->print("done\n");
1773 $wfh->flush();
1774
1775 } else {
1776 eval { server_wait($setup->{config_file}, $rfh) };
1777 if ($@) {
1778 warn($@);
1779 exit 1;
1780 }
1781
1782 exit 0;
1783 }
1784
1785 # Stop server
1786 server_stop($setup->{pid_file});
1787 $self->assert_child_ok($pid);
1788
1789 test_cleanup($setup->{log_file}, $ex);
1790 }
1791
1792 sub rang_stor_fails_too_little_data {
1793 my $self = shift;
1794 my $tmpdir = $self->{tmpdir};
1795 my $setup = test_setup($tmpdir, 'cmds');
1796
1797 my $test_file = File::Spec->rel2abs("$tmpdir/test.dat");
1798
1799 my $config = {
1800 PidFile => $setup->{pid_file},
1801 ScoreboardFile => $setup->{scoreboard_file},
1802 SystemLog => $setup->{log_file},
1803
1804 AuthUserFile => $setup->{auth_user_file},
1805 AuthGroupFile => $setup->{auth_group_file},
1806 AuthOrder => 'mod_auth_file.c',
1807
1808 AllowOverwrite => 'on',
1809 AllowStoreRestart => 'on',
1810
1811 IfModules => {
1812 'mod_delay.c' => {
1813 DelayEngine => 'off',
1814 },
1815 },
1816 };
1817
1818 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1819 $config);
1820
1821 # Open pipes, for use between the parent and child processes. Specifically,
1822 # the child will indicate when it's done with its test by writing a message
1823 # to the parent.
1824 my ($rfh, $wfh);
1825 unless (pipe($rfh, $wfh)) {
1826 die("Can't open pipe: $!");
1827 }
1828
1829 my $ex;
1830
1831 # Fork child
1832 $self->handle_sigchld();
1833 defined(my $pid = fork()) or die("Can't fork: $!");
1834 if ($pid) {
1835 eval {
1836 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0);
1837 $client->login($setup->{user}, $setup->{passwd});
1838 $client->type('binary');
1839 $client->rang(0, 5);
1840
1841 my $conn = $client->stor_raw('test.dat');
1842 unless ($conn) {
1843 die("STOR test.dat failed: " . $client->response_code() . " " .
1844 $client->response_msg());
1845 }
1846
1847 my $buf = 'hel';
1848 $conn->write($buf, length($buf));
1849 eval { $conn->close() };
1850
1851 my $resp_code = $client->response_code();
1852 my $resp_msg = $client->response_msg();
1853 $client->quit();
1854
1855 my $expected = 426;
1856 $self->assert($resp_code == $expected,
1857 "Expected response code $expected, got $resp_code");
1858
1859 $expected = 'Transfer aborted';
1860 $self->assert(qr/$expected/, $resp_msg,
1861 "Expected response message '$expected', got '$resp_msg'");
1862 };
1863 if ($@) {
1864 $ex = $@;
1865 }
1866
1867 $wfh->print("done\n");
1868 $wfh->flush();
1869
1870 } else {
1871 eval { server_wait($setup->{config_file}, $rfh) };
1872 if ($@) {
1873 warn($@);
1874 exit 1;
1875 }
1876
1877 exit 0;
1878 }
1879
1880 # Stop server
1881 server_stop($setup->{pid_file});
1882 $self->assert_child_ok($pid);
1883
1884 test_cleanup($setup->{log_file}, $ex);
1885 }
1886
1887 sub rang_stor_fails_too_much_data {
1888 my $self = shift;
1889 my $tmpdir = $self->{tmpdir};
1890 my $setup = test_setup($tmpdir, 'cmds');
1891
1892 my $test_file = File::Spec->rel2abs("$tmpdir/test.dat");
1893
1894 my $config = {
1895 PidFile => $setup->{pid_file},
1896 ScoreboardFile => $setup->{scoreboard_file},
1897 SystemLog => $setup->{log_file},
1898
1899 AuthUserFile => $setup->{auth_user_file},
1900 AuthGroupFile => $setup->{auth_group_file},
1901 AuthOrder => 'mod_auth_file.c',
1902
1903 AllowOverwrite => 'on',
1904 AllowStoreRestart => 'on',
1905
1906 IfModules => {
1907 'mod_delay.c' => {
1908 DelayEngine => 'off',
1909 },
1910 },
1911 };
1912
1913 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1914 $config);
1915
1916 # Open pipes, for use between the parent and child processes. Specifically,
1917 # the child will indicate when it's done with its test by writing a message
1918 # to the parent.
1919 my ($rfh, $wfh);
1920 unless (pipe($rfh, $wfh)) {
1921 die("Can't open pipe: $!");
1922 }
1923
1924 my $ex;
1925
1926 # Fork child
1927 $self->handle_sigchld();
1928 defined(my $pid = fork()) or die("Can't fork: $!");
1929 if ($pid) {
1930 eval {
1931 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0);
1932 $client->login($setup->{user}, $setup->{passwd});
1933 $client->type('binary');
1934 $client->rang(0, 5);
1935
1936 my $conn = $client->stor_raw('test.dat');
1937 unless ($conn) {
1938 die("STOR test.dat failed: " . $client->response_code() . " " .
1939 $client->response_msg());
1940 }
1941
1942 my $buf = 'Hello, World!\n';
1943 $conn->write($buf, length($buf));
1944 eval { $conn->close() };
1945
1946 my $resp_code = $client->response_code();
1947 my $resp_msg = $client->response_msg();
1948 $client->quit();
1949
1950 my $expected = 426;
1951 $self->assert($resp_code == $expected,
1952 "Expected response code $expected, got $resp_code");
1953
1954 $expected = 'Transfer aborted';
1955 $self->assert(qr/$expected/, $resp_msg,
1956 "Expected response message '$expected', got '$resp_msg'");
1957 };
1958 if ($@) {
1959 $ex = $@;
1960 }
1961
1962 $wfh->print("done\n");
1963 $wfh->flush();
1964
1965 } else {
1966 eval { server_wait($setup->{config_file}, $rfh) };
1967 if ($@) {
1968 warn($@);
1969 exit 1;
1970 }
1971
1972 exit 0;
1973 }
1974
1975 # Stop server
1976 server_stop($setup->{pid_file});
1977 $self->assert_child_ok($pid);
1978
1979 test_cleanup($setup->{log_file}, $ex);
1980 }
1981
1982 sub rang_appe_fails {
1983 my $self = shift;
1984 my $tmpdir = $self->{tmpdir};
1985 my $setup = test_setup($tmpdir, 'cmds');
1986
1987 my $src_path = File::Spec->rel2abs("$tmpdir/src.dat");
1988 if (open(my $fh, "> $src_path")) {
1989 print $fh "Hello, World!\n";
1990 unless (close($fh)) {
1991 die("Can't write $src_path: $!");
1992 }
1993
1994 } else {
1995 die("Can't open $src_path: $!");
1996 }
1997
1998 my $dst_path = File::Spec->rel2abs("$tmpdir/dst.dat");
1999
2000 my $config = {
2001 PidFile => $setup->{pid_file},
2002 ScoreboardFile => $setup->{scoreboard_file},
2003 SystemLog => $setup->{log_file},
2004
2005 AuthUserFile => $setup->{auth_user_file},
2006 AuthGroupFile => $setup->{auth_group_file},
2007 AuthOrder => 'mod_auth_file.c',
2008
2009 IfModules => {
2010 'mod_delay.c' => {
2011 DelayEngine => 'off',
2012 },
2013 },
2014 };
2015
2016 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
2017 $config);
2018
2019 # Open pipes, for use between the parent and child processes. Specifically,
2020 # the child will indicate when it's done with its test by writing a message
2021 # to the parent.
2022 my ($rfh, $wfh);
2023 unless (pipe($rfh, $wfh)) {
2024 die("Can't open pipe: $!");
2025 }
2026
2027 my $ex;
2028
2029 # Fork child
2030 $self->handle_sigchld();
2031 defined(my $pid = fork()) or die("Can't fork: $!");
2032 if ($pid) {
2033 eval {
2034 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0);
2035 $client->login($setup->{user}, $setup->{passwd});
2036 $client->type('binary');
2037 $client->rang(0, 2);
2038
2039 eval { $client->appe($src_path, $dst_path) };
2040 unless ($@) {
2041 die("APPE succeeded unexpectedly");
2042 }
2043
2044 my $resp_code = $client->response_code();
2045 my $resp_msg = $client->response_msg();
2046
2047 my $expected = 550;
2048 $self->assert($expected == $resp_code,
2049 test_msg("Expected response code $expected, got $resp_code"));
2050
2051 $expected = "APPE incompatible with RANG";
2052 $self->assert($expected eq $resp_msg,
2053 test_msg("Expected response message '$expected', got '$resp_msg'"));
2054
2055 $client->quit();
2056 };
2057 if ($@) {
2058 $ex = $@;
2059 }
2060
2061 $wfh->print("done\n");
2062 $wfh->flush();
2063
2064 } else {
2065 eval { server_wait($setup->{config_file}, $rfh) };
2066 if ($@) {
2067 warn($@);
2068 exit 1;
2069 }
2070
2071 exit 0;
2072 }
2073
2074 # Stop server
2075 server_stop($setup->{pid_file});
2076 $self->assert_child_ok($pid);
2077
2078 test_cleanup($setup->{log_file}, $ex);
2079 }
2080
2081 sub rang_stou_fails {
2082 my $self = shift;
2083 my $tmpdir = $self->{tmpdir};
2084 my $setup = test_setup($tmpdir, 'cmds');
2085
2086 my $src_path = File::Spec->rel2abs("$tmpdir/src.dat");
2087 if (open(my $fh, "> $src_path")) {
2088 print $fh "Hello, World!\n";
2089 unless (close($fh)) {
2090 die("Can't write $src_path: $!");
2091 }
2092
2093 } else {
2094 die("Can't open $src_path: $!");
2095 }
2096
2097 my $dst_path = File::Spec->rel2abs("$tmpdir/dst.dat");
2098
2099 my $config = {
2100 PidFile => $setup->{pid_file},
2101 ScoreboardFile => $setup->{scoreboard_file},
2102 SystemLog => $setup->{log_file},
2103
2104 AuthUserFile => $setup->{auth_user_file},
2105 AuthGroupFile => $setup->{auth_group_file},
2106 AuthOrder => 'mod_auth_file.c',
2107
2108 IfModules => {
2109 'mod_delay.c' => {
2110 DelayEngine => 'off',
2111 },
2112 },
2113 };
2114
2115 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
2116 $config);
2117
2118 # Open pipes, for use between the parent and child processes. Specifically,
2119 # the child will indicate when it's done with its test by writing a message
2120 # to the parent.
2121 my ($rfh, $wfh);
2122 unless (pipe($rfh, $wfh)) {
2123 die("Can't open pipe: $!");
2124 }
2125
2126 my $ex;
2127
2128 # Fork child
2129 $self->handle_sigchld();
2130 defined(my $pid = fork()) or die("Can't fork: $!");
2131 if ($pid) {
2132 eval {
2133 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0);
2134 $client->login($setup->{user}, $setup->{passwd});
2135 $client->type('binary');
2136 $client->rang(0, 2);
2137
2138 eval { $client->stou($src_path, $dst_path) };
2139 unless ($@) {
2140 die("STOU succeeded unexpectedly");
2141 }
2142
2143 my $resp_code = $client->response_code();
2144 my $resp_msg = $client->response_msg();
2145
2146 my $expected = 550;
2147 $self->assert($expected == $resp_code,
2148 test_msg("Expected response code $expected, got $resp_code"));
2149
2150 $expected = "STOU incompatible with RANG";
2151 $self->assert($expected eq $resp_msg,
2152 test_msg("Expected response message '$expected', got '$resp_msg'"));
2153
2154 $client->quit();
2155 };
2156 if ($@) {
2157 $ex = $@;
2158 }
2159
2160 $wfh->print("done\n");
2161 $wfh->flush();
2162
2163 } else {
2164 eval { server_wait($setup->{config_file}, $rfh) };
2165 if ($@) {
2166 warn($@);
2167 exit 1;
2168 }
2169
2170 exit 0;
2171 }
2172
2173 # Stop server
2174 server_stop($setup->{pid_file});
2175 $self->assert_child_ok($pid);
2176
2177 test_cleanup($setup->{log_file}, $ex);
2178 }
2179
2180 sub rang_config_limit_deny {
2181 my $self = shift;
2182 my $tmpdir = $self->{tmpdir};
2183 my $setup = test_setup($tmpdir, 'cmds');
2184
2185 my $config = {
2186 PidFile => $setup->{pid_file},
2187 ScoreboardFile => $setup->{scoreboard_file},
2188 SystemLog => $setup->{log_file},
2189
2190 AuthUserFile => $setup->{auth_user_file},
2191 AuthGroupFile => $setup->{auth_group_file},
2192 AuthOrder => 'mod_auth_file.c',
2193
2194 IfModules => {
2195 'mod_delay.c' => {
2196 DelayEngine => 'off',
2197 },
2198 },
2199 };
2200
2201 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
2202 $config);
2203 if (open(my $fh, ">> $setup->{config_file}")) {
2204 print $fh <<EOC;
2205 <Limit RANG>
2206 DenyAll
2207 </Limit>
2208 EOC
2209 unless (close($fh)) {
2210 die("Can't write $setup->{config_file}: $!");
2211 }
2212
2213 } else {
2214 die("Can't open $setup->{config_file}: $!");
2215 }
2216
2217 # Open pipes, for use between the parent and child processes. Specifically,
2218 # the child will indicate when it's done with its test by writing a message
2219 # to the parent.
2220 my ($rfh, $wfh);
2221 unless (pipe($rfh, $wfh)) {
2222 die("Can't open pipe: $!");
2223 }
2224
2225 my $ex;
2226
2227 # Fork child
2228 $self->handle_sigchld();
2229 defined(my $pid = fork()) or die("Can't fork: $!");
2230 if ($pid) {
2231 eval {
2232 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0);
2233 $client->login($setup->{user}, $setup->{passwd});
2234 $client->type('binary');
2235
2236 eval { $client->rang(0, 2) };
2237 unless ($@) {
2238 die("RANG succeeded unexpectedly");
2239 }
2240
2241 my $resp_code = $client->response_code();
2242 my $resp_msg = $client->response_msg();
2243
2244 my $expected = 552;
2245 $self->assert($expected == $resp_code,
2246 test_msg("Expected response code $expected, got $resp_code"));
2247
2248 $expected = "RANG: Operation not permitted";
2249 $self->assert($expected eq $resp_msg,
2250 test_msg("Expected response message '$expected', got '$resp_msg'"));
2251
2252 $client->quit();
2253 };
2254 if ($@) {
2255 $ex = $@;
2256 }
2257
2258 $wfh->print("done\n");
2259 $wfh->flush();
2260
2261 } else {
2262 eval { server_wait($setup->{config_file}, $rfh) };
2263 if ($@) {
2264 warn($@);
2265 exit 1;
2266 }
2267
2268 exit 0;
2269 }
2270
2271 # Stop server
2272 server_stop($setup->{pid_file});
2273 $self->assert_child_ok($pid);
2274
2275 test_cleanup($setup->{log_file}, $ex);
2276 }
2277
2278 1;