Debian Codegraph @

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

raw
1 package ProFTPD::Tests::Commands::HELP;
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 :features :running :test :testsuite);
12
13 $| = 1;
14
15 my $order = 0;
16
17 my $TESTS = {
18 help_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 help_ok {
34 my $self = shift;
35 my $tmpdir = $self->{tmpdir};
36 my $setup = test_setup($tmpdir, 'cmds');
37
38 my $config = {
39 PidFile => $setup->{pid_file},
40 ScoreboardFile => $setup->{scoreboard_file},
41 SystemLog => $setup->{log_file},
42
43 AuthUserFile => $setup->{auth_user_file},
44 AuthGroupFile => $setup->{auth_group_file},
45 AuthOrder => 'mod_auth_file.c',
46
47 IfModules => {
48 'mod_delay.c' => {
49 DelayEngine => 'off',
50 },
51 },
52 };
53
54 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
55 $config);
56
57 my $auth_helps = [
58 ' NOOP FEAT OPTS HOST CLNT AUTH* CCC* CONF* ',
59 ' ENC* MIC* PBSZ* PROT* TYPE STRU MODE RETR ',
60 ];
61
62 # Open pipes, for use between the parent and child processes. Specifically,
63 # the child will indicate when it's done with its test by writing a message
64 # to the parent.
65 my ($rfh, $wfh);
66 unless (pipe($rfh, $wfh)) {
67 die("Can't open pipe: $!");
68 }
69
70 my $ex;
71
72 # Fork child
73 $self->handle_sigchld();
74 defined(my $pid = fork()) or die("Can't fork: $!");
75 if ($pid) {
76 eval {
77 # Allow for server startup
78 sleep(2);
79
80 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
81
82 $client->help();
83 my $resp_code = $client->response_code();
84 my $resp_msgs = $client->response_msgs();
85
86 my $expected = 214;
87 $self->assert($expected == $resp_code,
88 test_msg("Expected response code $expected, got $resp_code"));
89
90 $expected = 9;
91 my $nhelp = scalar(@$resp_msgs);
92 $self->assert($expected == $nhelp,
93 test_msg("Expected $expected lines, got $nhelp"));
94
95 my $helps = [(
96 'The following commands are recognized (* =>\'s unimplemented):',
97 ' CWD XCWD CDUP XCUP SMNT* QUIT PORT PASV ',
98 ' EPRT EPSV ALLO RNFR RNTO DELE MDTM RMD ',
99 ' XRMD MKD XMKD PWD XPWD SIZE SYST HELP ',
100 @$auth_helps,
101 ' STOR STOU APPE REST ABOR RANG USER PASS ',
102 ' ACCT* REIN* LIST NLST STAT SITE MLSD MLST ',
103 'Direct comments to [email protected]',
104 )];
105
106 for (my $i = 0; $i < $nhelp; $i++) {
107 $expected = $helps->[$i];
108 $self->assert($expected eq $resp_msgs->[$i],
109 test_msg("Expected '$expected', got '$resp_msgs->[$i]'"));
110 }
111
112 $client->quit();
113 };
114 if ($@) {
115 $ex = $@;
116 }
117
118 $wfh->print("done\n");
119 $wfh->flush();
120
121 } else {
122 eval { server_wait($setup->{config_file}, $rfh) };
123 if ($@) {
124 warn($@);
125 exit 1;
126 }
127
128 exit 0;
129 }
130
131 # Stop server
132 server_stop($setup->{pid_file});
133 $self->assert_child_ok($pid);
134
135 test_cleanup($setup->{log_file}, $ex);
136 }
137
138 1;