- Timestamp:
- 11/11/11 13:17:43 (20 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/router/proftpd/tests/t/lib/ProFTPD/Tests/Config/HideNoAccess.pm
r14674 r17876 2 2 3 3 use lib qw(t/lib); 4 use base qw( Test::Unit::TestCaseProFTPD::TestSuite::Child);4 use base qw(ProFTPD::TestSuite::Child); 5 5 use strict; 6 6 7 use File::Path qw(mkpath rmtree);7 use File::Path qw(mkpath); 8 8 use File::Spec; 9 9 use IO::Handle; … … 22 22 }, 23 23 24 hidenoaccess_with_directory_glob => { 25 order => ++$order, 26 test_class => [qw(forking)], 27 }, 28 24 29 }; 25 30 … … 32 37 } 33 38 34 sub set_up {35 my $self = shift;36 $self->{tmpdir} = testsuite_get_tmp_dir();37 38 # Create temporary scratch dir39 eval { mkpath($self->{tmpdir}) };40 if ($@) {41 my $abs_path = File::Spec->rel2abs($self->{tmpdir});42 die("Can't create dir $abs_path: $@");43 }44 }45 46 sub tear_down {47 my $self = shift;48 49 # Remove temporary scratch dir50 if ($self->{tmpdir}) {51 eval { rmtree($self->{tmpdir}) };52 }53 54 undef $self;55 }56 57 39 sub hidenoaccess_ok { 58 40 my $self = shift; … … 70 52 my $user = 'proftpd'; 71 53 my $passwd = 'test'; 54 my $group = 'ftpd'; 72 55 my $home_dir = File::Spec->rel2abs($tmpdir); 73 56 my $uid = 500; … … 88 71 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, 89 72 '/bin/bash'); 90 auth_group_write($auth_group_file, 'ftpd', $gid, $user);73 auth_group_write($auth_group_file, $group, $gid, $user); 91 74 92 75 my $test_dir = File::Spec->rel2abs("$tmpdir/testdir"); … … 147 130 148 131 my $buf; 149 $conn->read($buf, 8192); 150 $conn->close(); 151 152 my ($resp_code, $resp_msg); 153 $resp_code = $client->response_code(); 154 $resp_msg = $client->response_msg(); 132 $conn->read($buf, 8192, 25); 133 eval { $conn->close() }; 134 135 my $resp_code = $client->response_code(); 136 my $resp_msg = $client->response_msg(); 155 137 156 138 my $expected; … … 182 164 'config.pid' => 1, 183 165 'config.scoreboard' => 1, 166 'config.scoreboard.lck' => 1, 184 167 }; 185 168 … … 234 217 } 235 218 219 sub hidenoaccess_with_directory_glob { 220 my $self = shift; 221 my $tmpdir = $self->{tmpdir}; 222 223 my $config_file = "$tmpdir/config.conf"; 224 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid"); 225 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard"); 226 227 my $log_file = File::Spec->rel2abs('tests.log'); 228 229 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd"); 230 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group"); 231 232 my $user = 'proftpd'; 233 my $passwd = 'test'; 234 my $group = 'ftpd'; 235 my $home_dir = File::Spec->rel2abs($tmpdir); 236 my $uid = 500; 237 my $gid = 500; 238 239 # Make sure that, if we're running as root, that the home directory has 240 # permissions/privs set for the account we create 241 if ($< == 0) { 242 unless (chmod(0755, $home_dir)) { 243 die("Can't set perms on $home_dir to 0755: $!"); 244 } 245 246 unless (chown($uid, $gid, $home_dir)) { 247 die("Can't set owner of $home_dir to $uid/$gid: $!"); 248 } 249 } 250 251 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, 252 '/bin/bash'); 253 auth_group_write($auth_group_file, $group, $gid, $user); 254 255 for (my $i = 1; $i < 6; $i++) { 256 my $test_dir = File::Spec->rel2abs("$tmpdir/testdir" . $i); 257 mkpath($test_dir); 258 259 unless (chmod(0755, $test_dir)) { 260 die("Can't set perms on $test_dir to 0755: $!"); 261 } 262 } 263 264 my $config = { 265 PidFile => $pid_file, 266 ScoreboardFile => $scoreboard_file, 267 SystemLog => $log_file, 268 TraceLog => $log_file, 269 Trace => 'DEFAULT:10', 270 271 AuthUserFile => $auth_user_file, 272 AuthGroupFile => $auth_group_file, 273 274 Directory => { 275 '/*' => { 276 HideNoAccess => 'on', 277 }, 278 }, 279 280 IfModules => { 281 'mod_delay.c' => { 282 DelayEngine => 'off', 283 }, 284 }, 285 }; 286 287 my ($port, $config_user, $config_group) = config_write($config_file, $config); 288 289 # Open pipes, for use between the parent and child processes. Specifically, 290 # the child will indicate when it's done with its test by writing a message 291 # to the parent. 292 my ($rfh, $wfh); 293 unless (pipe($rfh, $wfh)) { 294 die("Can't open pipe: $!"); 295 } 296 297 my $ex; 298 299 # Fork child 300 $self->handle_sigchld(); 301 defined(my $pid = fork()) or die("Can't fork: $!"); 302 if ($pid) { 303 eval { 304 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); 305 $client->login($user, $passwd); 306 307 my $conn = $client->list_raw(); 308 unless ($conn) { 309 die("Failed to LIST: " . $client->response_code() . " " . 310 $client->response_msg()); 311 } 312 313 my $buf; 314 $conn->read($buf, 8192, 25); 315 eval { $conn->close() }; 316 317 my $resp_code = $client->response_code(); 318 my $resp_msg = $client->response_msg(); 319 320 my $expected; 321 322 $expected = 226; 323 $self->assert($expected == $resp_code, 324 test_msg("Expected $expected, got $resp_code")); 325 326 $expected = "Transfer complete"; 327 $self->assert($expected eq $resp_msg, 328 test_msg("Expected '$expected', got '$resp_msg'")); 329 330 $client->quit(); 331 332 # We have to be careful of the fact that readdir returns directory 333 # entries in an unordered fashion. 334 my $res = {}; 335 my $lines = [split(/\n/, $buf)]; 336 foreach my $line (@$lines) { 337 if ($line =~ /^\S+\s+\d+\s+\S+\s+\S+\s+.*?\s+(\S+)$/) { 338 $res->{$1} = 1; 339 } 340 } 341 342 $expected = { 343 'config.conf' => 1, 344 'config.group' => 1, 345 'config.passwd' => 1, 346 'config.pid' => 1, 347 'config.scoreboard' => 1, 348 'config.scoreboard.lck' => 1, 349 'testdir1' => 1, 350 'testdir2' => 1, 351 'testdir3' => 1, 352 'testdir4' => 1, 353 'testdir5' => 1, 354 }; 355 356 my $ok = 1; 357 my $mismatch; 358 foreach my $name (keys(%$res)) { 359 unless (defined($expected->{$name})) { 360 $mismatch = $name; 361 $ok = 0; 362 last; 363 } 364 } 365 366 unless ($ok) { 367 die("Unexpected name '$mismatch' appeared in LIST data") 368 } 369 370 my $count = scalar(keys(%$res)); 371 unless ($count == scalar(keys(%$expected))) { 372 die("Unexpected count ($count) of names appeared in LIST data"); 373 } 374 375 }; 376 377 if ($@) { 378 $ex = $@; 379 } 380 381 $wfh->print("done\n"); 382 $wfh->flush(); 383 384 } else { 385 eval { server_wait($config_file, $rfh) }; 386 if ($@) { 387 warn($@); 388 exit 1; 389 } 390 391 exit 0; 392 } 393 394 # Stop server 395 server_stop($pid_file); 396 397 $self->assert_child_ok($pid); 398 399 if ($ex) { 400 die($ex); 401 } 402 403 unlink($log_file); 404 } 405 236 406 1;
Note: See TracChangeset
for help on using the changeset viewer.
