| 1 |
package ProFTPD::Tests::Config::LogOptions; |
| 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 |
logoptions_no_timestamp => { |
| 19 |
order => ++$order, |
| 20 |
test_class => [qw(forking)], |
| 21 |
}, |
| 22 |
|
| 23 |
logoptions_no_hostname => { |
| 24 |
order => ++$order, |
| 25 |
test_class => [qw(forking)], |
| 26 |
}, |
| 27 |
|
| 28 |
logoptions_no_virtualhost => { |
| 29 |
order => ++$order, |
| 30 |
test_class => [qw(forking)], |
| 31 |
}, |
| 32 |
|
| 33 |
logoptions_use_rolebasedprocesslabels => { |
| 34 |
order => ++$order, |
| 35 |
test_class => [qw(forking)], |
| 36 |
}, |
| 37 |
}; |
| 38 |
|
| 39 |
sub new { |
| 40 |
return shift()->SUPER::new(@_); |
| 41 |
} |
| 42 |
|
| 43 |
sub list_tests { |
| 44 |
return testsuite_get_runnable_tests($TESTS); |
| 45 |
} |
| 46 |
|
| 47 |
sub logoptions_no_timestamp { |
| 48 |
my $self = shift; |
| 49 |
my $tmpdir = $self->{tmpdir}; |
| 50 |
my $setup = test_setup($tmpdir, 'log'); |
| 51 |
|
| 52 |
my $config = { |
| 53 |
PidFile => $setup->{pid_file}, |
| 54 |
ScoreboardFile => $setup->{scoreboard_file}, |
| 55 |
SystemLog => $setup->{log_file}, |
| 56 |
|
| 57 |
AuthUserFile => $setup->{auth_user_file}, |
| 58 |
AuthGroupFile => $setup->{auth_group_file}, |
| 59 |
AuthOrder => 'mod_auth_file.c', |
| 60 |
|
| 61 |
LogOptions => '-Timestamp', |
| 62 |
|
| 63 |
IfModules => { |
| 64 |
'mod_delay.c' => { |
| 65 |
DelayEngine => 'off', |
| 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 |
$client->login($setup->{user}, $setup->{passwd}); |
| 90 |
$client->quit(); |
| 91 |
}; |
| 92 |
if ($@) { |
| 93 |
$ex = $@; |
| 94 |
} |
| 95 |
|
| 96 |
$wfh->print("done\n"); |
| 97 |
$wfh->flush(); |
| 98 |
|
| 99 |
} else { |
| 100 |
eval { server_wait($setup->{config_file}, $rfh) }; |
| 101 |
if ($@) { |
| 102 |
warn($@); |
| 103 |
exit 1; |
| 104 |
} |
| 105 |
|
| 106 |
exit 0; |
| 107 |
} |
| 108 |
|
| 109 |
# Stop server |
| 110 |
server_stop($setup->{pid_file}); |
| 111 |
$self->assert_child_ok($pid); |
| 112 |
|
| 113 |
eval { |
| 114 |
if (open(my $fh, "< $setup->{log_file}")) { |
| 115 |
my $ok = 0; |
| 116 |
|
| 117 |
while (my $line = <$fh>) { |
| 118 |
chomp($line); |
| 119 |
|
| 120 |
if ($ENV{TEST_VERBOSE}) { |
| 121 |
print STDERR "# $line\n"; |
| 122 |
} |
| 123 |
|
| 124 |
my $expected = '^\S+ proftpd\[\d+\] .*?$'; |
| 125 |
|
| 126 |
if ($line =~ /$expected/) { |
| 127 |
$ok = 1; |
| 128 |
last; |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
close($fh); |
| 133 |
|
| 134 |
$self->assert($ok, test_msg("Missing expected LogOptions messages")); |
| 135 |
|
| 136 |
} else { |
| 137 |
die("Can't read $setup->{log_file}: $!"); |
| 138 |
} |
| 139 |
}; |
| 140 |
if ($@) { |
| 141 |
$ex = $@; |
| 142 |
} |
| 143 |
|
| 144 |
test_cleanup($setup->{log_file}, $ex); |
| 145 |
} |
| 146 |
|
| 147 |
sub logoptions_no_hostname { |
| 148 |
my $self = shift; |
| 149 |
my $tmpdir = $self->{tmpdir}; |
| 150 |
my $setup = test_setup($tmpdir, 'log'); |
| 151 |
|
| 152 |
my $config = { |
| 153 |
PidFile => $setup->{pid_file}, |
| 154 |
ScoreboardFile => $setup->{scoreboard_file}, |
| 155 |
SystemLog => $setup->{log_file}, |
| 156 |
|
| 157 |
AuthUserFile => $setup->{auth_user_file}, |
| 158 |
AuthGroupFile => $setup->{auth_group_file}, |
| 159 |
AuthOrder => 'mod_auth_file.c', |
| 160 |
|
| 161 |
LogOptions => '-Hostname', |
| 162 |
|
| 163 |
IfModules => { |
| 164 |
'mod_delay.c' => { |
| 165 |
DelayEngine => 'off', |
| 166 |
}, |
| 167 |
}, |
| 168 |
}; |
| 169 |
|
| 170 |
my ($port, $config_user, $config_group) = config_write($setup->{config_file}, |
| 171 |
$config); |
| 172 |
|
| 173 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 174 |
# the child will indicate when it's done with its test by writing a message |
| 175 |
# to the parent. |
| 176 |
my ($rfh, $wfh); |
| 177 |
unless (pipe($rfh, $wfh)) { |
| 178 |
die("Can't open pipe: $!"); |
| 179 |
} |
| 180 |
|
| 181 |
my $ex; |
| 182 |
|
| 183 |
# Fork child |
| 184 |
$self->handle_sigchld(); |
| 185 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 186 |
if ($pid) { |
| 187 |
eval { |
| 188 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 189 |
$client->login($setup->{user}, $setup->{passwd}); |
| 190 |
$client->quit(); |
| 191 |
}; |
| 192 |
if ($@) { |
| 193 |
$ex = $@; |
| 194 |
} |
| 195 |
|
| 196 |
$wfh->print("done\n"); |
| 197 |
$wfh->flush(); |
| 198 |
|
| 199 |
} else { |
| 200 |
eval { server_wait($setup->{config_file}, $rfh) }; |
| 201 |
if ($@) { |
| 202 |
warn($@); |
| 203 |
exit 1; |
| 204 |
} |
| 205 |
|
| 206 |
exit 0; |
| 207 |
} |
| 208 |
|
| 209 |
# Stop server |
| 210 |
server_stop($setup->{pid_file}); |
| 211 |
$self->assert_child_ok($pid); |
| 212 |
|
| 213 |
eval { |
| 214 |
if (open(my $fh, "< $setup->{log_file}")) { |
| 215 |
my $ok = 0; |
| 216 |
|
| 217 |
while (my $line = <$fh>) { |
| 218 |
chomp($line); |
| 219 |
|
| 220 |
if ($ENV{TEST_VERBOSE}) { |
| 221 |
print STDERR "# $line\n"; |
| 222 |
} |
| 223 |
|
| 224 |
my $expected = '^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3} proftpd\[\d+\] .*?$'; |
| 225 |
|
| 226 |
if ($line =~ /$expected/) { |
| 227 |
my $pid = $1; |
| 228 |
$ok = 1; |
| 229 |
last; |
| 230 |
} |
| 231 |
} |
| 232 |
|
| 233 |
close($fh); |
| 234 |
|
| 235 |
$self->assert($ok, test_msg("Missing expected LogOptions messages")); |
| 236 |
|
| 237 |
} else { |
| 238 |
die("Can't read $setup->{log_file}: $!"); |
| 239 |
} |
| 240 |
}; |
| 241 |
if ($@) { |
| 242 |
$ex = $@; |
| 243 |
} |
| 244 |
|
| 245 |
test_cleanup($setup->{log_file}, $ex); |
| 246 |
} |
| 247 |
|
| 248 |
sub logoptions_no_virtualhost { |
| 249 |
my $self = shift; |
| 250 |
my $tmpdir = $self->{tmpdir}; |
| 251 |
my $setup = test_setup($tmpdir, 'log'); |
| 252 |
|
| 253 |
my $config = { |
| 254 |
PidFile => $setup->{pid_file}, |
| 255 |
ScoreboardFile => $setup->{scoreboard_file}, |
| 256 |
SystemLog => $setup->{log_file}, |
| 257 |
|
| 258 |
AuthUserFile => $setup->{auth_user_file}, |
| 259 |
AuthGroupFile => $setup->{auth_group_file}, |
| 260 |
AuthOrder => 'mod_auth_file.c', |
| 261 |
|
| 262 |
LogOptions => '-VirtualHost', |
| 263 |
|
| 264 |
IfModules => { |
| 265 |
'mod_delay.c' => { |
| 266 |
DelayEngine => 'off', |
| 267 |
}, |
| 268 |
}, |
| 269 |
}; |
| 270 |
|
| 271 |
my ($port, $config_user, $config_group) = config_write($setup->{config_file}, |
| 272 |
$config); |
| 273 |
|
| 274 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 275 |
# the child will indicate when it's done with its test by writing a message |
| 276 |
# to the parent. |
| 277 |
my ($rfh, $wfh); |
| 278 |
unless (pipe($rfh, $wfh)) { |
| 279 |
die("Can't open pipe: $!"); |
| 280 |
} |
| 281 |
|
| 282 |
my $ex; |
| 283 |
|
| 284 |
# Fork child |
| 285 |
$self->handle_sigchld(); |
| 286 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 287 |
if ($pid) { |
| 288 |
eval { |
| 289 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 290 |
$client->login($setup->{user}, $setup->{passwd}); |
| 291 |
$client->quit(); |
| 292 |
}; |
| 293 |
if ($@) { |
| 294 |
$ex = $@; |
| 295 |
} |
| 296 |
|
| 297 |
$wfh->print("done\n"); |
| 298 |
$wfh->flush(); |
| 299 |
|
| 300 |
} else { |
| 301 |
eval { server_wait($setup->{config_file}, $rfh) }; |
| 302 |
if ($@) { |
| 303 |
warn($@); |
| 304 |
exit 1; |
| 305 |
} |
| 306 |
|
| 307 |
exit 0; |
| 308 |
} |
| 309 |
|
| 310 |
# Stop server |
| 311 |
server_stop($setup->{pid_file}); |
| 312 |
$self->assert_child_ok($pid); |
| 313 |
|
| 314 |
eval { |
| 315 |
if (open(my $fh, "< $setup->{log_file}")) { |
| 316 |
my $ok = 0; |
| 317 |
|
| 318 |
while (my $line = <$fh>) { |
| 319 |
chomp($line); |
| 320 |
|
| 321 |
if ($ENV{TEST_VERBOSE}) { |
| 322 |
print STDERR "# $line\n"; |
| 323 |
} |
| 324 |
|
| 325 |
my $expected = '^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3} \S+ proftpd\[\d+\] \(.*?$'; |
| 326 |
|
| 327 |
if ($line =~ /$expected/) { |
| 328 |
$ok = 1; |
| 329 |
last; |
| 330 |
} |
| 331 |
} |
| 332 |
|
| 333 |
close($fh); |
| 334 |
|
| 335 |
$self->assert($ok, test_msg("Missing expected LogOptions messages")); |
| 336 |
|
| 337 |
} else { |
| 338 |
die("Can't read $setup->{log_file}: $!"); |
| 339 |
} |
| 340 |
}; |
| 341 |
if ($@) { |
| 342 |
$ex = $@; |
| 343 |
} |
| 344 |
|
| 345 |
test_cleanup($setup->{log_file}, $ex); |
| 346 |
} |
| 347 |
|
| 348 |
sub logoptions_use_rolebasedprocesslabels { |
| 349 |
my $self = shift; |
| 350 |
my $tmpdir = $self->{tmpdir}; |
| 351 |
my $setup = test_setup($tmpdir, 'log'); |
| 352 |
|
| 353 |
my $config = { |
| 354 |
PidFile => $setup->{pid_file}, |
| 355 |
ScoreboardFile => $setup->{scoreboard_file}, |
| 356 |
SystemLog => $setup->{log_file}, |
| 357 |
|
| 358 |
AuthUserFile => $setup->{auth_user_file}, |
| 359 |
AuthGroupFile => $setup->{auth_group_file}, |
| 360 |
AuthOrder => 'mod_auth_file.c', |
| 361 |
|
| 362 |
LogOptions => '+RoleBasedProcessLabels', |
| 363 |
|
| 364 |
IfModules => { |
| 365 |
'mod_delay.c' => { |
| 366 |
DelayEngine => 'off', |
| 367 |
}, |
| 368 |
}, |
| 369 |
}; |
| 370 |
|
| 371 |
my ($port, $config_user, $config_group) = config_write($setup->{config_file}, |
| 372 |
$config); |
| 373 |
|
| 374 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 375 |
# the child will indicate when it's done with its test by writing a message |
| 376 |
# to the parent. |
| 377 |
my ($rfh, $wfh); |
| 378 |
unless (pipe($rfh, $wfh)) { |
| 379 |
die("Can't open pipe: $!"); |
| 380 |
} |
| 381 |
|
| 382 |
my $ex; |
| 383 |
|
| 384 |
# Fork child |
| 385 |
$self->handle_sigchld(); |
| 386 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 387 |
if ($pid) { |
| 388 |
eval { |
| 389 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 390 |
$client->login($setup->{user}, $setup->{passwd}); |
| 391 |
$client->quit(); |
| 392 |
}; |
| 393 |
if ($@) { |
| 394 |
$ex = $@; |
| 395 |
} |
| 396 |
|
| 397 |
$wfh->print("done\n"); |
| 398 |
$wfh->flush(); |
| 399 |
|
| 400 |
} else { |
| 401 |
eval { server_wait($setup->{config_file}, $rfh) }; |
| 402 |
if ($@) { |
| 403 |
warn($@); |
| 404 |
exit 1; |
| 405 |
} |
| 406 |
|
| 407 |
exit 0; |
| 408 |
} |
| 409 |
|
| 410 |
# Stop server |
| 411 |
server_stop($setup->{pid_file}); |
| 412 |
$self->assert_child_ok($pid); |
| 413 |
|
| 414 |
eval { |
| 415 |
if (open(my $fh, "< $setup->{log_file}")) { |
| 416 |
my $saw_daemon_label = 0; |
| 417 |
my $saw_session_label = 0; |
| 418 |
|
| 419 |
while (my $line = <$fh>) { |
| 420 |
chomp($line); |
| 421 |
|
| 422 |
if ($ENV{TEST_VERBOSE}) { |
| 423 |
print STDERR "# $line\n"; |
| 424 |
} |
| 425 |
|
| 426 |
my $expected = '^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3} \S+ daemon\[\d+\] '; |
| 427 |
if ($line =~ /$expected/) { |
| 428 |
$saw_daemon_label = 1; |
| 429 |
} |
| 430 |
|
| 431 |
$expected = '^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3} \S+ session\[\d+\] '; |
| 432 |
if ($line =~ /$expected/) { |
| 433 |
$saw_session_label = 1; |
| 434 |
} |
| 435 |
|
| 436 |
if ($saw_daemon_label == 1 && |
| 437 |
$saw_session_label) { |
| 438 |
last; |
| 439 |
} |
| 440 |
} |
| 441 |
|
| 442 |
close($fh); |
| 443 |
|
| 444 |
$self->assert($saw_daemon_label && $saw_session_label, |
| 445 |
test_msg("Missing expected LogOptions messages")); |
| 446 |
|
| 447 |
} else { |
| 448 |
die("Can't read $setup->{log_file}: $!"); |
| 449 |
} |
| 450 |
}; |
| 451 |
if ($@) { |
| 452 |
$ex = $@; |
| 453 |
} |
| 454 |
|
| 455 |
test_cleanup($setup->{log_file}, $ex); |
| 456 |
} |
| 457 |
|
| 458 |
1; |