Debian Codegraph @

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

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