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