Debian Codegraph @

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

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