Debian Codegraph @

tests/t/lib/ProFTPD/Tests/Config/Port.pm

raw
1 package ProFTPD::Tests::Config::Port;
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 port_server_config => {
19 order => ++$order,
20 test_class => [qw(forking)],
21 },
22
23 port_vhost_config => {
24 order => ++$order,
25 test_class => [qw(forking)],
26 },
27
28 port_global_config_issue1418 => {
29 order => ++$order,
30 test_class => [qw(bug forking)],
31 },
32
33 port_global_and_vhost_config_issue1418 => {
34 order => ++$order,
35 test_class => [qw(bug forking)],
36 },
37
38 };
39
40 sub new {
41 return shift()->SUPER::new(@_);
42 }
43
44 sub list_tests {
45 return testsuite_get_runnable_tests($TESTS);
46 }
47
48 sub port_server_config {
49 my $self = shift;
50 my $tmpdir = $self->{tmpdir};
51 my $setup = test_setup($tmpdir, 'config');
52
53 my $config = {
54 PidFile => $setup->{pid_file},
55 ScoreboardFile => $setup->{scoreboard_file},
56 SystemLog => $setup->{log_file},
57 TraceLog => $setup->{log_file},
58 Trace => 'DEFAULT:0 binding:20 data:10',
59
60 AuthUserFile => $setup->{auth_user_file},
61 AuthGroupFile => $setup->{auth_group_file},
62 AuthOrder => 'mod_auth_file.c',
63
64 SocketBindTight => 'on',
65
66 IfModules => {
67 'mod_delay.c' => {
68 DelayEngine => 'off',
69 },
70 },
71 };
72
73 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
74 $config);
75
76 # Open pipes, for use between the parent and child processes. Specifically,
77 # the child will indicate when it's done with its test by writing a message
78 # to the parent.
79 my ($rfh, $wfh);
80 unless (pipe($rfh, $wfh)) {
81 die("Can't open pipe: $!");
82 }
83
84 my $ex;
85
86 # Fork child
87 $self->handle_sigchld();
88 defined(my $pid = fork()) or die("Can't fork: $!");
89 if ($pid) {
90 eval {
91 # Allow server to start up
92 sleep(2);
93
94 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
95 $client->login($setup->{user}, $setup->{passwd});
96 $client->quit();
97 };
98 if ($@) {
99 $ex = $@;
100 }
101
102 $wfh->print("done\n");
103 $wfh->flush();
104
105 } else {
106 eval { server_wait($setup->{config_file}, $rfh) };
107 if ($@) {
108 warn($@);
109 exit 1;
110 }
111
112 exit 0;
113 }
114
115 # Stop server
116 server_stop($setup->{pid_file});
117 $self->assert_child_ok($pid);
118
119 test_cleanup($setup->{log_file}, $ex);
120 }
121
122 sub port_vhost_config {
123 my $self = shift;
124 my $tmpdir = $self->{tmpdir};
125 my $setup = test_setup($tmpdir, 'config');
126
127 my $config = {
128 PidFile => $setup->{pid_file},
129 ScoreboardFile => $setup->{scoreboard_file},
130 SystemLog => $setup->{log_file},
131 TraceLog => $setup->{log_file},
132 Trace => 'DEFAULT:0 binding:20 data:10',
133
134 AuthUserFile => $setup->{auth_user_file},
135 AuthGroupFile => $setup->{auth_group_file},
136 AuthOrder => 'mod_auth_file.c',
137
138 Port => '0',
139 SocketBindTight => 'on',
140
141 IfModules => {
142 'mod_delay.c' => {
143 DelayEngine => 'off',
144 },
145 },
146 };
147
148 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
149 $config);
150
151 my $vhost_port = ProFTPD::TestSuite::Utils::get_high_numbered_port();
152
153 if (open(my $fh, ">> $setup->{config_file}")) {
154 print $fh <<EOC;
155 <VirtualHost 127.0.0.1>
156 ServerName "Vhost"
157 Port $vhost_port
158 AuthUserFile $setup->{auth_user_file}
159 AuthGroupFile $setup->{auth_group_file}
160 AuthOrder mod_auth_file.c
161 </VirtualHost>
162 EOC
163 unless (close($fh)) {
164 die("Can't write $setup->{config_file}: $!");
165 }
166
167 } else {
168 die("Can't open $setup->{config_file}: $!");
169 }
170
171 # Open pipes, for use between the parent and child processes. Specifically,
172 # the child will indicate when it's done with its test by writing a message
173 # to the parent.
174 my ($rfh, $wfh);
175 unless (pipe($rfh, $wfh)) {
176 die("Can't open pipe: $!");
177 }
178
179 my $ex;
180
181 # Fork child
182 $self->handle_sigchld();
183 defined(my $pid = fork()) or die("Can't fork: $!");
184 if ($pid) {
185 eval {
186 # Allow server to start up
187 sleep(2);
188
189 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $vhost_port);
190 $client->login($setup->{user}, $setup->{passwd});
191 $client->quit();
192 };
193 if ($@) {
194 $ex = $@;
195 }
196
197 $wfh->print("done\n");
198 $wfh->flush();
199
200 } else {
201 eval { server_wait($setup->{config_file}, $rfh) };
202 if ($@) {
203 warn($@);
204 exit 1;
205 }
206
207 exit 0;
208 }
209
210 # Stop server
211 server_stop($setup->{pid_file});
212 $self->assert_child_ok($pid);
213
214 test_cleanup($setup->{log_file}, $ex);
215 }
216
217 sub port_global_config_issue1418 {
218 my $self = shift;
219 my $tmpdir = $self->{tmpdir};
220 my $setup = test_setup($tmpdir, 'config');
221
222 my $config = {
223 PidFile => $setup->{pid_file},
224 ScoreboardFile => $setup->{scoreboard_file},
225 SystemLog => $setup->{log_file},
226 TraceLog => $setup->{log_file},
227 Trace => 'DEFAULT:0 binding:20 data:10',
228
229 AuthUserFile => $setup->{auth_user_file},
230 AuthGroupFile => $setup->{auth_group_file},
231 AuthOrder => 'mod_auth_file.c',
232
233 Port => '0',
234 SocketBindTight => 'on',
235
236 IfModules => {
237 'mod_delay.c' => {
238 DelayEngine => 'off',
239 },
240 },
241 };
242
243 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
244 $config);
245
246 my $vhost_port = ProFTPD::TestSuite::Utils::get_high_numbered_port();
247
248 if (open(my $fh, ">> $setup->{config_file}")) {
249 print $fh <<EOC;
250 <Global>
251 Port $vhost_port
252 </Global>
253
254 <VirtualHost 127.0.0.1>
255 ServerName "Vhost"
256 AuthUserFile $setup->{auth_user_file}
257 AuthGroupFile $setup->{auth_group_file}
258 AuthOrder mod_auth_file.c
259 </VirtualHost>
260 EOC
261 unless (close($fh)) {
262 die("Can't write $setup->{config_file}: $!");
263 }
264
265 } else {
266 die("Can't open $setup->{config_file}: $!");
267 }
268
269 # Open pipes, for use between the parent and child processes. Specifically,
270 # the child will indicate when it's done with its test by writing a message
271 # to the parent.
272 my ($rfh, $wfh);
273 unless (pipe($rfh, $wfh)) {
274 die("Can't open pipe: $!");
275 }
276
277 my $ex;
278
279 # Fork child
280 $self->handle_sigchld();
281 defined(my $pid = fork()) or die("Can't fork: $!");
282 if ($pid) {
283 eval {
284 # Allow server to start up
285 sleep(2);
286
287 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $vhost_port);
288 $client->login($setup->{user}, $setup->{passwd});
289 $client->quit();
290 };
291 if ($@) {
292 $ex = $@;
293 }
294
295 $wfh->print("done\n");
296 $wfh->flush();
297
298 } else {
299 eval { server_wait($setup->{config_file}, $rfh) };
300 if ($@) {
301 warn($@);
302 exit 1;
303 }
304
305 exit 0;
306 }
307
308 # Stop server
309 server_stop($setup->{pid_file});
310 $self->assert_child_ok($pid);
311
312 test_cleanup($setup->{log_file}, $ex);
313 }
314
315 sub port_global_and_vhost_config_issue1418 {
316 my $self = shift;
317 my $tmpdir = $self->{tmpdir};
318 my $setup = test_setup($tmpdir, 'config');
319
320 my $config = {
321 PidFile => $setup->{pid_file},
322 ScoreboardFile => $setup->{scoreboard_file},
323 SystemLog => $setup->{log_file},
324 TraceLog => $setup->{log_file},
325 Trace => 'DEFAULT:0 binding:20 data:10',
326
327 AuthUserFile => $setup->{auth_user_file},
328 AuthGroupFile => $setup->{auth_group_file},
329 AuthOrder => 'mod_auth_file.c',
330
331 Port => '0',
332 SocketBindTight => 'on',
333
334 IfModules => {
335 'mod_delay.c' => {
336 DelayEngine => 'off',
337 },
338 },
339 };
340
341 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
342 $config);
343
344 my $global_port = ProFTPD::TestSuite::Utils::get_high_numbered_port();
345 my $vhost_port = ProFTPD::TestSuite::Utils::get_high_numbered_port();
346
347 if ($ENV{TEST_VERBOSE}) {
348 print STDERR "# Using <Global> port $global_port, <VirtualHost> port $vhost_port\n";
349 }
350
351 if (open(my $fh, ">> $setup->{config_file}")) {
352 print $fh <<EOC;
353 <Global>
354 Port $global_port
355 </Global>
356
357 <VirtualHost 127.0.0.1>
358 ServerName "Vhost"
359 Port $vhost_port
360 AuthUserFile $setup->{auth_user_file}
361 AuthGroupFile $setup->{auth_group_file}
362 AuthOrder mod_auth_file.c
363 </VirtualHost>
364 EOC
365 unless (close($fh)) {
366 die("Can't write $setup->{config_file}: $!");
367 }
368
369 } else {
370 die("Can't open $setup->{config_file}: $!");
371 }
372
373 # Open pipes, for use between the parent and child processes. Specifically,
374 # the child will indicate when it's done with its test by writing a message
375 # to the parent.
376 my ($rfh, $wfh);
377 unless (pipe($rfh, $wfh)) {
378 die("Can't open pipe: $!");
379 }
380
381 my $ex;
382
383 # Fork child
384 $self->handle_sigchld();
385 defined(my $pid = fork()) or die("Can't fork: $!");
386 if ($pid) {
387 eval {
388 # Allow server to start up
389 sleep(2);
390
391 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $vhost_port);
392 $client->login($setup->{user}, $setup->{passwd});
393 $client->quit();
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 1;