Debian Codegraph @

tests/t/lib/ProFTPD/Tests/Config/Limit/HELP.pm

raw
1 package ProFTPD::Tests::Config::Limit::HELP;
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 limit_help_issue1296 => {
20 order => ++$order,
21 test_class => [qw(forking)],
22 },
23
24 limit_site_help_issue1296 => {
25 order => ++$order,
26 test_class => [qw(forking)],
27 },
28
29 };
30
31 sub new {
32 return shift()->SUPER::new(@_);
33 }
34
35 sub list_tests {
36 return testsuite_get_runnable_tests($TESTS);
37 }
38
39 sub limit_help_issue1296 {
40 my $self = shift;
41 my $tmpdir = $self->{tmpdir};
42 my $setup = test_setup($tmpdir, 'limit');
43
44 my $config = {
45 PidFile => $setup->{pid_file},
46 ScoreboardFile => $setup->{scoreboard_file},
47 SystemLog => $setup->{log_file},
48 TraceLog => $setup->{log_file},
49 Trace => 'command:10 directory:10',
50
51 AuthUserFile => $setup->{auth_user_file},
52 AuthGroupFile => $setup->{auth_group_file},
53 AuthOrder => 'mod_auth_file.c',
54
55 DefaultChdir => '~',
56
57 IfModules => {
58 'mod_delay.c' => {
59 DelayEngine => 'off',
60 },
61 },
62
63 Limit => {
64 HELP => {
65 DenyAll => '',
66 },
67 }
68 };
69
70 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
71 $config);
72
73 # Open pipes, for use between the parent and child processes. Specifically,
74 # the child will indicate when it's done with its test by writing a message
75 # to the parent.
76 my ($rfh, $wfh);
77 unless (pipe($rfh, $wfh)) {
78 die("Can't open pipe: $!");
79 }
80
81 my $ex;
82
83 # Fork child
84 $self->handle_sigchld();
85 defined(my $pid = fork()) or die("Can't fork: $!");
86 if ($pid) {
87 eval {
88 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
89
90 eval { $client->help() };
91 unless ($@) {
92 die("HELP command succeeded unexpectedly");
93 }
94
95 my $resp_code = $client->response_code();
96 my $resp_msg = $client->response_msg();
97
98 my $expected = 501;
99 $self->assert($expected == $resp_code,
100 test_msg("Expected response code $expected, got $resp_code"));
101
102 $expected = 'HELP: Permission denied';
103 $self->assert($expected eq $resp_msg,
104 test_msg("Expected response message '$expected', got '$resp_msg'"));
105
106 $client->login($setup->{user}, $setup->{passwd});
107 eval { $client->help() };
108 unless ($@) {
109 die("HELP command succeeded unexpectedly");
110 }
111
112 $resp_code = $client->response_code();
113 $resp_msg = $client->response_msg();
114
115 $expected = 501;
116 $self->assert($expected == $resp_code,
117 test_msg("Expected response code $expected, got $resp_code"));
118
119 $expected = 'HELP: Permission denied';
120 $self->assert($expected eq $resp_msg,
121 test_msg("Expected response message '$expected', got '$resp_msg'"));
122
123 $client->quit();
124 };
125 if ($@) {
126 $ex = $@;
127 }
128
129 $wfh->print("done\n");
130 $wfh->flush();
131
132 } else {
133 eval { server_wait($setup->{config_file}, $rfh) };
134 if ($@) {
135 warn($@);
136 exit 1;
137 }
138
139 exit 0;
140 }
141
142 # Stop server
143 server_stop($setup->{pid_file});
144 $self->assert_child_ok($pid);
145
146 test_cleanup($setup->{log_file}, $ex);
147 }
148
149 sub limit_site_help_issue1296 {
150 my $self = shift;
151 my $tmpdir = $self->{tmpdir};
152 my $setup = test_setup($tmpdir, 'limit');
153
154 my $config = {
155 PidFile => $setup->{pid_file},
156 ScoreboardFile => $setup->{scoreboard_file},
157 SystemLog => $setup->{log_file},
158 TraceLog => $setup->{log_file},
159 Trace => 'command:10 directory:10',
160
161 AuthUserFile => $setup->{auth_user_file},
162 AuthGroupFile => $setup->{auth_group_file},
163 AuthOrder => 'mod_auth_file.c',
164
165 DefaultChdir => '~',
166
167 IfModules => {
168 'mod_delay.c' => {
169 DelayEngine => 'off',
170 },
171 },
172
173 Limit => {
174 SITE_HELP => {
175 DenyAll => '',
176 },
177 }
178 };
179
180 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
181 $config);
182
183 # Open pipes, for use between the parent and child processes. Specifically,
184 # the child will indicate when it's done with its test by writing a message
185 # to the parent.
186 my ($rfh, $wfh);
187 unless (pipe($rfh, $wfh)) {
188 die("Can't open pipe: $!");
189 }
190
191 my $ex;
192
193 # Fork child
194 $self->handle_sigchld();
195 defined(my $pid = fork()) or die("Can't fork: $!");
196 if ($pid) {
197 eval {
198 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
199
200 eval { $client->site('help') };
201 unless ($@) {
202 die("SITE HELP command succeeded unexpectedly");
203 }
204
205 my $resp_code = $client->response_code();
206 my $resp_msg = $client->response_msg();
207
208 my $expected = 501;
209 $self->assert($expected == $resp_code,
210 test_msg("Expected response code $expected, got $resp_code"));
211
212 $expected = 'HELP: Permission denied';
213 $self->assert($expected eq $resp_msg,
214 test_msg("Expected response message '$expected', got '$resp_msg'"));
215
216 $client->login($setup->{user}, $setup->{passwd});
217 eval { $client->site('help') };
218 unless ($@) {
219 die("SITE HELP command succeeded unexpectedly");
220 }
221
222 $resp_code = $client->response_code();
223 $resp_msg = $client->response_msg();
224
225 $expected = 501;
226 $self->assert($expected == $resp_code,
227 test_msg("Expected response code $expected, got $resp_code"));
228
229 $expected = 'HELP: Permission denied';
230 $self->assert($expected eq $resp_msg,
231 test_msg("Expected response message '$expected', got '$resp_msg'"));
232
233 $client->quit();
234 };
235 if ($@) {
236 $ex = $@;
237 }
238
239 $wfh->print("done\n");
240 $wfh->flush();
241
242 } else {
243 eval { server_wait($setup->{config_file}, $rfh) };
244 if ($@) {
245 warn($@);
246 exit 1;
247 }
248
249 exit 0;
250 }
251
252 # Stop server
253 server_stop($setup->{pid_file});
254 $self->assert_child_ok($pid);
255
256 test_cleanup($setup->{log_file}, $ex);
257 }
258
259 1;