| 1 |
package ProFTPD::Tests::Commands::SYST; |
| 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 |
syst_ok => { |
| 19 |
order => ++$order, |
| 20 |
test_class => [qw(forking)], |
| 21 |
}, |
| 22 |
|
| 23 |
}; |
| 24 |
|
| 25 |
sub new { |
| 26 |
return shift()->SUPER::new(@_); |
| 27 |
} |
| 28 |
|
| 29 |
sub list_tests { |
| 30 |
return testsuite_get_runnable_tests($TESTS); |
| 31 |
} |
| 32 |
|
| 33 |
sub syst_ok { |
| 34 |
my $self = shift; |
| 35 |
my $tmpdir = $self->{tmpdir}; |
| 36 |
|
| 37 |
my $config_file = "$tmpdir/cmds.conf"; |
| 38 |
my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid"); |
| 39 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard"); |
| 40 |
|
| 41 |
my $log_file = test_get_logfile(); |
| 42 |
|
| 43 |
my $config = { |
| 44 |
PidFile => $pid_file, |
| 45 |
ScoreboardFile => $scoreboard_file, |
| 46 |
SystemLog => $log_file, |
| 47 |
|
| 48 |
IfModules => { |
| 49 |
'mod_delay.c' => { |
| 50 |
DelayEngine => 'off', |
| 51 |
}, |
| 52 |
}, |
| 53 |
}; |
| 54 |
|
| 55 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 56 |
|
| 57 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 58 |
# the child will indicate when it's done with its test by writing a message |
| 59 |
# to the parent. |
| 60 |
my ($rfh, $wfh); |
| 61 |
unless (pipe($rfh, $wfh)) { |
| 62 |
die("Can't open pipe: $!"); |
| 63 |
} |
| 64 |
|
| 65 |
my $ex; |
| 66 |
|
| 67 |
# Fork child |
| 68 |
$self->handle_sigchld(); |
| 69 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 70 |
if ($pid) { |
| 71 |
eval { |
| 72 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 73 |
|
| 74 |
my ($resp_code, $resp_msg); |
| 75 |
($resp_code, $resp_msg) = $client->syst(); |
| 76 |
|
| 77 |
my $expected; |
| 78 |
|
| 79 |
$expected = 215; |
| 80 |
$self->assert($expected == $resp_code, |
| 81 |
test_msg("Expected $expected, got $resp_code")); |
| 82 |
|
| 83 |
$expected = "UNIX Type: L8"; |
| 84 |
$self->assert($expected eq $resp_msg, |
| 85 |
test_msg("Expected '$expected', got '$resp_msg'")); |
| 86 |
}; |
| 87 |
|
| 88 |
if ($@) { |
| 89 |
$ex = $@; |
| 90 |
} |
| 91 |
|
| 92 |
$wfh->print("done\n"); |
| 93 |
$wfh->flush(); |
| 94 |
|
| 95 |
} else { |
| 96 |
eval { server_wait($config_file, $rfh) }; |
| 97 |
if ($@) { |
| 98 |
warn($@); |
| 99 |
exit 1; |
| 100 |
} |
| 101 |
|
| 102 |
exit 0; |
| 103 |
} |
| 104 |
|
| 105 |
# Stop server |
| 106 |
server_stop($pid_file); |
| 107 |
|
| 108 |
$self->assert_child_ok($pid); |
| 109 |
|
| 110 |
if ($ex) { |
| 111 |
test_append_logfile($log_file, $ex); |
| 112 |
unlink($log_file); |
| 113 |
|
| 114 |
die($ex); |
| 115 |
} |
| 116 |
|
| 117 |
unlink($log_file); |
| 118 |
} |
| 119 |
|
| 120 |
1; |