Debian Codegraph @

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

raw
1 package ProFTPD::Tests::Config::DisplayLogin;
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 displaylogin_abs_path => {
19 order => ++$order,
20 test_class => [qw(forking)],
21 },
22
23 displaylogin_rel_path => {
24 order => ++$order,
25 test_class => [qw(forking)],
26 },
27
28 displaylogin_absent => {
29 order => ++$order,
30 test_class => [qw(forking)],
31 },
32
33 displaylogin_multiline => {
34 order => ++$order,
35 test_class => [qw(forking)],
36 },
37
38 # XXX Add other tests with the various Display variables
39 };
40
41 sub new {
42 return shift()->SUPER::new(@_);
43 }
44
45 sub list_tests {
46 return testsuite_get_runnable_tests($TESTS);
47 }
48
49 sub displaylogin_abs_path {
50 my $self = shift;
51 my $tmpdir = $self->{tmpdir};
52
53 my $config_file = "$tmpdir/config.conf";
54 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
55 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
56
57 my $log_file = File::Spec->rel2abs('tests.log');
58
59 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
60 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
61
62 my $user = 'proftpd';
63 my $passwd = 'test';
64 my $home_dir = File::Spec->rel2abs($tmpdir);
65
66 auth_user_write($auth_user_file, $user, $passwd, 500, 500, $home_dir,
67 '/bin/bash');
68 auth_group_write($auth_group_file, 'ftpd', 500, $user);
69
70 my $login_file = File::Spec->rel2abs("$tmpdir/login.txt");
71
72 if (open(my $fh, "> $login_file")) {
73 print $fh "Hello user!\n";
74
75 unless (close($fh)) {
76 die("Unable to write $login_file: $!");
77 }
78
79 } else {
80 die("Unable to open $login_file: $!");
81 }
82
83 my $config = {
84 PidFile => $pid_file,
85 ScoreboardFile => $scoreboard_file,
86 SystemLog => $log_file,
87
88 AuthUserFile => $auth_user_file,
89 AuthGroupFile => $auth_group_file,
90 AuthOrder => 'mod_auth_file.c',
91
92 DisplayLogin => $login_file,
93
94 IfModules => {
95 'mod_delay.c' => {
96 DelayEngine => 'off',
97 },
98 },
99 };
100
101 my ($port, $config_user, $config_group) = config_write($config_file, $config);
102
103 # Open pipes, for use between the parent and child processes. Specifically,
104 # the child will indicate when it's done with its test by writing a message
105 # to the parent.
106 my ($rfh, $wfh);
107 unless (pipe($rfh, $wfh)) {
108 die("Can't open pipe: $!");
109 }
110
111 my $ex;
112
113 # Fork child
114 $self->handle_sigchld();
115 defined(my $pid = fork()) or die("Can't fork: $!");
116 if ($pid) {
117 eval {
118 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
119
120 $client->login($user, $passwd);
121
122 my ($resp_code, $resp_msg);
123
124 $resp_code = $client->response_code();
125 $resp_msg = $client->response_msg(0);
126
127 my $expected;
128
129 $expected = 230;
130 $self->assert($expected == $resp_code,
131 test_msg("Expected $expected, got $resp_code"));
132
133 $expected = "Hello user!";
134 $self->assert($expected eq $resp_msg,
135 test_msg("Expected '$expected', got '$resp_msg'"));
136
137 $client->quit();
138
139 $resp_code = $client->response_code();
140 $resp_msg = $client->response_msg(0);
141
142 $expected = 221;
143 $self->assert($expected == $resp_code,
144 test_msg("Expected $expected, got $resp_code"));
145
146 $expected = "Goodbye.";
147 $self->assert($expected eq $resp_msg,
148 test_msg("Expected '$expected', got '$resp_msg'"));
149
150 };
151
152 if ($@) {
153 $ex = $@;
154 }
155
156 $wfh->print("done\n");
157 $wfh->flush();
158
159 } else {
160 eval { server_wait($config_file, $rfh) };
161 if ($@) {
162 warn($@);
163 exit 1;
164 }
165
166 exit 0;
167 }
168
169 # Stop server
170 server_stop($pid_file);
171
172 $self->assert_child_ok($pid);
173
174 if ($ex) {
175 die($ex);
176 }
177
178 unlink($log_file);
179 }
180
181 sub displaylogin_rel_path {
182 my $self = shift;
183 my $tmpdir = $self->{tmpdir};
184
185 my $config_file = "$tmpdir/config.conf";
186 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
187 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
188
189 my $log_file = File::Spec->rel2abs('tests.log');
190
191 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
192 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
193
194 my $user = 'proftpd';
195 my $passwd = 'test';
196 my $home_dir = File::Spec->rel2abs($tmpdir);
197
198 auth_user_write($auth_user_file, $user, $passwd, 500, 500, $home_dir,
199 '/bin/bash');
200 auth_group_write($auth_group_file, 'ftpd', 500, $user);
201
202 my $login_file = 'login.txt';
203
204 my $login_path = File::Spec->rel2abs("$tmpdir/$login_file");
205
206 if (open(my $fh, "> $login_path")) {
207 print $fh "Hello user!\n";
208
209 unless (close($fh)) {
210 die("Unable to write $login_path: $!");
211 }
212
213 } else {
214 die("Unable to open $login_path: $!");
215 }
216
217 my $config = {
218 PidFile => $pid_file,
219 ScoreboardFile => $scoreboard_file,
220 SystemLog => $log_file,
221
222 AuthUserFile => $auth_user_file,
223 AuthGroupFile => $auth_group_file,
224 AuthOrder => 'mod_auth_file.c',
225
226 DisplayLogin => $login_file,
227
228 IfModules => {
229 'mod_delay.c' => {
230 DelayEngine => 'off',
231 },
232 },
233 };
234
235 my ($port, $config_user, $config_group) = config_write($config_file, $config);
236
237 # Open pipes, for use between the parent and child processes. Specifically,
238 # the child will indicate when it's done with its test by writing a message
239 # to the parent.
240 my ($rfh, $wfh);
241 unless (pipe($rfh, $wfh)) {
242 die("Can't open pipe: $!");
243 }
244
245 my $ex;
246
247 # Fork child
248 $self->handle_sigchld();
249 defined(my $pid = fork()) or die("Can't fork: $!");
250 if ($pid) {
251 eval {
252 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
253 $client->login($user, $passwd);
254
255 my ($resp_code, $resp_msg);
256
257 $resp_code = $client->response_code();
258 $resp_msg = $client->response_msg(0);
259
260 my $expected;
261
262 $expected = 230;
263 $self->assert($expected == $resp_code,
264 test_msg("Expected $expected, got $resp_code"));
265
266 $expected = "Hello user!";
267 $self->assert($expected eq $resp_msg,
268 test_msg("Expected '$expected', got '$resp_msg'"));
269
270 $client->quit();
271
272 $resp_code = $client->response_code();
273 $resp_msg = $client->response_msg(0);
274
275 $expected = 221;
276 $self->assert($expected == $resp_code,
277 test_msg("Expected $expected, got $resp_code"));
278
279 $expected = "Goodbye.";
280 $self->assert($expected eq $resp_msg,
281 test_msg("Expected '$expected', got '$resp_msg'"));
282
283 };
284
285 if ($@) {
286 $ex = $@;
287 }
288
289 $wfh->print("done\n");
290 $wfh->flush();
291
292 } else {
293 eval { server_wait($config_file, $rfh) };
294 if ($@) {
295 warn($@);
296 exit 1;
297 }
298
299 exit 0;
300 }
301
302 # Stop server
303 server_stop($pid_file);
304
305 $self->assert_child_ok($pid);
306
307 if ($ex) {
308 die($ex);
309 }
310
311 unlink($log_file);
312 }
313
314 sub displaylogin_absent {
315 my $self = shift;
316 my $tmpdir = $self->{tmpdir};
317
318 my $config_file = "$tmpdir/config.conf";
319 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
320 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
321
322 my $log_file = File::Spec->rel2abs('tests.log');
323
324 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
325 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
326
327 my $user = 'proftpd';
328 my $passwd = 'test';
329 my $home_dir = File::Spec->rel2abs($tmpdir);
330
331 auth_user_write($auth_user_file, $user, $passwd, 500, 500, $home_dir,
332 '/bin/bash');
333 auth_group_write($auth_group_file, 'ftpd', 500, $user);
334
335 my $config = {
336 PidFile => $pid_file,
337 ScoreboardFile => $scoreboard_file,
338 SystemLog => $log_file,
339
340 AuthUserFile => $auth_user_file,
341 AuthGroupFile => $auth_group_file,
342 AuthOrder => 'mod_auth_file.c',
343
344 IfModules => {
345 'mod_delay.c' => {
346 DelayEngine => 'off',
347 },
348 },
349 };
350
351 my ($port, $config_user, $config_group) = config_write($config_file, $config);
352
353 # Open pipes, for use between the parent and child processes. Specifically,
354 # the child will indicate when it's done with its test by writing a message
355 # to the parent.
356 my ($rfh, $wfh);
357 unless (pipe($rfh, $wfh)) {
358 die("Can't open pipe: $!");
359 }
360
361 my $ex;
362
363 # Fork child
364 $self->handle_sigchld();
365 defined(my $pid = fork()) or die("Can't fork: $!");
366 if ($pid) {
367 eval {
368 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
369 $client->login($user, $passwd);
370
371 my ($resp_code, $resp_msg);
372
373 $resp_code = $client->response_code();
374 $resp_msg = $client->response_msg(0);
375
376 my $expected;
377
378 $expected = 230;
379 $self->assert($expected == $resp_code,
380 test_msg("Expected $expected, got $resp_code"));
381
382 $expected = "User $user logged in";
383 $self->assert($expected eq $resp_msg,
384 test_msg("Expected '$expected', got '$resp_msg'"));
385 };
386
387 if ($@) {
388 $ex = $@;
389 }
390
391 $wfh->print("done\n");
392 $wfh->flush();
393
394 } else {
395 eval { server_wait($config_file, $rfh) };
396 if ($@) {
397 warn($@);
398 exit 1;
399 }
400
401 exit 0;
402 }
403
404 # Stop server
405 server_stop($pid_file);
406
407 $self->assert_child_ok($pid);
408
409 if ($ex) {
410 die($ex);
411 }
412
413 unlink($log_file);
414 }
415
416 sub displaylogin_multiline {
417 my $self = shift;
418 my $tmpdir = $self->{tmpdir};
419
420 my $config_file = "$tmpdir/config.conf";
421 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
422 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
423
424 my $log_file = File::Spec->rel2abs('tests.log');
425
426 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
427 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
428
429 my $user = 'proftpd';
430 my $passwd = 'test';
431 my $home_dir = File::Spec->rel2abs($tmpdir);
432
433 auth_user_write($auth_user_file, $user, $passwd, 500, 500, $home_dir,
434 '/bin/bash');
435 auth_group_write($auth_group_file, 'ftpd', 500, $user);
436
437 my $login_file = File::Spec->rel2abs("$tmpdir/login.txt");
438
439 if (open(my $fh, "> $login_file")) {
440 print $fh "Velkommen, Bienvenue\nDoor's open, come on in\nHello user!\n";
441
442 unless (close($fh)) {
443 die("Unable to write $login_file: $!");
444 }
445
446 } else {
447 die("Unable to open $login_file: $!");
448 }
449
450 my $config = {
451 PidFile => $pid_file,
452 ScoreboardFile => $scoreboard_file,
453 SystemLog => $log_file,
454
455 AuthUserFile => $auth_user_file,
456 AuthGroupFile => $auth_group_file,
457 AuthOrder => 'mod_auth_file.c',
458
459 DisplayLogin => $login_file,
460
461 IfModules => {
462 'mod_delay.c' => {
463 DelayEngine => 'off',
464 },
465 },
466 };
467
468 my ($port, $config_user, $config_group) = config_write($config_file, $config);
469
470 # Open pipes, for use between the parent and child processes. Specifically,
471 # the child will indicate when it's done with its test by writing a message
472 # to the parent.
473 my ($rfh, $wfh);
474 unless (pipe($rfh, $wfh)) {
475 die("Can't open pipe: $!");
476 }
477
478 my $ex;
479
480 # Fork child
481 $self->handle_sigchld();
482 defined(my $pid = fork()) or die("Can't fork: $!");
483 if ($pid) {
484 eval {
485 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
486
487 $client->login($user, $passwd);
488
489 my ($resp_code, $resp_msg);
490
491 $resp_code = $client->response_code();
492 $resp_msg = $client->response_msg(2);
493
494 my $expected;
495
496 $expected = 230;
497 $self->assert($expected == $resp_code,
498 test_msg("Expected $expected, got $resp_code"));
499
500 $expected = " Hello user!";
501 $self->assert($expected eq $resp_msg,
502 test_msg("Expected '$expected', got '$resp_msg'"));
503 };
504
505 if ($@) {
506 $ex = $@;
507 }
508
509 $wfh->print("done\n");
510 $wfh->flush();
511
512 } else {
513 eval { server_wait($config_file, $rfh) };
514 if ($@) {
515 warn($@);
516 exit 1;
517 }
518
519 exit 0;
520 }
521
522 # Stop server
523 server_stop($pid_file);
524
525 $self->assert_child_ok($pid);
526
527 if ($ex) {
528 die($ex);
529 }
530
531 unlink($log_file);
532 }
533
534 1;